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

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

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

Parser.getVocabulary介绍

暂无

代码示例

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

  1. Analyzer analyzer = new Analyzer(atn, parser.getVocabulary(), specialRules, specialTokens, ignoredRules, parser.getTokenStream());
  2. Multimap<Integer, String> candidates = analyzer.process(currentState, currentToken.getTokenIndex(), context);

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

  1. protected void reportMissingToken(final Parser recognizer) {
  2. if (!this.inErrorRecoveryMode(recognizer)) {
  3. this.beginErrorCondition(recognizer);
  4. final Token t = recognizer.getCurrentToken();
  5. final IntervalSet expecting = this.getExpectedTokens(recognizer);
  6. final String msg =
  7. "missing " + expecting.toString(recognizer.getVocabulary()) + " at " + this
  8. .getTokenErrorDisplay(t);
  9. recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
  10. }
  11. }
  12. }

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

  1. protected void reportUnwantedToken(final Parser recognizer) {
  2. if (!this.inErrorRecoveryMode(recognizer)) {
  3. this.beginErrorCondition(recognizer);
  4. final Token t = recognizer.getCurrentToken();
  5. final String tokenName = this.getTokenErrorDisplay(t);
  6. final IntervalSet expecting = this.getExpectedTokens(recognizer);
  7. final String msg =
  8. "extraneous input " + tokenName + " expecting "
  9. + expecting.toString(recognizer.getVocabulary());
  10. recognizer.notifyErrorListeners(t, msg, (RecognitionException) null);
  11. }
  12. }

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

  1. public String getTokenName(int t) {
  2. if (t == Token.EOF) {
  3. return "EOF";
  4. }
  5. Vocabulary vocabulary = parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY;
  6. String displayName = vocabulary.getDisplayName(t);
  7. if (displayName.equals(Integer.toString(t))) {
  8. return displayName;
  9. }
  10. return displayName + "<" + t + ">";
  11. }

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

  1. /** For debugging and other purposes. */
  2. public List<String> getDFAStrings() {
  3. synchronized (_interp.decisionToDFA) {
  4. List<String> s = new ArrayList<String>();
  5. for (int d = 0; d < _interp.decisionToDFA.length; d++) {
  6. DFA dfa = _interp.decisionToDFA[d];
  7. s.add( dfa.toString(getVocabulary()) );
  8. }
  9. return s;
  10. }
  11. }

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

  1. /** For debugging and other purposes. */
  2. public void dumpDFA() {
  3. synchronized (_interp.decisionToDFA) {
  4. boolean seenOne = false;
  5. for (int d = 0; d < _interp.decisionToDFA.length; d++) {
  6. DFA dfa = _interp.decisionToDFA[d];
  7. if ( !dfa.states.isEmpty() ) {
  8. if ( seenOne ) System.out.println();
  9. System.out.println("Decision " + dfa.decision + ":");
  10. System.out.print(dfa.toString(getVocabulary()));
  11. seenOne = true;
  12. }
  13. }
  14. }
  15. }

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

  1. System.out.println("DFA=\n"+dfa.toString(parser!=null?parser.getVocabulary():VocabularyImpl.EMPTY_VOCABULARY));

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

  1. /**
  2. * This is called by {@link #reportError} when the exception is an
  3. * {@link InputMismatchException}.
  4. *
  5. * @see #reportError
  6. *
  7. * @param recognizer the parser instance
  8. * @param e the recognition exception
  9. */
  10. protected void reportInputMismatch(Parser recognizer,
  11. InputMismatchException e)
  12. {
  13. String msg = "mismatched input "+getTokenErrorDisplay(e.getOffendingToken())+
  14. " expecting "+e.getExpectedTokens().toString(recognizer.getVocabulary());
  15. recognizer.notifyErrorListeners(e.getOffendingToken(), msg, e);
  16. }

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

  1. /**
  2. * This method is called to report a syntax error which requires the
  3. * insertion of a missing token into the input stream. At the time this
  4. * method is called, the missing token has not yet been inserted. When this
  5. * method returns, {@code recognizer} is in error recovery mode.
  6. *
  7. * <p>This method is called when {@link #singleTokenInsertion} identifies
  8. * single-token insertion as a viable recovery strategy for a mismatched
  9. * input error.</p>
  10. *
  11. * <p>The default implementation simply returns if the handler is already in
  12. * error recovery mode. Otherwise, it calls {@link #beginErrorCondition} to
  13. * enter error recovery mode, followed by calling
  14. * {@link Parser#notifyErrorListeners}.</p>
  15. *
  16. * @param recognizer the parser instance
  17. */
  18. protected void reportMissingToken(Parser recognizer) {
  19. if (inErrorRecoveryMode(recognizer)) {
  20. return;
  21. }
  22. beginErrorCondition(recognizer);
  23. Token t = recognizer.getCurrentToken();
  24. IntervalSet expecting = getExpectedTokens(recognizer);
  25. String msg = "missing "+expecting.toString(recognizer.getVocabulary())+
  26. " at "+getTokenErrorDisplay(t);
  27. recognizer.notifyErrorListeners(t, msg, null);
  28. }

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

  1. /**
  2. * This method is called to report a syntax error which requires the removal
  3. * of a token from the input stream. At the time this method is called, the
  4. * erroneous symbol is current {@code LT(1)} symbol and has not yet been
  5. * removed from the input stream. When this method returns,
  6. * {@code recognizer} is in error recovery mode.
  7. *
  8. * <p>This method is called when {@link #singleTokenDeletion} identifies
  9. * single-token deletion as a viable recovery strategy for a mismatched
  10. * input error.</p>
  11. *
  12. * <p>The default implementation simply returns if the handler is already in
  13. * error recovery mode. Otherwise, it calls {@link #beginErrorCondition} to
  14. * enter error recovery mode, followed by calling
  15. * {@link Parser#notifyErrorListeners}.</p>
  16. *
  17. * @param recognizer the parser instance
  18. */
  19. protected void reportUnwantedToken(Parser recognizer) {
  20. if (inErrorRecoveryMode(recognizer)) {
  21. return;
  22. }
  23. beginErrorCondition(recognizer);
  24. Token t = recognizer.getCurrentToken();
  25. String tokenName = getTokenErrorDisplay(t);
  26. IntervalSet expecting = getExpectedTokens(recognizer);
  27. String msg = "extraneous input "+tokenName+" expecting "+
  28. expecting.toString(recognizer.getVocabulary());
  29. recognizer.notifyErrorListeners(t, msg, null);
  30. }

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

  1. parser.getVocabulary(),
  2. Arrays.asList(parser.getRuleNames()),
  3. parser.getATNWithBypassAlts(),

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

  1. /** For debugging and other purposes. */
  2. public List<String> getDFAStrings() {
  3. synchronized (_interp.decisionToDFA) {
  4. List<String> s = new ArrayList<String>();
  5. for (int d = 0; d < _interp.decisionToDFA.length; d++) {
  6. DFA dfa = _interp.decisionToDFA[d];
  7. s.add( dfa.toString(getVocabulary()) );
  8. }
  9. return s;
  10. }
  11. }

代码示例来源:origin: io.virtdata/virtdata-lib-realer

  1. public String getTokenName(int t) {
  2. if (t == Token.EOF) {
  3. return "EOF";
  4. }
  5. Vocabulary vocabulary = parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY;
  6. String displayName = vocabulary.getDisplayName(t);
  7. if (displayName.equals(Integer.toString(t))) {
  8. return displayName;
  9. }
  10. return displayName + "<" + t + ">";
  11. }

代码示例来源:origin: io.virtdata/virtdata-lib-realer

  1. /** For debugging and other purposes. */
  2. public List<String> getDFAStrings() {
  3. synchronized (_interp.decisionToDFA) {
  4. List<String> s = new ArrayList<String>();
  5. for (int d = 0; d < _interp.decisionToDFA.length; d++) {
  6. DFA dfa = _interp.decisionToDFA[d];
  7. s.add( dfa.toString(getVocabulary()) );
  8. }
  9. return s;
  10. }
  11. }

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

  1. @NotNull
  2. public String getTokenName(int t) {
  3. if (t == Token.EOF) {
  4. return "EOF";
  5. }
  6. Vocabulary vocabulary = parser != null ? parser.getVocabulary() : VocabularyImpl.EMPTY_VOCABULARY;
  7. String displayName = vocabulary.getDisplayName(t);
  8. if (displayName.equals(Integer.toString(t))) {
  9. return displayName;
  10. }
  11. return displayName + "<" + t + ">";
  12. }

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

  1. /** For debugging and other purposes. */
  2. public List<String> getDFAStrings() {
  3. List<String> s = new ArrayList<String>();
  4. for (int d = 0; d < _interp.atn.decisionToDFA.length; d++) {
  5. DFA dfa = _interp.atn.decisionToDFA[d];
  6. s.add( dfa.toString(getVocabulary(), getRuleNames()) );
  7. }
  8. return s;
  9. }

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

  1. else tokenText = "<missing "+recognizer.getVocabulary().getDisplayName(expectedTokenType)+">";
  2. Token current = currentSymbol;
  3. Token lookback = recognizer.getInputStream().LT(-1);

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

  1. if ( debug ) System.out.println("DFA after predictATN: "+ dfa.toString(parser.getVocabulary()));
  2. return alt;

代码示例来源:origin: org.codelibs.elasticsearch.module/lang-painless

  1. @Override
  2. public Token recoverInline(final Parser recognizer) throws RecognitionException {
  3. final Token token = recognizer.getCurrentToken();
  4. final String message = "unexpected token [" + getTokenErrorDisplay(token) + "]" +
  5. " was expecting one of [" + recognizer.getExpectedTokens().toString(recognizer.getVocabulary()) + "].";
  6. Location location = new Location(sourceName, token.getStartIndex());
  7. throw location.createError(new IllegalArgumentException(message));
  8. }

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

  1. @Override
  2. public void reportInputMismatch(Parser parser, InputMismatchException e) {
  3. setErrorState(parser);
  4. Token offendingToken = e.getOffendingToken();
  5. String mismatchedToken = getTokenErrorDisplay(offendingToken);
  6. String expectedToken = e.getExpectedTokens().toString(parser.getVocabulary());
  7. DiagnosticPos pos = getPosition(offendingToken);
  8. dlog.error(pos, DiagnosticCode.MISMATCHED_INPUT, mismatchedToken, expectedToken);
  9. }

相关文章