Package org.antlr.v4.parse

Examples of org.antlr.v4.parse.GrammarASTAdaptor.create()


    // Compute list of rules in root grammar and ensure we have a RULES node
    GrammarAST RULES = (GrammarAST)root.getFirstChildWithType(ANTLRParser.RULES);
    Set<String> rootRuleNames = new HashSet<String>();
    if ( RULES==null ) { // no rules in root, make RULES node, hook in
      RULES = (GrammarAST)adaptor.create(ANTLRParser.RULES, "RULES");
      RULES.g = rootGrammar;
      root.addChild(RULES);
    }
    else {
      // make list of rules we have in root grammar
View Full Code Here


      // COPY TOKENS
      GrammarAST imp_tokensRoot = (GrammarAST)imp.ast.getFirstChildWithType(ANTLRParser.TOKENS_SPEC);
      if ( imp_tokensRoot!=null ) {
        rootGrammar.tool.log("grammar", "imported tokens: "+imp_tokensRoot.getChildren());
        if ( tokensRoot==null ) {
          tokensRoot = (GrammarAST)adaptor.create(ANTLRParser.TOKENS_SPEC, "TOKENS");
          tokensRoot.g = rootGrammar;
          root.insertChild(1, tokensRoot); // ^(GRAMMAR ID TOKENS...)
        }
        tokensRoot.addChildren(Arrays.asList(imp_tokensRoot.getChildren().toArray(new Tree[0])));
      }
View Full Code Here

    String lexerName = combinedAST.getChild(0).getText()+"Lexer";
    GrammarRootAST lexerAST =
        new GrammarRootAST(new CommonToken(ANTLRParser.GRAMMAR, "LEXER_GRAMMAR"), combinedGrammar.ast.tokenStream);
    lexerAST.grammarType = ANTLRParser.LEXER;
    lexerAST.token.setInputStream(combinedAST.token.getInputStream());
    lexerAST.addChild((GrammarAST)adaptor.create(ANTLRParser.ID, lexerName));

    // COPY OPTIONS
    GrammarAST optionsRoot =
      (GrammarAST)combinedAST.getFirstChildWithType(ANTLRParser.OPTIONS);
    if ( optionsRoot!=null && optionsRoot.getChildCount()!=0 ) {
View Full Code Here

    if ( combinedRulesRoot==null ) return lexerAST;

    // MOVE lexer rules

    GrammarAST lexerRulesRoot =
      (GrammarAST)adaptor.create(ANTLRParser.RULES, "RULES");
    lexerAST.addChild(lexerRulesRoot);
    List<GrammarAST> rulesWeMoved = new ArrayList<GrammarAST>();
    GrammarASTWithOptions[] rules;
    if (combinedRulesRoot.getChildCount() > 0) {
      rules = combinedRulesRoot.getChildren().toArray(new GrammarASTWithOptions[0]);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.