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

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

本文整理了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

protected void reportNoViableAlternative(final Parser recognizer, final NoViableAltException e) {
 final TokenStream tokens = recognizer.getInputStream();
 final String input;
 if (tokens != null) {
  if (e.getStartToken().getType() == -1) {
   input = "<EOF>";
  } else {
   input = tokens.getText(e.getStartToken(), e.getOffendingToken());
  }
 } else {
  input = "<unknown input>";
 }
 final String msg = "no viable alternative at input " + this.escapeWSAndQuote(input);
 recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}

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

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

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

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

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

public NoViableAltException(Parser recognizer) { // LL(1) error
  this(recognizer,
     recognizer.getInputStream(),
     recognizer.getCurrentToken(),
     recognizer.getCurrentToken(),
     null,
     recognizer._ctx);
}

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

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

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

public InputMismatchException(Parser recognizer, int state, ParserRuleContext ctx) {
    super(recognizer, recognizer.getInputStream(), ctx);
    this.setOffendingState(state);
    this.setOffendingToken(recognizer.getCurrentToken());
  }
}

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

/** reset the parser's state */
public void reset() {
  if ( getInputStream()!=null ) getInputStream().seek(0);
  _errHandler.reset(this);
  _ctx = null;
  _syntaxErrors = 0;
  matchedEOF = false;
  setTrace(false);
  _precedenceStack.clear();
  _precedenceStack.push(0);
  ATNSimulator interpreter = getInterpreter();
  if (interpreter != null) {
    interpreter.reset();
  }
}

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

public FailedPredicateException(Parser recognizer,
                String predicate,
                String message)
{
  super(formatMessage(predicate, message), recognizer, recognizer.getInputStream(), recognizer._ctx);
  ATNState s = recognizer.getInterpreter().atn.states.get(recognizer.getState());
  AbstractPredicateTransition trans = (AbstractPredicateTransition)s.transition(0);
  if (trans instanceof PredicateTransition) {
    this.ruleIndex = ((PredicateTransition)trans).ruleIndex;
    this.predicateIndex = ((PredicateTransition)trans).predIndex;
  }
  else {
    this.ruleIndex = 0;
    this.predicateIndex = 0;
  }
  this.predicate = predicate;
  this.setOffendingToken(recognizer.getCurrentToken());
}

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

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

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

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

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

if ( lastErrorIndex==recognizer.getInputStream().index() &&
  lastErrorStates != null &&
  lastErrorStates.contains(recognizer.getState()) ) {
lastErrorIndex = recognizer.getInputStream().index();
if ( lastErrorStates==null ) lastErrorStates = new IntervalSet();
lastErrorStates.add(recognizer.getState());

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

/**
 * This is called by {@link #reportError} when the exception is a
 * {@link NoViableAltException}.
 *
 * @see #reportError
 *
 * @param recognizer the parser instance
 * @param e the recognition exception
 */
protected void reportNoViableAlternative(Parser recognizer,
                     NoViableAltException e)
{
  TokenStream tokens = recognizer.getInputStream();
  String input;
  if ( tokens!=null ) {
    if ( e.getStartToken().getType()==Token.EOF ) input = "<EOF>";
    else input = tokens.getText(e.getStartToken(), e.getOffendingToken());
  }
  else {
    input = "<unknown input>";
  }
  String msg = "no viable alternative at input "+escapeWSAndQuote(input);
  recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
}

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

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

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

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

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

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

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

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

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

@Override
    public Token recoverInline(Parser recognizer) throws RecognitionException {
      int errIndex = recognizer.getInputStream().index();
      if ( firstErrorTokenIndex == -1 ) {
        firstErrorTokenIndex = errIndex; // latch
      }
//            System.err.println("recoverInline: error at " + errIndex);
      InputMismatchException e = new InputMismatchException(recognizer);
//            TokenStream input = recognizer.getInputStream(); // seek EOF
//            input.seek(input.size() - 1);
      throw e;
    }

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

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

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

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

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

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

相关文章