org.antlr.v4.runtime.Parser.getInputStream()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中org.antlr.v4.runtime.Parser.getInputStream()方法的一些代码示例,展示了Parser.getInputStream()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Parser.getInputStream()方法的具体详情如下:
包路径:org.antlr.v4.runtime.Parser
类名称:Parser
方法名:getInputStream

Parser.getInputStream介绍

暂无

代码示例

代码示例来源:origin: confluentinc/ksql

  1. protected void reportNoViableAlternative(final Parser recognizer, final NoViableAltException e) {
  2. final TokenStream tokens = recognizer.getInputStream();
  3. final String input;
  4. if (tokens != null) {
  5. if (e.getStartToken().getType() == -1) {
  6. input = "<EOF>";
  7. } else {
  8. input = tokens.getText(e.getStartToken(), e.getOffendingToken());
  9. }
  10. } else {
  11. input = "<unknown input>";
  12. }
  13. final String msg = "no viable alternative at input " + this.escapeWSAndQuote(input);
  14. recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
  15. }

代码示例来源:origin: apache/incubator-shardingsphere

  1. TokenStream tokens = recognizer.getInputStream();
  2. Token token = tokens.LT(1);
  3. ATNState state = recognizer.getInterpreter().atn.states.get(recognizer.getState());

代码示例来源:origin: org.antlr/antlr4-runtime

  1. /** Consume tokens until one matches the given token set. */
  2. protected void consumeUntil(Parser recognizer, IntervalSet set) {
  3. // System.err.println("consumeUntil("+set.toString(recognizer.getTokenNames())+")");
  4. int ttype = recognizer.getInputStream().LA(1);
  5. while (ttype != Token.EOF && !set.contains(ttype) ) {
  6. //System.out.println("consume during recover LA(1)="+getTokenNames()[input.LA(1)]);
  7. // recognizer.getInputStream().consume();
  8. recognizer.consume();
  9. ttype = recognizer.getInputStream().LA(1);
  10. }
  11. }
  12. }

代码示例来源:origin: org.antlr/antlr4-runtime

  1. public NoViableAltException(Parser recognizer) { // LL(1) error
  2. this(recognizer,
  3. recognizer.getInputStream(),
  4. recognizer.getCurrentToken(),
  5. recognizer.getCurrentToken(),
  6. null,
  7. recognizer._ctx);
  8. }

代码示例来源:origin: org.antlr/antlr4-runtime

  1. public InputMismatchException(Parser recognizer) {
  2. super(recognizer, recognizer.getInputStream(), recognizer._ctx);
  3. this.setOffendingToken(recognizer.getCurrentToken());
  4. }

代码示例来源:origin: org.antlr/antlr4-runtime

  1. public InputMismatchException(Parser recognizer, int state, ParserRuleContext ctx) {
  2. super(recognizer, recognizer.getInputStream(), ctx);
  3. this.setOffendingState(state);
  4. this.setOffendingToken(recognizer.getCurrentToken());
  5. }
  6. }

代码示例来源:origin: org.antlr/antlr4-runtime

  1. /** reset the parser's state */
  2. public void reset() {
  3. if ( getInputStream()!=null ) getInputStream().seek(0);
  4. _errHandler.reset(this);
  5. _ctx = null;
  6. _syntaxErrors = 0;
  7. matchedEOF = false;
  8. setTrace(false);
  9. _precedenceStack.clear();
  10. _precedenceStack.push(0);
  11. ATNSimulator interpreter = getInterpreter();
  12. if (interpreter != null) {
  13. interpreter.reset();
  14. }
  15. }

代码示例来源:origin: org.antlr/antlr4-runtime

  1. public FailedPredicateException(Parser recognizer,
  2. String predicate,
  3. String message)
  4. {
  5. super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx);
  6. ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
  7. AbstractPredicateTransition trans = (AbstractPredicateTransition)s.transition(0);
  8. if (trans instanceof PredicateTransition) {
  9. this.ruleIndex = ((PredicateTransition)trans).ruleIndex;
  10. this.predicateIndex = ((PredicateTransition)trans).predIndex;
  11. }
  12. else {
  13. this.ruleIndex = 0;
  14. this.predicateIndex = 0;
  15. }
  16. this.predicate = predicate;
  17. this.setOffendingToken(recognizer.getCurrentToken());
  18. }

代码示例来源:origin: org.antlr/antlr4-runtime

  1. int currentSymbolType = recognizer.getInputStream().LA(1);

代码示例来源:origin: org.antlr/antlr4-runtime

  1. int nextTokenType = recognizer.getInputStream().LA(2);
  2. IntervalSet expecting = getExpectedTokens(recognizer);
  3. if ( expecting.contains(nextTokenType) ) {

代码示例来源:origin: org.antlr/antlr4-runtime

  1. if ( lastErrorIndex==recognizer.getInputStream().index() &&
  2. lastErrorStates != null &&
  3. lastErrorStates.contains(recognizer.getState()) ) {
  4. lastErrorIndex = recognizer.getInputStream().index();
  5. if ( lastErrorStates==null ) lastErrorStates = new IntervalSet();
  6. lastErrorStates.add(recognizer.getState());

代码示例来源:origin: org.antlr/antlr4-runtime

  1. /**
  2. * This is called by {@link #reportError} when the exception is a
  3. * {@link NoViableAltException}.
  4. *
  5. * @see #reportError
  6. *
  7. * @param recognizer the parser instance
  8. * @param e the recognition exception
  9. */
  10. protected void reportNoViableAlternative(Parser recognizer,
  11. NoViableAltException e)
  12. {
  13. TokenStream tokens = recognizer.getInputStream();
  14. String input;
  15. if ( tokens!=null ) {
  16. if ( e.getStartToken().getType()==Token.EOF ) input = "<EOF>";
  17. else input = tokens.getText(e.getStartToken(), e.getOffendingToken());
  18. }
  19. else {
  20. input = "<unknown input>";
  21. }
  22. String msg = "no viable alternative at input "+escapeWSAndQuote(input);
  23. recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
  24. }

代码示例来源:origin: org.antlr/antlr4-runtime

  1. Token o = getCurrentToken();
  2. if (o.getType() != EOF) {
  3. getInputStream().consume();

代码示例来源:origin: org.antlr/antlr4-runtime

  1. TokenStream tokens = recognizer.getInputStream();
  2. int la = tokens.LA(1);

代码示例来源:origin: org.antlr/antlr4-runtime

  1. else tokenText = "<missing "+recognizer.getVocabulary().getDisplayName(expectedTokenType)+">";
  2. Token current = currentSymbol;
  3. Token lookback = recognizer.getInputStream().LT(-1);
  4. if ( current.getType() == Token.EOF && lookback!=null ) {
  5. current = lookback;

代码示例来源:origin: org.antlr/antlr4

  1. @Override
  2. public void recover(Parser recognizer, RecognitionException e) {
  3. int errIndex = recognizer.getInputStream().index();
  4. if ( firstErrorTokenIndex == -1 ) {
  5. firstErrorTokenIndex = errIndex; // latch
  6. }
  7. // System.err.println("recover: error at " + errIndex);
  8. TokenStream input = recognizer.getInputStream();
  9. if ( input.index()<input.size()-1 ) { // don't consume() eof
  10. recognizer.consume(); // just kill this bad token and let it continue.
  11. }
  12. }

代码示例来源:origin: org.antlr/antlr4

  1. @Override
  2. public Token recoverInline(Parser recognizer) throws RecognitionException {
  3. int errIndex = recognizer.getInputStream().index();
  4. if ( firstErrorTokenIndex == -1 ) {
  5. firstErrorTokenIndex = errIndex; // latch
  6. }
  7. // System.err.println("recoverInline: error at " + errIndex);
  8. InputMismatchException e = new InputMismatchException(recognizer);
  9. // TokenStream input = recognizer.getInputStream(); // seek EOF
  10. // input.seek(input.size() - 1);
  11. throw e;
  12. }

代码示例来源:origin: antlr/intellij-plugin-v4

  1. @Override
  2. public void recover(Parser recognizer, RecognitionException e) {
  3. int errIndex = recognizer.getInputStream().index();
  4. if ( firstErrorTokenIndex == -1 ) {
  5. firstErrorTokenIndex = errIndex; // latch
  6. }
  7. // System.err.println("recover: error at " + errIndex);
  8. TokenStream input = recognizer.getInputStream();
  9. if ( input.index()<input.size()-1 ) { // don't consume() eof
  10. recognizer.consume(); // just kill this bad token and let it continue.
  11. }
  12. }

代码示例来源:origin: javamonkey/beetl2.0

  1. protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e)
  2. {
  3. Token t1 = recognizer.getInputStream().LT(-1);
  4. String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 "
  5. + e.getExpectedTokens().toString(recognizer.getTokenNames());
  6. BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e);
  7. // exception.token = this.getGrammarToken(e.getOffendingToken());
  8. exception.pushToken(this.getGrammarToken(t1));
  9. throw exception;
  10. }

代码示例来源:origin: com.ibeetl/beetl

  1. protected void reportInputMismatch(@NotNull Parser recognizer, @NotNull InputMismatchException e)
  2. {
  3. Token t1 = recognizer.getInputStream().LT(-1);
  4. String msg = "缺少输入在 " + getTokenErrorDisplay(t1) + " 后面, 期望 "
  5. + e.getExpectedTokens().toString(recognizer.getTokenNames());
  6. BeetlException exception = new BeetlParserException(BeetlException.PARSER_MISS_ERROR, msg, e);
  7. // exception.token = this.getGrammarToken(e.getOffendingToken());
  8. exception.pushToken(this.getGrammarToken(t1));
  9. throw exception;
  10. }

相关文章