Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.BailErrorStrategy


  }

  public void reduceBlocksToSets(GrammarAST root) {
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(new GrammarASTAdaptor(), root);
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    BlockSetTransformer transformer = new BlockSetTransformer(nodes, g);
    transformer.setTreeAdaptor(adaptor);
    transformer.downup(root);
  }
View Full Code Here


  public Map<Integer, ASSOC> altAssociativity = new HashMap<Integer, ASSOC>();

  public LeftRecursiveRuleAnalyzer(GrammarAST ruleAST,
                   Tool tool, String ruleName, String language)
  {
    super(new CommonTreeNodeStream(new GrammarASTAdaptor(ruleAST.token.getInputStream()), ruleAST));
    this.tool = tool;
    this.ruleName = ruleName;
    this.language = language;
    this.tokenStream = ruleAST.g.tokenStream;
    if (this.tokenStream == null) {
View Full Code Here

        tool.log("grammar", "after: "+root.toStringTree());
  }

  public void reduceBlocksToSets(GrammarAST root) {
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(new GrammarASTAdaptor(), root);
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    BlockSetTransformer transformer = new BlockSetTransformer(nodes, g);
    transformer.setTreeAdaptor(adaptor);
    transformer.downup(root);
  }
View Full Code Here

    ClassUtils cu = new ClassUtils();
    setup(cu);
    registry.clearForType(JavaCompletionTypes.CUSTOM_TYPE);
    registry.clearForType(JavaCompletionTypes.FIELD);
    registry.clearForType(JavaCompletionTypes.NAME);
    Lexer lexer = new JavaLexer(new ANTLRInputStream(txt));
    CommonTokenStream tokens = new CommonTokenStream(lexer);

    // Create a parser that reads from the scanner
    JavaParser parser = new JavaParser(tokens);
    parser.removeErrorListeners();
View Full Code Here

  @Test
  public void Process() throws IOException {
    InputStream is = CheckSymbols.class.getResource("/Mson.js")
        .openStream();
    ANTLRInputStream input = new ANTLRInputStream(is);
    MsonLexer lexer = new MsonLexer(input);
//    SymbolASTFactory factory = new SymbolASTFactory();
//    lexer.setTokenFactory(factory);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
   
View Full Code Here

            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

                                 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

     * 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

    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

  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

TOP

Related Classes of org.antlr.v4.runtime.BailErrorStrategy

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.