Package org.antlr.v4.runtime

Examples of org.antlr.v4.runtime.LexerInterpreter


        "MULT : '*';\n" +
        "WS : ' '+;\n");
        // Tokens: 012345678901234567
        // Input:  x = 3 * 0 + 2 * 0;
    TestingUnbufferedCharStream input = createStream("x = 302 * 91 + 20234234 * 0;");
        LexerInterpreter lexEngine = g.createLexerInterpreter(input);
    // copy text into tokens from char stream
    lexEngine.setTokenFactory(new CommonTokenFactory(true));
    CommonTokenStream tokens = new CommonTokenStream(lexEngine);
        String result = tokens.LT(1).getText();
        String expecting = "x";
        assertEquals(expecting, result);
    tokens.fill();
View Full Code Here


        combinedGrammarFileName = grammarFileName;
        break;
    }

    ANTLRInputStream input = new ANTLRInputStream(inputText);
    LexerInterpreter lexEngine;
    if (combinedGrammarFileName != null) {
      lexEngine = g.createLexerInterpreter(input);
    }
    else {
      LexerGrammar lg = null;
      try {
        lg = (LexerGrammar) Grammar.load(lexerGrammarFileName);
      } catch (ClassCastException cce) {
        out.println("File " + lexerGrammarFileName + " isn't a lexer grammar");
      }
      g = loadGrammar(antlr, parserGrammarFileName, lg);
      lexEngine = lg.createLexerInterpreter(input);
    }

    final String gname = g.name;
    BaseErrorListener printError = new BaseErrorListener() {
      @Override
      public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
          final int line, final int position, final String msg,
          final RecognitionException e) {
        out.println(gname + "::" + startRule + ":" + line + ":" + position + ": " + msg);
      }
    };

    lexEngine.removeErrorListeners();
    lexEngine.addErrorListener(printError);

    CommonTokenStream tokens = new CommonTokenStream(lexEngine);

    ParserInterpreter parser = g.createParserInterpreter(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

    for (GrammarAST t : terminals) {
      int ttype = g.getTokenType(t.getText());
      set.add(ttype);
    }
    if ( invert ) {
      left.addTransition(new NotSetTransition(right, set));
    }
    else {
      left.addTransition(new SetTransition(right, set));
    }
    associatedAST.atnState = left;
View Full Code Here

        BlockStartState star = newState(StarBlockStartState.class, ebnfRoot);
        if ( alts.size()>1 ) atn.defineDecisionState(star);
        h = makeBlock(star, blkAST, alts);
        return star(ebnfRoot, h);
      case ANTLRParser.POSITIVE_CLOSURE :
        PlusBlockStartState plus = newState(PlusBlockStartState.class, ebnfRoot);
        if ( alts.size()>1 ) atn.defineDecisionState(plus);
        h = makeBlock(plus, blkAST, alts);
        return plus(ebnfRoot, h);
    }
    return null;
View Full Code Here

   * start.
   */
  @NotNull
  @Override
  public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) {
    PlusBlockStartState blkStart = (PlusBlockStartState)blk.left;
    BlockEndState blkEnd = (BlockEndState)blk.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    PlusLoopbackState loop = newState(PlusLoopbackState.class, plusAST);
    loop.nonGreedy = !((QuantifierAST)plusAST).isGreedy();
View Full Code Here

  public Handle plus(@NotNull GrammarAST plusAST, @NotNull Handle blk) {
    PlusBlockStartState blkStart = (PlusBlockStartState)blk.left;
    BlockEndState blkEnd = (BlockEndState)blk.right;
    preventEpsilonClosureBlocks.add(new Triple<Rule, ATNState, ATNState>(currentRule, blkStart, blkEnd));

    PlusLoopbackState loop = newState(PlusLoopbackState.class, plusAST);
    loop.nonGreedy = !((QuantifierAST)plusAST).isGreedy();
    atn.defineDecisionState(loop);
    LoopEndState end = newState(LoopEndState.class, plusAST);
    blkStart.loopBackState = loop;
    end.loopBackState = loop;
View Full Code Here

    ATNState right = newState(pred);

    AbstractPredicateTransition p;
    if (pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME) != null) {
      int precedence = Integer.parseInt(pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
      p = new PrecedencePredicateTransition(right, precedence);
    }
    else {
      boolean isCtxDependent = UseDefAnalyzer.actionIsContextDependent(pred);
      p = new PredicateTransition(right, currentRule.index, g.sempreds.get(pred), isCtxDependent);
    }
View Full Code Here

      int precedence = Integer.parseInt(pred.getOptionString(LeftRecursiveRuleTransformer.PRECEDENCE_OPTION_NAME));
      p = new PrecedencePredicateTransition(right, precedence);
    }
    else {
      boolean isCtxDependent = UseDefAnalyzer.actionIsContextDependent(pred);
      p = new PredicateTransition(right, currentRule.index, g.sempreds.get(pred), isCtxDependent);
    }

    left.addTransition(p);
    pred.atnState = left;
    return new Handle(left, right);
View Full Code Here

TOP

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

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.