Examples of BailErrorStrategy


Examples of org.antlr.v4.runtime.BailErrorStrategy

            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);
                }

                DFA[] decisionToDFA = previousParser.getInterpreter().decisionToDFA;
                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();
              parser.addErrorListener(DescriptiveErrorListener.INSTANCE);
              parser.addErrorListener(new SummarizingDiagnosticErrorListener());
              parser.getInterpreter().setPredictionMode(PredictionMode.LL);
              parser.setBuildParseTree(BUILD_PARSE_TREES);
              if (COMPUTE_CHECKSUM && !BUILD_PARSE_TREES) {
                parser.addParseListener(new ChecksumParseTreeListener(checksum));
              }
              if (!BUILD_PARSE_TREES && BLANK_LISTENER) {
                parser.addParseListener(listener);
              }
              if (BAIL_ON_ERROR) {
                parser.setErrorHandler(new BailErrorStrategy());
              }

              parseResult = parseMethod.invoke(parser);
            }
View Full Code Here

Examples of org.antlr.v4.runtime.BailErrorStrategy

                                 parser.getATNWithBypassAlts(),
                                 tokens);

    ParseTree tree = null;
    try {
      parserInterp.setErrorHandler(new BailErrorStrategy());
      tree = parserInterp.parse(patternRuleIndex);
//      System.out.println("pattern tree = "+tree.toStringTree(parserInterp));
    }
    catch (ParseCancellationException e) {
      throw (RecognitionException)e.getCause();
View Full Code Here

Examples of org.antlr.v4.runtime.BailErrorStrategy

     * Override to return an instance of {@link ErrorStrategy}, for example
     * to control the error messages corresponding to syntax errors.
     * By default (non-overriden) returns a strategy bailing at first error.
     */
    public ANTLRErrorStrategy createErrorStrategy() {
        return new BailErrorStrategy() { /* bail out at the first parse error */
            private void bail(Parser recognizer, Exception exc) {
                List<String> stack = recognizer.getRuleInvocationStack();
                Collections.reverse(stack);
                // TODO use recognizer.getRuleContext().toInfoString(recognizer); as the diagnostic ?
                throw new ParseCancellationException((exc.getMessage() != null ? exc.getMessage() + "; " : "") + (exc.getCause().getMessage() != null ? exc.getCause().getMessage() + "; " : "") + "in " + stack, exc.getCause());
View Full Code Here

Examples of org.antlr.v4.runtime.BailErrorStrategy

    abstract protected String getErrorMessage(int offendingState, int offendingTokenType);
    abstract protected String[] ruleNames();

    @Override
    public ANTLRErrorStrategy createErrorStrategy() {
        return new BailErrorStrategy() {
            private void bail(Parser recognizer, Exception exc, String additionalHint)
                        throws ParseCancellationException
            {
                RecognitionException re = (RecognitionException)exc.getCause();
                int offendingState = re.getOffendingState();
View Full Code Here

Examples of org.antlr.v4.runtime.BailErrorStrategy

  private EquationGrammarParser getParser(final String equation) {
    final ANTLRInputStream input = new ANTLRInputStream(equation);
    final EquationGrammarLexer lexer = new EquationGrammarLexer(input);
    final TokenStream tokenStream = new CommonTokenStream(lexer);
    final EquationGrammarParser parser = new EquationGrammarParser(tokenStream);
    final ANTLRErrorStrategy handler = new BailErrorStrategy();
    parser.setErrorHandler(handler);
    final ParseTreeListener listener = new EquationGrammerListener();
    parser.addParseListener(listener);
    return parser;
  }
View Full Code Here

Examples of org.antlr.v4.runtime.BailErrorStrategy

        // add custom error listener that logs syntax errors
        parser.addErrorListener(mErrorListener);

        // This strategy stops parsing when parser error occurs.
        // By default it uses Error Recover Strategy which is slow and useless.
        parser.setErrorHandler(new BailErrorStrategy());

        return parser.javadoc();
    }
View Full Code Here

Examples of org.antlr.v4.runtime.BailErrorStrategy

      }
      /*
       * 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

Examples of org.antlr.v4.runtime.BailErrorStrategy

//      lexerTime += stop-start;

      // Create a parser that reads from the scanner
      JavaParser parser = new JavaParser(tokens);
      if ( diag ) parser.addErrorListener(new DiagnosticErrorListener());
      if ( bail ) parser.setErrorHandler(new BailErrorStrategy());
      if ( SLL ) parser.getInterpreter().setPredictionMode(PredictionMode.SLL);

      // start parsing at the compilationUnit rule
      ParserRuleContext t = parser.compilationUnit();
      if ( notree ) parser.setBuildParseTree(false);
View Full Code Here

Examples of org.antlr.v4.runtime.BailErrorStrategy

//      lexerTime += stop-start;

      // Create a parser that reads from the scanner
      Java8Parser parser = new Java8Parser(tokens);
      if ( diag ) parser.addErrorListener(new DiagnosticErrorListener());
      if ( bail ) parser.setErrorHandler(new BailErrorStrategy());
      if ( SLL ) parser.getInterpreter().setPredictionMode(PredictionMode.SLL);

      // start parsing at the compilationUnit rule
      ParserRuleContext t = parser.compilationUnit();
      if ( notree ) parser.setBuildParseTree(false);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.