Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.Parser$TraceListener


    Constructor<? extends Lexer> lexerCtor = lexerClass.getConstructor(CharStream.class);
    Lexer lexer = lexerCtor.newInstance((CharStream)null);

    Class<? extends Parser> parserClass = null;
    Parser parser = null;
    if ( !startRuleName.equals(LEXER_START_RULE_NAME) ) {
      String parserName = grammarName+"Parser";
      parserClass = cl.loadClass(parserName).asSubclass(Parser.class);
      if ( parserClass==null ) {
        System.err.println("Can't load "+parserName);
View Full Code Here


      }
    }

    if (RUN_PARSER && sharedParsers.length > 0) {
      int index = FILE_GRANULARITY ? 0 : ((NumberedThread)Thread.currentThread()).getThreadNumber();
      Parser parser = sharedParsers[index];
            // make sure the individual DFAState objects actually have unique ATNConfig arrays
            final ParserATNSimulator interpreter = parser.getInterpreter();
            final DFA[] decisionToDFA = interpreter.decisionToDFA;

            if (SHOW_DFA_STATE_STATS) {
                int states = 0;
        int configs = 0;
        Set<ATNConfig> uniqueConfigs = new HashSet<ATNConfig>();

                for (int i = 0; i < decisionToDFA.length; i++) {
                    DFA dfa = decisionToDFA[i];
                    if (dfa == null) {
                        continue;
                    }

                    states += dfa.states.size();
          for (DFAState state : dfa.states.values()) {
            configs += state.configs.size();
            uniqueConfigs.addAll(state.configs);
          }
                }

                System.out.format("There are %d parser DFAState instances, %d configs (%d unique).%n", states, configs, uniqueConfigs.size());

        if (DETAILED_DFA_STATE_STATS) {
          if (COMPUTE_TRANSITION_STATS) {
            System.out.format("\tDecision\tStates\tConfigs\tPredict (ALL)\tPredict (LL)\tNon-SLL\tTransitions\tTransitions (ATN)\tTransitions (LL)\tLA (SLL)\tLA (LL)\tRule%n");
          }
          else {
            System.out.format("\tDecision\tStates\tConfigs\tRule%n");
          }

          for (int i = 0; i < decisionToDFA.length; i++) {
            DFA dfa = decisionToDFA[i];
            if (dfa == null || dfa.states.isEmpty()) {
              continue;
            }

            int decisionConfigs = 0;
            for (DFAState state : dfa.states.values()) {
              decisionConfigs += state.configs.size();
            }

            String ruleName = parser.getRuleNames()[parser.getATN().decisionToState.get(dfa.decision).ruleIndex];

            long calls = 0;
            long fullContextCalls = 0;
            long nonSllCalls = 0;
            long transitions = 0;
View Full Code Here

                        if (!RUN_PARSER) {
                            return new FileParseResult(input.getSourceName(), (int)checksum.getValue(), null, tokens.size(), startTime, lexer, null);
                        }

            final long parseStartTime = System.nanoTime();
            Parser parser = sharedParsers[thread];
                        if (REUSE_PARSER && parser != null) {
                            parser.setInputStream(tokens);
                        } else {
              Parser previousParser = parser;

              if (USE_PARSER_INTERPRETER) {
                Parser referenceParser = parserCtor.newInstance(tokens);
                parser = new ParserInterpreter(referenceParser.getGrammarFileName(), referenceParser.getVocabulary(), Arrays.asList(referenceParser.getRuleNames()), referenceParser.getATN(), tokens);
              }
              else {
                parser = parserCtor.newInstance(tokens);
              }

              DFA[] decisionToDFA = (FILE_GRANULARITY || previousParser == null ? parser : previousParser).getInterpreter().decisionToDFA;
              if (!REUSE_PARSER_DFA || (!FILE_GRANULARITY && previousParser == null)) {
                decisionToDFA = new DFA[decisionToDFA.length];
              }

              if (COMPUTE_TRANSITION_STATS) {
                parser.setInterpreter(new StatisticsParserATNSimulator(parser, parser.getATN(), decisionToDFA, parser.getInterpreter().getSharedContextCache()));
              } else if (!REUSE_PARSER_DFA) {
                parser.setInterpreter(new ParserATNSimulator(parser, parser.getATN(), decisionToDFA, parser.getInterpreter().getSharedContextCache()));
              }

              sharedParsers[thread] = parser;
                        }

            parser.removeParseListeners();
            parser.removeErrorListeners();
            if (!TWO_STAGE_PARSING) {
              parser.addErrorListener(DescriptiveErrorListener.INSTANCE);
              parser.addErrorListener(new SummarizingDiagnosticErrorListener());
            }

            if (parser.getInterpreter().decisionToDFA[0] == null) {
              ATN atn = parser.getATN();
              for (int i = 0; i < parser.getInterpreter().decisionToDFA.length; i++) {
                parser.getInterpreter().decisionToDFA[i] = new DFA(atn.getDecisionState(i), i);
              }
            }

            parser.getInterpreter().setPredictionMode(TWO_STAGE_PARSING ? PredictionMode.SLL : PREDICTION_MODE);
            parser.setBuildParseTree(BUILD_PARSE_TREES);
            if (!BUILD_PARSE_TREES && BLANK_LISTENER) {
              parser.addParseListener(listener);
            }
            if (BAIL_ON_ERROR || TWO_STAGE_PARSING) {
              parser.setErrorHandler(new BailErrorStrategy());
            }

                        Method parseMethod = parserClass.getMethod(entryPoint);
                        Object parseResult;

            try {
              if (COMPUTE_CHECKSUM && !BUILD_PARSE_TREES) {
                parser.addParseListener(new ChecksumParseTreeListener(checksum));
              }

              if (USE_PARSER_INTERPRETER) {
                ParserInterpreter parserInterpreter = (ParserInterpreter)parser;
                parseResult = parserInterpreter.parse(Collections.lastIndexOfSubList(Arrays.asList(parser.getRuleNames()), Collections.singletonList(entryPoint)));
              }
              else {
                parseResult = parseMethod.invoke(parser);
              }
            } catch (InvocationTargetException ex) {
              if (!TWO_STAGE_PARSING) {
                throw ex;
              }

              String sourceName = tokens.getSourceName();
              sourceName = sourceName != null && !sourceName.isEmpty() ? sourceName+": " : "";
              if (REPORT_SECOND_STAGE_RETRY) {
                System.err.println(sourceName+"Forced to retry with full context.");
              }

              if (!(ex.getCause() instanceof ParseCancellationException)) {
                throw ex;
              }

              tokens.reset();
              if (REUSE_PARSER && parser != null) {
                parser.setInputStream(tokens);
              } else {
                Parser previousParser = parser;

                if (USE_PARSER_INTERPRETER) {
                  Parser referenceParser = parserCtor.newInstance(tokens);
                  parser = new ParserInterpreter(referenceParser.getGrammarFileName(), referenceParser.getVocabulary(), Arrays.asList(referenceParser.getRuleNames()), referenceParser.getATN(), tokens);
                }
                else {
                  parser = parserCtor.newInstance(tokens);
                }
View Full Code Here

  public ParseTree execParser(String startRuleName, String input,
                String parserName, String lexerName)
    throws Exception
  {
    Pair<Parser, Lexer> pl = getParserAndLexer(input, parserName, lexerName);
    Parser parser = pl.a;
    return execStartRule(startRuleName, parser);
  }
View Full Code Here

    Lexer lexer = ctor.newInstance(in);

    Class<? extends Parser> pc = parserClass.asSubclass(Parser.class);
    Constructor<? extends Parser> pctor = pc.getConstructor(TokenStream.class);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    Parser parser = pctor.newInstance(tokens);
    return new Pair<Parser, Lexer>(parser, lexer);
  }
View Full Code Here

    Constructor<? extends Lexer> ctor = lexerClass.getConstructor(CharStream.class);
    Lexer lexer = ctor.newInstance((CharStream) null);

    Class<? extends Parser> parserClass = loadParserClassFromTempDir(grammarName + "Parser");
    Constructor<? extends Parser> pctor = parserClass.getConstructor(TokenStream.class);
    Parser parser = pctor.newInstance(new CommonTokenStream(lexer));

    return parser.compileParseTreePattern(pattern, parser.getRuleIndex(ruleName));
  }
View Full Code Here

    Constructor<? extends Lexer> ctor = lexerClass.getConstructor(CharStream.class);
    Lexer lexer = ctor.newInstance((CharStream) null);

    Class<? extends Parser> parserClass = loadParserClassFromTempDir(grammarName + "Parser");
    Constructor<? extends Parser> pctor = parserClass.getConstructor(TokenStream.class);
    Parser parser = pctor.newInstance(new CommonTokenStream(lexer));

    return new ParseTreePatternMatcher(lexer, parser);
  }
View Full Code Here

         }
      }
      /*
       * get parser
       */
      Parser parser = (Parser) parserConstructor.newInstance(tokens);
      parser.setErrorHandler(new BailErrorStrategy());
      final Method method = parserClass.getMethod(entryPoint);
      ParserRuleContext parserRuleContext = (ParserRuleContext) method.invoke(parser);
      /*
       * show the tree
       */
 
View Full Code Here

    // Create a parser that reads from the scanner
    JavaParser parser = new JavaParser(tokens);
    parser.removeErrorListeners();
   
    // start parsing at the compilationUnit rule
    ParserRuleContext t = parser.compilationUnit();
    ParseTreeWalker walker = new ParseTreeWalker();
    List<AutocompleteCandidate> q = new ArrayList<AutocompleteCandidate>();
         
    ImportDeclarationCompletion extractor = new ImportDeclarationCompletion(txt,cur,registry,cps,cu);
    NameBuilder extractor2 = new NameBuilder(registry,cu );
View Full Code Here

    isKeywords = false;
  }

  @Override
  public void enterPackage(@NotNull PackageContext ctx) {
    ParserRuleContext prc = ctx.getParent();
    if (!(prc instanceof DomainArrayContext)) {
      return;
    }
    DomainArrayContext dac = (DomainArrayContext) prc;
    DomainHeaderContext dhctx = (DomainHeaderContext) dac.getChild(0);
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.Parser$TraceListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.