Package org.antlr.v4.runtime.atn

Examples of org.antlr.v4.runtime.atn.ATN


        .openStream();
    ANTLRInputStream input = new ANTLRInputStream(is);
    MsonLexer lexer = new MsonLexer(input);
//    SymbolASTFactory factory = new SymbolASTFactory();
//    lexer.setTokenFactory(factory);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
   
    MsonParser parser = new MsonParser(tokens);
//    parser.setTokenFactory(factory);
    parser.addErrorListener(new DiagnosticErrorListener());
    parser.getInterpreter().setPredictionMode(
View Full Code Here


//    lexer.setTokenFactory(factory);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
   
    MsonParser parser = new MsonParser(tokens);
//    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
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

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

    // if current token is consistent with what could come after current
    // ATN state, then we know we're missing a token; error recovery
    // is free to conjure up and insert the missing token
    ATNState currentState = recognizer.getInterpreter().atn.states.get(recognizer.getState());
    ATNState next = currentState.transition(0).target;
    ATN atn = recognizer.getInterpreter().atn;
    IntervalSet expectingAtLL2 = atn.nextTokens(next, recognizer._ctx);
//    System.out.println("LT(2) set="+expectingAtLL2.toString(recognizer.getTokenNames()));
    if ( expectingAtLL2.contains(currentSymbolType) ) {
      reportMissingToken(recognizer);
      return true;
    }
View Full Code Here

   *  Like Grosch I implement context-sensitive FOLLOW sets that are combined
   *  at run-time upon error to avoid overhead during parsing.
   */
  @NotNull
  protected IntervalSet getErrorRecoverySet(@NotNull Parser recognizer) {
    ATN atn = recognizer.getInterpreter().atn;
    RuleContext ctx = recognizer._ctx;
    IntervalSet recoverSet = new IntervalSet();
    while ( ctx!=null && ctx.invokingState>=0 ) {
      // compute what follows who invoked us
      ATNState invokingState = atn.states.get(ctx.invokingState);
      RuleTransition rt = (RuleTransition)invokingState.transition(0);
      IntervalSet follow = atn.nextTokens(rt.followState);
      recoverSet.addAll(follow);
      ctx = ctx.parent;
    }
        recoverSet.remove(Token.EPSILON);
//    System.out.println("recover set "+recoverSet.toString(recognizer.getTokenNames()));
View Full Code Here

    if (serializedAtn == null) {
      throw new UnsupportedOperationException("The current parser does not support an ATN with bypass alternatives.");
    }

    synchronized (bypassAltsAtnCache) {
      ATN result = bypassAltsAtnCache.get(serializedAtn);
      if (result == null) {
        ATNDeserializationOptions deserializationOptions = new ATNDeserializationOptions();
        deserializationOptions.setGenerateRuleBypassTransitions(true);
        result = new ATNDeserializer(deserializationOptions).deserialize(serializedAtn.toCharArray());
        bypassAltsAtnCache.put(serializedAtn, result);
View Full Code Here

   * @return {@code true} if {@code symbol} can follow the current state in
   * the ATN, otherwise {@code false}.
   */
    public boolean isExpectedToken(int symbol) {
//       return getInterpreter().atn.nextTokens(_ctx);
        ATN atn = getInterpreter().atn;
    ParserRuleContext ctx = _ctx;
        ATNState s = atn.states.get(getState());
        IntervalSet following = atn.nextTokens(s);
        if (following.contains(symbol)) {
            return true;
        }
//        System.out.println("following "+s+"="+following);
        if ( !following.contains(Token.EPSILON) ) return false;

        while ( ctx!=null && ctx.invokingState>=0 && following.contains(Token.EPSILON) ) {
            ATNState invokingState = atn.states.get(ctx.invokingState);
            RuleTransition rt = (RuleTransition)invokingState.transition(0);
            following = atn.nextTokens(rt.followState);
            if (following.contains(symbol)) {
                return true;
            }

            ctx = (ParserRuleContext)ctx.parent;
View Full Code Here

    return getATN().getExpectedTokens(getState(), getContext());
  }

  @NotNull
    public IntervalSet getExpectedTokensWithinCurrentRule() {
        ATN atn = getInterpreter().atn;
        ATNState s = atn.states.get(getState());
       return atn.nextTokens(s);
     }
View Full Code Here

TOP

Related Classes of org.antlr.v4.runtime.atn.ATN

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.