Package org.antlr.v4.tool
Class GrammarTransformPipeline
- java.lang.Object
-
- org.antlr.v4.tool.GrammarTransformPipeline
-
public class GrammarTransformPipeline extends Object
Handle left-recursion and block-set transforms
-
-
Constructor Summary
Constructors Constructor Description GrammarTransformPipeline(Grammar g, Tool tool)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
augmentTokensWithOriginalPosition(Grammar g, GrammarAST tree)
GrammarAST
expandParameterizedLoop(GrammarAST t)
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.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.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
-
-
-
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?
-
expandParameterizedLoop
public GrammarAST expandParameterizedLoop(GrammarAST t)
-
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
-
-