Package org.antlr.v4.parse

Examples of org.antlr.v4.parse.GrammarASTAdaptor


  }

  protected void _createATN(@NotNull Collection<Rule> rules) {
    createRuleStartAndStopATNStates();

    GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
    for (Rule r : rules) {
      // find rule's block
      GrammarAST blk = (GrammarAST)r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
      CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
      ATNBuilder b = new ATNBuilder(nodes,this);
View Full Code Here


    this.tokenStream = ast.tokenStream;

    // ensure each node has pointer to surrounding grammar
    final Grammar thiz = this;
    org.antlr.runtime.tree.TreeVisitor v = new org.antlr.runtime.tree.TreeVisitor(new GrammarASTAdaptor());
    v.visit(ast, new org.antlr.runtime.tree.TreeVisitorAction() {
      @Override
      public Object pre(Object t) { ((GrammarAST)t).g = thiz; return t; }
      @Override
      public Object post(Object t) { return t; }
View Full Code Here

      "(RULE %name:TOKEN_REF (BLOCK (LEXER_ALT_ACTION (ALT %lit:STRING_LITERAL) (LEXER_ACTION_CALL . .))))",
      "(RULE %name:TOKEN_REF (BLOCK (LEXER_ALT_ACTION (ALT %lit:STRING_LITERAL) . (LEXER_ACTION_CALL . .))))",
      "(RULE %name:TOKEN_REF (BLOCK (LEXER_ALT_ACTION (ALT %lit:STRING_LITERAL) (LEXER_ACTION_CALL . .) .)))",
      // TODO: allow doc comment in there
    };
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor(ast.token.getInputStream());
    org.antlr.runtime.tree.TreeWizard wiz = new org.antlr.runtime.tree.TreeWizard(adaptor,ANTLRParser.tokenNames);
    List<Pair<GrammarAST,GrammarAST>> lexerRuleToStringLiteral =
      new ArrayList<Pair<GrammarAST,GrammarAST>>();

    List<GrammarAST> ruleNodes = ast.getNodesWithType(ANTLRParser.RULE);
View Full Code Here

  }

  public void buildNormalRuleFunction(Rule r, RuleFunction function) {
    CodeGenerator gen = delegate.getGenerator();
    // TRIGGER factory functions for rule alts, elements
    GrammarASTAdaptor adaptor = new GrammarASTAdaptor(r.ast.token.getInputStream());
    GrammarAST blk = (GrammarAST)r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
    CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
    walker = new SourceGenTriggers(nodes, this);
    try {
      // walk AST of rule alts/elements
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

    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

        .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

TOP

Related Classes of org.antlr.v4.parse.GrammarASTAdaptor

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.