forked from jasder/antlr
refactor grammar transform pipeline
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9454]
This commit is contained in:
parent
5dfc4aed1d
commit
3b543098aa
|
@ -256,7 +256,6 @@ public class Tool {
|
|||
public void process(Grammar g, boolean gencode) {
|
||||
g.loadImportedGrammars();
|
||||
|
||||
GrammarTransformPipeline.integrateImportedGrammars(g);
|
||||
|
||||
GrammarTransformPipeline transform = new GrammarTransformPipeline(g, this);
|
||||
transform.process();
|
||||
|
@ -266,7 +265,7 @@ public class Tool {
|
|||
if ( g.ast!=null && g.ast.grammarType== ANTLRParser.COMBINED &&
|
||||
!g.ast.hasErrors )
|
||||
{
|
||||
lexerAST = GrammarTransformPipeline.extractImplicitLexer(g); // alters g.ast
|
||||
lexerAST = transform.extractImplicitLexer(g); // alters g.ast
|
||||
if ( lexerAST!=null ) {
|
||||
lexerg = new LexerGrammar(this, lexerAST);
|
||||
lexerg.fileName = g.fileName;
|
||||
|
|
|
@ -55,11 +55,12 @@ public class GrammarTransformPipeline {
|
|||
if ( ast==null ) return;
|
||||
tool.log("grammar", "before: "+ast.toStringTree());
|
||||
|
||||
integrateImportedGrammars(g);
|
||||
if ( ast.grammarType==ANTLRParser.PARSER || ast.grammarType==ANTLRParser.COMBINED ) {
|
||||
translateLeftRecursiveRules(ast);
|
||||
}
|
||||
|
||||
reduceBlocksToSets(ast);
|
||||
|
||||
tool.log("grammar", "after: "+ast.toStringTree());
|
||||
}
|
||||
|
||||
|
@ -146,6 +147,7 @@ public class GrammarTransformPipeline {
|
|||
return null;
|
||||
}
|
||||
|
||||
/** Utility visitor that sets grammar ptr in each node */
|
||||
public static void setGrammarPtr(final Grammar g, GrammarAST tree) {
|
||||
// ensure each node has pointer to surrounding grammar
|
||||
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
|
||||
|
@ -169,7 +171,7 @@ public class GrammarTransformPipeline {
|
|||
The goal is a complete combined grammar so we can ignore subordinate
|
||||
grammars.
|
||||
*/
|
||||
public static void integrateImportedGrammars(Grammar rootGrammar) {
|
||||
public void integrateImportedGrammars(Grammar rootGrammar) {
|
||||
List<Grammar> imports = rootGrammar.getAllImportedGrammars();
|
||||
if ( imports==null ) return;
|
||||
|
||||
|
@ -305,7 +307,7 @@ public class GrammarTransformPipeline {
|
|||
* in combined AST. Anything cut out is dup'd before
|
||||
* adding to lexer to avoid "who's ur daddy" issues
|
||||
*/
|
||||
public static GrammarRootAST extractImplicitLexer(Grammar combinedGrammar) {
|
||||
public GrammarRootAST extractImplicitLexer(Grammar combinedGrammar) {
|
||||
GrammarRootAST combinedAST = combinedGrammar.ast;
|
||||
//tool.log("grammar", "before="+combinedAST.toStringTree());
|
||||
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(combinedAST.token.getInputStream());
|
||||
|
|
Loading…
Reference in New Issue