Class GrammarTransformPipeline


  • public class GrammarTransformPipeline
    extends Object
    Handle left-recursion and block-set transforms
    • Constructor Detail

      • GrammarTransformPipeline

        public GrammarTransformPipeline​(Grammar g,
                                        Tool tool)
    • Method Detail

      • process

        public void process()
      • reduceBlocksToSets

        public void reduceBlocksToSets​(GrammarAST root)
      • expandParameterizedLoops

        public void expandParameterizedLoops​(GrammarAST root)
        Find and replace ID*[','] with ID (',' ID)* ID+[','] with ID (',' ID)+ (x {action} y)+[','] with x {action} y (',' x {action} y)+ Parameter must be a token. todo: do we want?
      • setGrammarPtr

        public static void setGrammarPtr​(Grammar g,
                                         GrammarAST tree)
        Utility visitor that sets grammar ptr in each node
      • augmentTokensWithOriginalPosition

        public static void augmentTokensWithOriginalPosition​(Grammar g,
                                                             GrammarAST tree)
      • integrateImportedGrammars

        public void integrateImportedGrammars​(Grammar rootGrammar)
        Merge all the rules, token definitions, and named actions from imported grammars into the root grammar tree. Perform: (tokens { X (= Y 'y')) + (tokens { Z ) -> (tokens { X (= Y 'y') Z) (@ members {foo}) + (@ members {bar}) -> (@ members {foobar}) (RULES (RULE x y)) + (RULES (RULE z)) -> (RULES (RULE x y z)) Rules in root prevent same rule from being appended to RULES node. The goal is a complete combined grammar so we can ignore subordinate grammars.
      • extractImplicitLexer

        public GrammarRootAST extractImplicitLexer​(Grammar combinedGrammar)
        Build lexer grammar from combined grammar that looks like: (COMBINED_GRAMMAR A (tokens { X (= Y 'y')) (OPTIONS (= x 'y')) (@ members {foo}) (@ lexer header {package jj;}) (RULES (RULE .+))) Move rules and actions to new tree, don't dup. Split AST apart. We'll have this Grammar share token symbols later; don't generate tokenVocab or tokens{} section. Copy over named actions. Side-effects: it removes children from GRAMMAR & RULES nodes in combined AST. Anything cut out is dup'd before adding to lexer to avoid "who's ur daddy" issues