org.antlr.v4.runtime.BufferedTokenStream Java Examples
The following examples show how to use
org.antlr.v4.runtime.BufferedTokenStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZserioAstBuilder.java From zserio with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Custom visit overload which should be called on the parse tree of a single package (translation unit). * * @param tree Parse tree for a single package. * @param tokenStream Token stream for a single translation unit. * @return Object Result of the main rule of ZserioParser grammar. * Should be a package if the method was called on a correct parse tree. */ public Object visit(ParseTree tree, BufferedTokenStream tokenStream) { docCommentManager.setStream(tokenStream); final Object result = visit(tree); docCommentManager.printWarnings(); docCommentManager.resetStream(); return result; }
Example #2
Source File: ParserSupport.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Configuration configuration() throws IOException, ConfigurationException { final DescriptiveErrorListener error_listener = new DescriptiveErrorListener(); final ConfigTokenizer lexer = new ConfigTokenizer(CharStreams.fromReader(reader_)); lexer.removeErrorListeners(); lexer.addErrorListener(error_listener); final ConfigParser parser = new ConfigParser(new BufferedTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(error_listener); dir_.ifPresent(parser::setDir); final ConfigParser.ExprContext expr; try { expr = parser.expr(); } catch (Exception ex) { LOG.log(Level.SEVERE, "parser yielded exceptional return", ex); if (!error_listener.errors.isEmpty()) throw new ConfigurationException(error_listener.errors, ex); else throw ex; } if (!error_listener.errors.isEmpty()) { if (expr.exception != null) throw new ConfigurationException(error_listener.errors, expr.exception); throw new ConfigurationException(error_listener.errors); } else if (expr.exception != null) { throw new ConfigurationException(expr.exception); } return expr.s; }
Example #3
Source File: PathMatcher.java From monsoon with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Read path matcher from reader. * * @param reader A reader supplying the input of a path expression. * @return A PathMatcher corresponding to the parsed input * from the reader. * @throws IOException on IO errors from the reader. * @throws * com.groupon.lex.metrics.PathMatcher.ParseException * on invalid path expression. */ public static PathMatcher valueOf(Reader reader) throws IOException, ParseException { class DescriptiveErrorListener extends BaseErrorListener { public List<String> errors = new ArrayList<>(); @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, org.antlr.v4.runtime.RecognitionException e) { LOG.log(Level.INFO, "Parse error: {0}:{1} -> {2}", new Object[]{line, charPositionInLine, msg}); errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg)); } } final DescriptiveErrorListener error_listener = new DescriptiveErrorListener(); final PathMatcherLexer lexer = new PathMatcherLexer(CharStreams.fromReader(reader)); lexer.removeErrorListeners(); lexer.addErrorListener(error_listener); final PathMatcherGrammar parser = new PathMatcherGrammar(new BufferedTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(error_listener); final PathMatcherGrammar.ExprContext expr; try { expr = parser.expr(); } catch (Exception ex) { LOG.log(Level.SEVERE, "parser yielded exceptional return", ex); if (!error_listener.errors.isEmpty()) throw new ParseException(error_listener.errors, ex); else throw ex; } if (!error_listener.errors.isEmpty()) { if (expr.exception != null) throw new ParseException(error_listener.errors, expr.exception); throw new ParseException(error_listener.errors); } else if (expr.exception != null) { throw new ParseException(expr.exception); } return expr.s; }
Example #4
Source File: TimeSeriesMetricExpression.java From monsoon with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Read expression from reader. * * @param reader A reader supplying the input of an expression. * @return A TimeSeriesMetricExpression corresponding to the parsed input * from the reader. * @throws IOException on IO errors from the reader. * @throws * com.groupon.lex.metrics.timeseries.TimeSeriesMetricExpression.ParseException * on invalid expression. */ public static TimeSeriesMetricExpression valueOf(Reader reader) throws IOException, ParseException { final Logger LOG = Logger.getLogger(TimeSeriesMetricExpression.class.getName()); class DescriptiveErrorListener extends BaseErrorListener { public List<String> errors = new ArrayList<>(); @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, org.antlr.v4.runtime.RecognitionException e) { LOG.log(Level.INFO, "Parse error: {0}:{1} -> {2}", new Object[]{line, charPositionInLine, msg}); errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg)); } } final DescriptiveErrorListener error_listener = new DescriptiveErrorListener(); final ExpressionLexer lexer = new ExpressionLexer(CharStreams.fromReader(reader)); lexer.removeErrorListeners(); lexer.addErrorListener(error_listener); final Expression parser = new Expression(new BufferedTokenStream(lexer)); parser.removeErrorListeners(); parser.addErrorListener(error_listener); final Expression.ExprContext expr; try { expr = parser.expr(); } catch (Exception ex) { LOG.log(Level.SEVERE, "parser yielded exceptional return", ex); if (!error_listener.errors.isEmpty()) throw new ParseException(error_listener.errors, ex); else throw ex; } if (!error_listener.errors.isEmpty()) { if (expr.exception != null) throw new ParseException(error_listener.errors, expr.exception); throw new ParseException(error_listener.errors); } else if (expr.exception != null) { throw new ParseException(expr.exception); } return expr.s; }
Example #5
Source File: ServiceParseListener.java From protostuff-compiler with Apache License 2.0 | 4 votes |
protected ServiceParseListener(BufferedTokenStream tokens, ProtoContext context) { super(tokens, context); }
Example #6
Source File: ProtoParseListener.java From protostuff-compiler with Apache License 2.0 | 4 votes |
ProtoParseListener(BufferedTokenStream tokens, ProtoContext context) { super(tokens, context); this.tokens = tokens; }
Example #7
Source File: OptionParseListener.java From protostuff-compiler with Apache License 2.0 | 4 votes |
protected OptionParseListener(BufferedTokenStream tokens, ProtoContext context) { super(tokens, context); }
Example #8
Source File: MessageParseListener.java From protostuff-compiler with Apache License 2.0 | 4 votes |
public MessageParseListener(BufferedTokenStream tokens, ProtoContext context) { super(tokens, context); }
Example #9
Source File: EnumParseListener.java From protostuff-compiler with Apache License 2.0 | 4 votes |
protected EnumParseListener(BufferedTokenStream tokens, ProtoContext context) { super(tokens, context); }
Example #10
Source File: AbstractProtoParserListener.java From protostuff-compiler with Apache License 2.0 | 4 votes |
protected AbstractProtoParserListener(BufferedTokenStream tokens, ProtoContext context) { this.context = context; this.tokens = tokens; usedComments = new BitSet(); }
Example #11
Source File: DocCommentManager.java From zserio with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Sets the current token stream. * * @param tokenStream Current token stream. */ public void setStream(BufferedTokenStream tokenStream) { currentTokenStream = tokenStream; }