Package org.antlr.v4.tool
Class GrammarTransformPipeline
java.lang.Object
org.antlr.v4.tool.GrammarTransformPipeline
Handle left-recursion and block-set transforms
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
void
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.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.void
integrateImportedGrammars
(Grammar rootGrammar) Merge all the rules, token definitions, and named actions from imported grammars into the root grammar tree.void
process()
void
reduceBlocksToSets
(GrammarAST root) static void
setGrammarPtr
(Grammar g, GrammarAST tree) Utility visitor that sets grammar ptr in each node
-
Field Details
-
g
-
tool
-
-
Constructor Details
-
GrammarTransformPipeline
-
-
Method Details
-
process
public void process() -
reduceBlocksToSets
-
expandParameterizedLoops
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? -
expandParameterizedLoop
-
setGrammarPtr
Utility visitor that sets grammar ptr in each node -
augmentTokensWithOriginalPosition
-
integrateImportedGrammars
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
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
-