Top Description Fields Constructors Methods
org.antlr.v4.tool

public Class GrammarTransformPipeline

extends Object
Class Inheritance
Imports
org.antlr.runtime.CommonToken, org.antlr.runtime.tree.CommonTree, .CommonTreeNodeStream, .Tree, .TreeVisitor, .TreeVisitorAction, org.antlr.v4.Tool, org.antlr.v4.analysis.LeftRecursiveRuleTransformer, org.antlr.v4.parse.ANTLRParser, .BlockSetTransformer, .GrammarASTAdaptor, .GrammarToken, org.antlr.v4.runtime.misc.DoubleKeyMap, .Pair, org.antlr.v4.tool.ast.AltAST, .BlockAST, .GrammarAST, .GrammarASTWithOptions, .GrammarRootAST, .RuleAST, .TerminalAST, java.util.ArrayList, .Arrays, .HashSet, .List, .Map, .Set

Handle left-recursion and block-set transforms

Field Summary

Modifier and TypeField and Description
public Grammar
g

public Tool

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
public GrammarAST
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.

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.

public void
integrateImportedGrammars(Grammar rootGrammar)

Merge all the rules, token definitions, and named actions from imported grammars into the root grammar tree.

public void
public void
public static void
setGrammarPtr(final Grammar g, GrammarAST tree)

Utility visitor that sets grammar ptr in each node

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

gback to summary
public Grammar g
toolback to summary
public Tool tool

Constructor Detail

GrammarTransformPipelineback to summary
public GrammarTransformPipeline(Grammar g, Tool tool)

Method Detail

augmentTokensWithOriginalPositionback to summary
public static void augmentTokensWithOriginalPosition(final Grammar g, GrammarAST tree)
expandParameterizedLoopback to summary
public GrammarAST expandParameterizedLoop(GrammarAST t)
expandParameterizedLoopsback to summary
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?

extractImplicitLexerback to summary
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

integrateImportedGrammarsback to summary
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.

processback to summary
public void process()
reduceBlocksToSetsback to summary
public void reduceBlocksToSets(GrammarAST root)
setGrammarPtrback to summary
public static void setGrammarPtr(final Grammar g, GrammarAST tree)

Utility visitor that sets grammar ptr in each node