Package org.antlr.v4.runtime.misc

Examples of org.antlr.v4.runtime.misc.IntervalSet


        String result = s.toString();
        assertEquals(expecting, result);
    }

    @Test public void testRmRightSide() throws Exception {
        IntervalSet s = IntervalSet.of(1,10);
        s.add(-3,-3);
        s.remove(10);
        String expecting = "{-3, 1..9}";
        String result = s.toString();
        assertEquals(expecting, result);
    }
View Full Code Here


        String result = s.toString();
        assertEquals(expecting, result);
    }

    @Test public void testRmMiddleRange() throws Exception {
        IntervalSet s = IntervalSet.of(1,10);
        s.add(-3,-3);
        s.remove(5);
        String expecting = "{-3, 1..4, 6..10}";
        String result = s.toString();
        assertEquals(expecting, result);
    }
View Full Code Here

            {
                String additionalHint = "";
               // per {@link DefaultErrorStrategy#singleTokenDeletion}, {@link BailErrorStrategy#recoverInline}:
                Token currentSymbol = recognizer.getCurrentToken();
                int nextTokenType = recognizer.getInputStream().LA(2);
                IntervalSet expecting = getExpectedTokens(recognizer);
                if ( expecting.contains(nextTokenType) ) {
                    String s = currentSymbol.getType() == -1 ? "EOF" : ruleNames()[currentSymbol.getType()-1];
                    additionalHint += String.format("Maybe the token %s should be removed.\n", s);
                }
                // attempt to conjure a token, {@link DefaultErrorStrategy#getMissingSymbol}
                int missingTokenType = expecting.getSingleElement();
                if (missingTokenType != Token.INVALID_TYPE && missingTokenType != -1) {
                    additionalHint += String.format("Maybe you're missing the %s token.\n",ruleNames()[missingTokenType-1]);
                }
                try {
                    super.recoverInline(recognizer);
View Full Code Here

  @Override
  protected void reportMissingToken(@NotNull Parser recognizer) {
    beginErrorCondition(recognizer);
    Token t = recognizer.getCurrentToken();
    IntervalSet expecting = getExpectedTokens(recognizer);
    String msg = "missing "
        + expecting.toString(recognizer.getTokenNames()) + " at "
        + getTokenErrorDisplay(t);
    throw new RecognitionException(msg, recognizer,
        recognizer.getInputStream(), recognizer.getContext());
  }
View Full Code Here

    case ATNState.PLUS_LOOP_BACK:
    case ATNState.STAR_LOOP_BACK:
      // System.err.println("at loop back: "+s.getClass().getSimpleName());
      reportUnwantedToken(recognizer);
      IntervalSet expecting = recognizer.getExpectedTokens();
      IntervalSet whatFollowsLoopIterationOrRule = expecting
          .or(getErrorRecoverySet(recognizer));
      consumeUntil(recognizer, whatFollowsLoopIterationOrRule);
      break;

    default:
View Full Code Here

  @Override
  protected void reportUnwantedToken(@NotNull Parser recognizer) {
    beginErrorCondition(recognizer);
    Token t = recognizer.getCurrentToken();
    IntervalSet expecting = getExpectedTokens(recognizer);
    String msg = "unwanted token " + getTokenErrorDisplay(t) + " expected "
        + expecting.toString(recognizer.getTokenNames());
    throw new RecognitionException(msg, recognizer,
        recognizer.getInputStream(), recognizer.getContext());
  }
View Full Code Here

          }
        }
      }
      if(arg0.getParent() instanceof ExpressionContext) {
        // we are the leftmost child of the expression
        ParseTree chld = arg0.getParent().getChild(arg0.getParent().getChildCount()-1);
        if(!chld.equals(arg0)) return;
        addQuery(classUtils.expandExpression(arg0.getParent().getText(), registry));
      }
    }
  }
View Full Code Here

//    parser.setTokenFactory(factory);
    parser.addErrorListener(new DiagnosticErrorListener());
    parser.getInterpreter().setPredictionMode(
        PredictionMode.LL_EXACT_AMBIG_DETECTION);
    parser.setBuildParseTree(true);
    ParseTree tree = parser.mson();
    // show tree in text form
    // System.out.println(tree.toStringTree(parser));

    ParseTreeWalker walker = new ParseTreeWalker();
    SymbolTable symtab = new SymbolTable();
View Full Code Here

    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 );
    NodeCompletion extractor3 = new NodeCompletion(txt,cur, registry, cu);
    walker.walk(extractor, t);
    if(extractor.getQuery()!=null)
      q.addAll(extractor.getQuery());
    walker.walk(extractor2, t);
    walker.walk(extractor3, t);
    if(extractor3.getQuery()!=null)
      q.addAll(extractor3.getQuery());
    List<String> ret = registry.searchCandidates(q);

    // this shows the GUI
View Full Code Here

    parser.setBuildParseTree(true);
    ParseTree tree = parser.mson();
    // show tree in text form
    // System.out.println(tree.toStringTree(parser));

    ParseTreeWalker walker = new ParseTreeWalker();
    SymbolTable symtab = new SymbolTable();
    DefPhase def = new DefPhase(symtab);
    walker.walk(def, tree);
    // create next phase and feed symbol table info from def to ref phase
    RefPhase ref = new RefPhase(symtab, def.scopes);
    walker.walk(ref, tree);
  }
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.misc.IntervalSet

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.