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

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

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

Parser.getContext介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

  1. currentState = atn.states.get(parser.getState());
  2. currentToken = parser.getCurrentToken();
  3. context = parser.getContext();

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

  1. /**
  2. * Get matched token by token type.
  3. *
  4. * @param tokenType token type
  5. * @return matched token
  6. * @throws RecognitionException mismatch throw exception
  7. */
  8. public Token getMatchedToken(final int tokenType) throws RecognitionException {
  9. Token result = parser.getCurrentToken();
  10. boolean isIdentifierCompatible = false;
  11. if (identifierTokenIndex == tokenType && identifierTokenIndex > result.getType()) {
  12. isIdentifierCompatible = true;
  13. }
  14. if (result.getType() == tokenType || isIdentifierCompatible) {
  15. if (Token.EOF != tokenType && isIdentifierCompatible && result instanceof CommonToken) {
  16. ((CommonToken) result).setType(identifierTokenIndex);
  17. }
  18. parser.getErrorHandler().reportMatch(parser);
  19. parser.consume();
  20. } else {
  21. result = parser.getErrorHandler().recoverInline(parser);
  22. if (parser.getBuildParseTree() && -1 == result.getTokenIndex()) {
  23. parser.getContext().addErrorNode(parser.createErrorNode(parser.getContext(), result));
  24. }
  25. }
  26. return result;
  27. }
  28. }

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

  1. nextTokensContext = recognizer.getContext();
  2. nextTokensState = recognizer.getState();

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

  1. /** Instead of recovering from exception {@code e}, re-throw it wrapped
  2. * in a {@link ParseCancellationException} so it is not caught by the
  3. * rule function catches. Use {@link Exception#getCause()} to get the
  4. * original {@link RecognitionException}.
  5. */
  6. @Override
  7. public void recover(Parser recognizer, RecognitionException e) {
  8. for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
  9. context.exception = e;
  10. }
  11. throw new ParseCancellationException(e);
  12. }

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

  1. /**
  2. * Computes the set of input symbols which could follow the current parser
  3. * state and context, as given by {@link #getState} and {@link #getContext},
  4. * respectively.
  5. *
  6. * @see ATN#getExpectedTokens(int, RuleContext)
  7. */
  8. public IntervalSet getExpectedTokens() {
  9. return getATN().getExpectedTokens(getState(), getContext());
  10. }

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

  1. /** Make sure we don't attempt to recover inline; if the parser
  2. * successfully recovers, it won't throw an exception.
  3. */
  4. @Override
  5. public Token recoverInline(Parser recognizer)
  6. throws RecognitionException
  7. {
  8. InputMismatchException e = new InputMismatchException(recognizer);
  9. for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
  10. context.exception = e;
  11. }
  12. throw new ParseCancellationException(e);
  13. }

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

  1. nextTokensContext = recognizer.getContext();
  2. nextTokensState = recognizer.getState();

代码示例来源:origin: apache/eagle

  1. /** Instead of recovering from exception {@code e}, re-throw it wrapped
  2. * in a {@link org.antlr.v4.runtime.misc.ParseCancellationException} so it is not caught by the
  3. * rule function catches. Use {@link Exception#getCause()} to get the
  4. * original {@link org.antlr.v4.runtime.RecognitionException}.
  5. */
  6. @Override
  7. public void recover(Parser recognizer, RecognitionException e) {
  8. for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
  9. context.exception = e;
  10. }
  11. super.recover(recognizer,e);
  12. }

代码示例来源:origin: com.tunnelvisionlabs/antlr4-runtime

  1. /** Instead of recovering from exception {@code e}, re-throw it wrapped
  2. * in a {@link ParseCancellationException} so it is not caught by the
  3. * rule function catches. Use {@link Exception#getCause()} to get the
  4. * original {@link RecognitionException}.
  5. */
  6. @Override
  7. public void recover(Parser recognizer, RecognitionException e) {
  8. for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
  9. context.exception = e;
  10. }
  11. throw new ParseCancellationException(e);
  12. }

代码示例来源:origin: radkovo/jStyleParser

  1. /**
  2. * throws RecognitionException to handle in parser's catch block
  3. */
  4. public Token recoverInline(Parser recognizer) throws RecognitionException {
  5. throw new RecognitionException(recognizer, recognizer.getInputStream(), recognizer.getContext());
  6. }

代码示例来源:origin: org.apache.eagle/eagle-antlr

  1. /** Instead of recovering from exception {@code e}, re-throw it wrapped
  2. * in a {@link org.antlr.v4.runtime.misc.ParseCancellationException} so it is not caught by the
  3. * rule function catches. Use {@link Exception#getCause()} to get the
  4. * original {@link org.antlr.v4.runtime.RecognitionException}.
  5. */
  6. @Override
  7. public void recover(Parser recognizer, RecognitionException e) {
  8. for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
  9. context.exception = e;
  10. }
  11. super.recover(recognizer,e);
  12. }

代码示例来源:origin: net.sf.cssbox/jstyleparser

  1. /**
  2. * throws RecognitionException to handle in parser's catch block
  3. */
  4. public Token recoverInline(Parser recognizer) throws RecognitionException {
  5. throw new RecognitionException(recognizer, recognizer.getInputStream(), recognizer.getContext());
  6. }

代码示例来源:origin: uk.co.nichesolutions/antlr4-runtime

  1. /** Instead of recovering from exception {@code e}, re-throw it wrapped
  2. * in a {@link ParseCancellationException} so it is not caught by the
  3. * rule function catches. Use {@link Exception#getCause()} to get the
  4. * original {@link RecognitionException}.
  5. */
  6. @Override
  7. public void recover(Parser recognizer, RecognitionException e) {
  8. for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
  9. context.exception = e;
  10. }
  11. throw new ParseCancellationException(e);
  12. }

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

  1. /** Instead of recovering from exception {@code e}, re-throw it wrapped
  2. * in a {@link ParseCancellationException} so it is not caught by the
  3. * rule function catches. Use {@link Exception#getCause()} to get the
  4. * original {@link RecognitionException}.
  5. */
  6. @Override
  7. public void recover(Parser recognizer, RecognitionException e) {
  8. for (ParserRuleContext context = recognizer.getContext(); context != null; context = context.getParent()) {
  9. context.exception = e;
  10. }
  11. throw new ParseCancellationException(e);
  12. }

代码示例来源:origin: org.ballerinalang/language-server-core

  1. @Override
  2. public void reportInputMismatch(Parser parser, InputMismatchException e) {
  3. if (!parser.getContext().start.getTokenSource().getSourceName()
  4. .equals(context.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY).replace("\\", "/"))) {
  5. return;
  6. }
  7. this.context.put(CompletionKeys.TOKEN_STREAM_KEY, parser.getTokenStream());
  8. }

代码示例来源:origin: org.ballerinalang/language-server-core

  1. @Override
  2. public void reportMissingToken(Parser parser) {
  3. if (!parser.getContext().start.getTokenSource().getSourceName()
  4. .equals(context.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY).replace("\\", "/"))) {
  5. return;
  6. }
  7. this.context.put(CompletionKeys.TOKEN_STREAM_KEY, parser.getTokenStream());
  8. }

代码示例来源:origin: org.ballerinalang/language-server-core

  1. @Override
  2. public void reportNoViableAlternative(Parser parser, NoViableAltException e) {
  3. if (!parser.getContext().start.getTokenSource().getSourceName()
  4. .equals(context.get(DocumentServiceKeys.RELATIVE_FILE_PATH_KEY).replace("\\", "/"))) {
  5. return;
  6. }
  7. this.context.put(CompletionKeys.TOKEN_STREAM_KEY, parser.getTokenStream());
  8. }

代码示例来源:origin: org.ballerinalang/ballerina-lang

  1. @Override
  2. public void reportFailedPredicate(Parser parser, FailedPredicateException e) {
  3. setErrorState(parser);
  4. DiagnosticPos pos = getPosition(getMissingSymbol(parser));
  5. if (parser.getContext() instanceof BallerinaParser.ShiftExprPredicateContext) {
  6. dlog.error(pos, DiagnosticCode.INVALID_SHIFT_OPERATOR);
  7. } else if (parser.getContext() instanceof BallerinaParser.RestDescriptorPredicateContext) {
  8. dlog.error(pos, DiagnosticCode.INVALID_RECORD_REST_DESCRIPTOR);
  9. } else {
  10. dlog.error(pos, DiagnosticCode.FAILED_PREDICATE, e.getMessage());
  11. }
  12. }

代码示例来源:origin: org.ballerinalang/ballerina-lang

  1. @Override
  2. public void reportUnwantedToken(Parser parser) {
  3. if (parser.getContext().exception != null || inErrorRecoveryMode(parser)) {
  4. return;
  5. }
  6. beginErrorCondition(parser);
  7. setErrorState(parser);
  8. Token token = parser.getCurrentToken();
  9. DiagnosticPos pos = getPosition(getMissingSymbol(parser));
  10. dlog.error(pos, DiagnosticCode.EXTRANEOUS_INPUT, getTokenErrorDisplay(token));
  11. }

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

  1. protected void reportFailedPredicate(@NotNull Parser recognizer, @NotNull FailedPredicateException e)
  2. {
  3. String ruleName = recognizer.getRuleNames()[recognizer.getContext().getRuleIndex()];
  4. BeetlException exception = new BeetlParserException(BeetlException.PARSER_PREDICATE_ERROR, ruleName, e);
  5. // exception.token = this.getGrammarToken(e.getOffendingToken());
  6. exception.pushToken(this.getGrammarToken(e.getOffendingToken()));
  7. throw exception;
  8. }

相关文章