List of usage examples for org.antlr.v4.runtime ANTLRFileStream ANTLRFileStream
public ANTLRFileStream(String fileName, String encoding) throws IOException
From source file:com.brobston.indelible.processor.module.CharStreamProvider.java
License:Open Source License
@Override public CharStream get() throws IOException { return new ANTLRFileStream(fileName, encoding); }
From source file:com.fizzed.rocker.compiler.TemplateParser.java
License:Apache License
public TemplateModel parse(File f) throws IOException, ParserException { if (!f.exists() || !f.canRead()) { throw new IOException("File cannot read or does not exist [" + f + "]"); }/*from www.j ava2 s . c o m*/ TemplateIdentity identity = parseIdentity(this.configuration.getTemplateDirectory(), f); ANTLRFileStream input = new ANTLRFileStream(f.getPath(), "UTF-8"); return parse(input, identity.packageName, identity.templateName, f.lastModified()); }
From source file:com.fizzed.rocker.compiler.TemplateParser.java
License:Apache License
public TemplateModel parse(File f, String packageName) throws IOException, ParserException { ANTLRFileStream input = new ANTLRFileStream(f.getPath(), "UTF-8"); return parse(input, packageName, f.getName(), f.lastModified()); }
From source file:com.kaaprotech.satu.parser.SatuParserHelper.java
License:Apache License
public CompilationUnit parse(final String modelFile, final String encoding, final boolean jsonCompatible) { final ANTLRFileStream charStream; try {/*from w w w . ja v a 2 s.c om*/ charStream = new ANTLRFileStream(modelFile, encoding); } catch (IOException e) { throw new RuntimeException(e); } final SatuLexer lexer = new SatuLexer(charStream); final CommonTokenStream tokenStream = new CommonTokenStream(lexer); final SatuParser parser = new SatuParser(tokenStream); final ParserRuleContext tree = parser.compilationUnit(); final ParseTreeWalker walker = new ParseTreeWalker(); final SatuListener listener = new SatuListener(jsonCompatible); walker.walk(listener, tree); return listener.getCompilationUnit(); }
From source file:de.weltraumschaf.caythe.SourceFile.java
License:BEER-WARE LICENSE
/** * Creates a stream for the ANTL parser. * * @return never {@code null}, always new instance * @throws IOException if file can't be opened *//*w w w. j a v a 2 s . co m*/ public CharStream newStream() throws IOException { return new ANTLRFileStream(source.toString(), encoding); }
From source file:de.weltraumschaf.shackhack.ShackHackCommand.java
License:BEER-WARE LICENSE
private List<Instruction> parseSource(final String filename) throws IOException { final CharStream input = new ANTLRFileStream(filename, ENCODING); final ShackHackLexer lexer = new ShackHackLexer(input); final TokenStream tokens = new CommonTokenStream(lexer); final ShackHackParser parser = new ShackHackParser(tokens); if (echoDebug) { parser.setErrorHandler(new BailErrorStrategy()); }//from www.j av a 2s . co m final ByteCodeVisitor visitor = new ByteCodeVisitor(); return visitor.visit(parser.program()); }
From source file:mbtarranger.languages.dot.Glue.java
License:Open Source License
protected static <T_Pass extends ParseTreeVisitor<AST>> T_Pass extractSinglePassVisiting(File osPath, Class<T_Pass> cls) throws IOException, RecognitionException, MbtArrangerException { DotLexer lexer;//from w ww .ja v a2 s . c o m lexer = new DotLexer(new ANTLRFileStream(osPath.getAbsolutePath(), "UTF-8"/*"ANSI"*/)); lexer.removeErrorListeners(); ErrorListener errListener = new ErrorListener(osPath); lexer.addErrorListener(errListener); CommonTokenStream tokens = new CommonTokenStream(lexer); DotParser parser = new DotParser(tokens); parser.setBuildParseTree(true); parser.removeErrorListeners(); parser.addErrorListener(errListener); T_Pass pass1; try { pass1 = cls.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new MbtArrangerException("misdesigned generics using reflection to type instantiation", e); } parser.setBuildParseTree(true); try { ParseTree tree = parser.root(); pass1.visit(tree); } catch (NullPointerException nulex) { throw new MbtArrangerException( /* NullPointerExceptions caught here mean, that the parser needs additional logic to handle grammar robustly */ "ARRANGE parser failed", nulex); } return pass1; }
From source file:org.jarvis.main.engine.impl.transform.AimlTransformLexerImpl.java
License:Apache License
/** * build from file//from w w w .j a va 2 s . co m * * @param filename * @param encoding * @return * @throws AimlParsingError */ protected static CommonTokenStream getTokens(String filename, String encoding) throws AimlParsingError { AimlTransformLexerImpl lexer; try { lexer = new AimlTransformLexerImpl(new ANTLRFileStream(filename, encoding)); } catch (IOException e) { throw new AimlParsingError(e); } return new CommonTokenStream(lexer); }
From source file:org.jarvis.main.parser.AimlLexerImpl.java
License:Apache License
/** * build from file//from w w w . j ava 2 s . co m * @param filename * @param encoding * @return * @throws AimlParsingError */ protected static CommonTokenStream getTokens(String filename, String encoding) throws AimlParsingError { AimlLexerImpl lexer; try { lexer = new AimlLexerImpl(new ANTLRFileStream(filename, encoding)); } catch (IOException e) { throw new AimlParsingError(e); } return new CommonTokenStream(lexer); }