List of usage examples for org.antlr.v4.runtime CharStreams fromStream
public static CharStream fromStream(InputStream is) throws IOException
From source file:com.chiralbehaviors.CoRE.universal.Spa.java
License:Open Source License
public static Spa manifest(String resource) throws IOException { SpaLexer l = new SpaLexer(CharStreams.fromStream(Utils.resolveResource(Spa.class, resource))); SpaParser p = new SpaParser(new CommonTokenStream(l)); p.addErrorListener(new BaseErrorListener() { @Override// w w w. ja v a 2s.c om public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { throw new IllegalStateException("failed to parse at line " + line + " due to " + msg, e); } }); SpaContext spa = p.spa(); SpaImporter importer = new SpaImporter(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(importer, spa); return importer.getSpa(); }
From source file:greycat.language.Model.java
License:Open Source License
public void parseResource(String name, ClassLoader classLoader) throws IOException { InputStream is = classLoader.getResourceAsStream(name); Resolver resolver = new Resolver() { @Override// w w w. j a v a 2s .c om public CharStream resolver(String name) { InputStream sub = classLoader.getResourceAsStream(name); if (sub != null) { try { return CharStreams.fromStream(sub); } catch (IOException e) { e.printStackTrace(); } } return null; } }; internal_parse(CharStreams.fromStream(is), resolver); }
From source file:nl.knaw.huc.di.tag.tagml.importer.TAGMLImporter.java
License:Apache License
public TAGDocument importTAGML(InputStream input) throws TAGMLSyntaxError { try {//from w w w .j ava 2 s. com CharStream antlrInputStream = CharStreams.fromStream(input); return importTAGML(antlrInputStream); } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }
From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporter.java
License:Apache License
public TAGDocument importLMNL(InputStream input) throws LMNLSyntaxError { try {/*from www . j av a 2 s . c om*/ CharStream antlrInputStream = CharStreams.fromStream(input); return importLMNL(antlrInputStream); } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }
From source file:nl.knaw.huygens.alexandria.lmnl.importer.LMNLImporterInMemory.java
License:Apache License
public Document importLMNL(InputStream input) throws LMNLSyntaxError { try {//from w w w . ja v a 2s.c o m CharStream antlrInputStream = CharStreams.fromStream(input); return importLMNL(antlrInputStream); } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }
From source file:nl.knaw.huygens.alexandria.texmecs.importer.TexMECSImporter.java
License:Apache License
public TAGDocument importTexMECS(InputStream input) throws TexMECSSyntaxError { try {// w w w . j a va 2 s . com CharStream antlrInputStream = CharStreams.fromStream(input); return importTexMECS(antlrInputStream); } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }
From source file:nl.knaw.huygens.alexandria.texmecs.importer.TexMECSImporterInMemory.java
License:Apache License
public Document importTexMECS(InputStream input) throws TexMECSSyntaxError { try {/* w w w. ja v a2s .com*/ CharStream antlrInputStream = CharStreams.fromStream(input); return importTexMECS(antlrInputStream); } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }
From source file:org.eolang.compiler.Program.java
License:Open Source License
/** * Compile it to Java and save./* ww w. ja v a 2 s . c o m*/ * * @throws IOException If fails */ public void compile() throws IOException { final String[] lines = new TextOf(this.input).asString().split("\n"); final ANTLRErrorListener errors = new BaseErrorListener() { // @checkstyle ParameterNumberCheck (10 lines) @Override public void syntaxError(final Recognizer<?, ?> recognizer, final Object symbol, final int line, final int position, final String msg, final RecognitionException error) { throw new CompileException( String.format("[%d:%d] %s: \"%s\"", line, position, msg, lines[line - 1]), error); } }; final org.eolang.compiler.ProgramLexer lexer = new org.eolang.compiler.ProgramLexer( CharStreams.fromStream(this.input.stream())); lexer.removeErrorListeners(); lexer.addErrorListener(errors); final org.eolang.compiler.ProgramParser parser = new org.eolang.compiler.ProgramParser( new CommonTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(errors); final Tree tree = parser.program().ret; new IoCheckedScalar<>(new And(path -> { new LengthOf(new TeeInput(path.getValue(), this.target.apply(path.getKey()))).value(); }, tree.java().entrySet())).value(); }
From source file:org.kie.dmn.feel.parser.feel11.FEELTestRig.java
License:Apache License
public void process(String cu) throws Exception { CharStream charStream = CharStreams .fromStream(new ByteArrayInputStream(cu.getBytes(StandardCharsets.UTF_8))); process(lexer, parserClass, parser, charStream); }
From source file:org.lightjason.agentspeak.grammar.IBaseParser.java
License:LGPL
/** * returns a parser component//from ww w .j a va 2s.c om * * @param p_stream input stream * @return parser (for using in visitor interface) * * @throws IOException on io-stream errors * @throws IllegalAccessException on lexer / parser method access error * @throws InvocationTargetException on lexer / parser invocation error * @throws InstantiationException on lexer / parser instantiation error */ protected final P parser(@Nonnull final InputStream p_stream) throws IOException, IllegalAccessException, InvocationTargetException, InstantiationException { final L l_lexer = m_ctorlexer.newInstance(CharStreams.fromStream(p_stream)); l_lexer.removeErrorListeners(); l_lexer.addErrorListener(m_errorlistener); final P l_parser = m_ctorparser.newInstance(new CommonTokenStream(l_lexer)); l_parser.removeErrorListeners(); l_parser.addErrorListener(m_errorlistener); return l_parser; }