forked from jasder/antlr
major reorg to get rewrites in there
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 8821]
This commit is contained in:
parent
919e3a1c06
commit
07161bffe7
|
@ -52,8 +52,8 @@ public abstract class BaseTreeAdaptor implements TreeAdaptor {
|
||||||
public List getChildren(Object root) { return ((Tree)root).getChildren(); }
|
public List getChildren(Object root) { return ((Tree)root).getChildren(); }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public List createElementList() {
|
public List<Object> createElementList() {
|
||||||
return new ArrayList(5);
|
return new ArrayList(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
// END v4 stuff
|
// END v4 stuff
|
||||||
|
|
|
@ -51,7 +51,7 @@ public interface TreeAdaptor {
|
||||||
//public List getChildren(Object root);
|
//public List getChildren(Object root);
|
||||||
|
|
||||||
/** Used to track elements to left of -> for use in rewrite */
|
/** Used to track elements to left of -> for use in rewrite */
|
||||||
public List createElementList();
|
public List<Object> createElementList();
|
||||||
|
|
||||||
// END new v4 stuff
|
// END new v4 stuff
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
grammar T;
|
grammar T;
|
||||||
options {output=AST;}
|
options {output=AST;}
|
||||||
tokens {I;}
|
tokens {I;}
|
||||||
a : A b -> A b ;
|
a : A b ';' -> A b ';' ;
|
||||||
|
|
||||||
b : B ;
|
b : B ;
|
||||||
|
|
||||||
|
|
|
@ -121,7 +121,7 @@ public QStack\<<currentRule.ctxType>\> <currentRule.name>_stk = new QStack\<<cur
|
||||||
}
|
}
|
||||||
>>
|
>>
|
||||||
|
|
||||||
CodeBlock(c, ops) ::= <<
|
CodeBlockForAlt(c, ops) ::= <<
|
||||||
<ops; separator="\n">
|
<ops; separator="\n">
|
||||||
>>
|
>>
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ public static class <s.name> extends ParserRuleContext {
|
||||||
|
|
||||||
AttributeDecl(d) ::= "<d.decl>"
|
AttributeDecl(d) ::= "<d.decl>"
|
||||||
|
|
||||||
/** If we don't know location of label def, use this template */
|
/** If we don't know location of label def x, use this template */
|
||||||
labelref(x) ::= "<if(!x.isLocal)>_localctx.<endif><x.name>"
|
labelref(x) ::= "<if(!x.isLocal)>_localctx.<endif><x.name>"
|
||||||
|
|
||||||
// AST stuff (TODO: separate?)
|
// AST stuff (TODO: separate?)
|
||||||
|
@ -371,9 +371,18 @@ _localctx.tree = _root0;
|
||||||
_adaptor.setTokenBoundaries(_localctx.tree, _localctx.start, _localctx.stop);
|
_adaptor.setTokenBoundaries(_localctx.tree, _localctx.start, _localctx.stop);
|
||||||
>>
|
>>
|
||||||
|
|
||||||
ElementListDecl(d) ::= "List <d.name> = new ArrayList(5);"
|
ElementListDecl(d) ::= "List\<Object> <d.name> = _adaptor.createElementList();"
|
||||||
ElementListName(elemName) ::= "_track_<elemName>"
|
ElementListName(elemName) ::= "_track_<elemName>"
|
||||||
TrackElement(e) ::= "_track_<e.name>.add(<labelref(e.label)>);"
|
TrackRuleElement(e) ::= "<e.name>.add(<labelref(e.label)>);"
|
||||||
|
TrackTokenElement(e) ::= "<e.name>.add(_adaptor.create(<labelref(e.label)>));"
|
||||||
|
|
||||||
|
TreeRewrite(tr, ops) ::= <<
|
||||||
|
// rewrite: ...
|
||||||
|
<ops; separator="\n">
|
||||||
|
>>
|
||||||
|
|
||||||
|
RewriteTokenRef(t) ::= "/* tokenref */"
|
||||||
|
RewriteRuleRef(r) ::= "/* ruleref */"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
BitSetDecl(b) ::= <<
|
BitSetDecl(b) ::= <<
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
[The "BSD license"]
|
||||||
|
Copyright (c) 2011 Terence Parr
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.antlr.v4.codegen;
|
||||||
|
|
||||||
|
import org.antlr.v4.codegen.model.*;
|
||||||
|
import org.antlr.v4.codegen.model.ast.TreeRewrite;
|
||||||
|
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||||
|
import org.antlr.v4.tool.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class BlankOutputModelFactory implements OutputModelFactory {
|
||||||
|
public ParserFile parserFile(String fileName) { return null; }
|
||||||
|
|
||||||
|
public Parser parser(ParserFile file) { return null; }
|
||||||
|
|
||||||
|
public RuleFunction rule(Rule r) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> rulePostamble(RuleFunction function, Rule r) { return null; }
|
||||||
|
|
||||||
|
public LexerFile lexerFile(String fileName) { return null; }
|
||||||
|
|
||||||
|
public Lexer lexer(LexerFile file) { return null; }
|
||||||
|
|
||||||
|
// ALTERNATIVES / ELEMENTS
|
||||||
|
|
||||||
|
public CodeBlockForAlt alternative(List<SrcOp> elems) { return null; }
|
||||||
|
|
||||||
|
public CodeBlockForAlt epsilon() { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> tokenRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> stringRef(GrammarAST ID, GrammarAST label) { return tokenRef(ID, label, null); }
|
||||||
|
|
||||||
|
// ACTIONS
|
||||||
|
|
||||||
|
public List<SrcOp> action(GrammarAST ast) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> forcedAction(GrammarAST ast) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> sempred(GrammarAST ast) { return null; }
|
||||||
|
|
||||||
|
// AST OPS
|
||||||
|
|
||||||
|
public List<SrcOp> rootToken(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
|
public List<SrcOp> rootRule(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
|
// AST REWRITES
|
||||||
|
|
||||||
|
public TreeRewrite treeRewrite(List<SrcOp> ops) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> rewrite_ruleRef(GrammarAST ID) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> rewrite_tokenRef(GrammarAST ID) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> rewrite_stringRef(GrammarAST ID) { return rewrite_tokenRef(ID); }
|
||||||
|
|
||||||
|
// BLOCKS
|
||||||
|
|
||||||
|
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) { return null; }
|
||||||
|
|
||||||
|
public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) { return null; }
|
||||||
|
|
||||||
|
public Choice getLL1ChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) { return null; }
|
||||||
|
|
||||||
|
public Choice getLLStarChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) { return null; }
|
||||||
|
|
||||||
|
public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) { return null; }
|
||||||
|
|
||||||
|
public Choice getLLStarEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) { return null; }
|
||||||
|
|
||||||
|
public List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST) { return null; }
|
||||||
|
|
||||||
|
public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) { return false; }
|
||||||
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ package org.antlr.v4.codegen;
|
||||||
|
|
||||||
|
|
||||||
import org.antlr.v4.codegen.model.*;
|
import org.antlr.v4.codegen.model.*;
|
||||||
|
import org.antlr.v4.codegen.model.ast.TreeRewrite;
|
||||||
import org.antlr.v4.tool.GrammarAST;
|
import org.antlr.v4.tool.GrammarAST;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -55,7 +56,9 @@ public class CodeGeneratorExtension {
|
||||||
|
|
||||||
public List<SrcOp> rulePostamble(List<SrcOp> ops) { return ops; }
|
public List<SrcOp> rulePostamble(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
public List<SrcOp> alternative(List<SrcOp> ops) { return ops; }
|
public CodeBlockForAlt alternative(CodeBlockForAlt blk) { return blk; }
|
||||||
|
|
||||||
|
public CodeBlockForAlt epsilon(CodeBlockForAlt blk) { return blk; }
|
||||||
|
|
||||||
public List<SrcOp> ruleRef(List<SrcOp> ops) { return ops; }
|
public List<SrcOp> ruleRef(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
|
@ -63,7 +66,6 @@ public class CodeGeneratorExtension {
|
||||||
|
|
||||||
public List<SrcOp> stringRef(List<SrcOp> ops) { return ops; }
|
public List<SrcOp> stringRef(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
public List<SrcOp> epsilon(List<SrcOp> ops) { return ops; }
|
|
||||||
|
|
||||||
// ACTIONS
|
// ACTIONS
|
||||||
|
|
||||||
|
@ -85,10 +87,14 @@ public class CodeGeneratorExtension {
|
||||||
|
|
||||||
// AST REWRITEs
|
// AST REWRITEs
|
||||||
|
|
||||||
|
public TreeRewrite treeRewrite(TreeRewrite code) { return code; }
|
||||||
|
|
||||||
public List<SrcOp> rewrite_ruleRef(List<SrcOp> ops) { return ops; }
|
public List<SrcOp> rewrite_ruleRef(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
public List<SrcOp> rewrite_tokenRef(List<SrcOp> ops) { return ops; }
|
public List<SrcOp> rewrite_tokenRef(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
|
public List<SrcOp> rewrite_stringRef(List<SrcOp> ops) { return ops; }
|
||||||
|
|
||||||
// BLOCKS
|
// BLOCKS
|
||||||
|
|
||||||
public List<SrcOp> getChoiceBlock(List<SrcOp> ops) { return ops; }
|
public List<SrcOp> getChoiceBlock(List<SrcOp> ops) { return ops; }
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
package org.antlr.v4.codegen;
|
package org.antlr.v4.codegen;
|
||||||
|
|
||||||
import org.antlr.v4.codegen.model.*;
|
import org.antlr.v4.codegen.model.*;
|
||||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.tool.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -40,7 +39,7 @@ import java.util.*;
|
||||||
* objects such as RuleFunction that surround elements in rule
|
* objects such as RuleFunction that surround elements in rule
|
||||||
* functions.
|
* functions.
|
||||||
*/
|
*/
|
||||||
public abstract class DefaultOutputModelFactory implements OutputModelFactory {
|
public abstract class DefaultOutputModelFactory extends BlankOutputModelFactory {
|
||||||
// Interface to outside world
|
// Interface to outside world
|
||||||
public Grammar g;
|
public Grammar g;
|
||||||
public CodeGenerator gen;
|
public CodeGenerator gen;
|
||||||
|
@ -60,71 +59,6 @@ public abstract class DefaultOutputModelFactory implements OutputModelFactory {
|
||||||
|
|
||||||
public CodeGenerator getGenerator() { return gen; }
|
public CodeGenerator getGenerator() { return gen; }
|
||||||
|
|
||||||
public ParserFile parserFile(String fileName) { return null; }
|
|
||||||
|
|
||||||
public Parser parser(ParserFile file) { return null; }
|
|
||||||
|
|
||||||
public RuleFunction rule(Rule r) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> rulePostamble(RuleFunction function, Rule r) { return null; }
|
|
||||||
|
|
||||||
public LexerFile lexerFile(String fileName) { return null; }
|
|
||||||
|
|
||||||
public Lexer lexer(LexerFile file) { return null; }
|
|
||||||
|
|
||||||
// ALTERNATIVES / ELEMENTS
|
|
||||||
|
|
||||||
public List<SrcOp> alternative(List<SrcOp> elems) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> tokenRef(GrammarAST ID, GrammarAST label, GrammarAST args) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> stringRef(GrammarAST ID, GrammarAST label) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> epsilon() { return null; }
|
|
||||||
|
|
||||||
// ACTIONS
|
|
||||||
|
|
||||||
public List<SrcOp> action(GrammarAST ast) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> forcedAction(GrammarAST ast) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> sempred(GrammarAST ast) { return null; }
|
|
||||||
|
|
||||||
// AST OPS
|
|
||||||
|
|
||||||
public List<SrcOp> rootToken(List<SrcOp> ops) { return ops; }
|
|
||||||
|
|
||||||
public List<SrcOp> rootRule(List<SrcOp> ops) { return ops; }
|
|
||||||
|
|
||||||
// AST REWRITES
|
|
||||||
|
|
||||||
public List<SrcOp> rewrite_ruleRef(GrammarAST ID) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> rewrite_tokenRef(GrammarAST ID) { return null; }
|
|
||||||
|
|
||||||
// BLOCKS
|
|
||||||
|
|
||||||
public List<SrcOp> getChoiceBlock(BlockAST blkAST, List<SrcOp> alts) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> getEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> getLL1ChoiceBlock(BlockAST blkAST, List<SrcOp> alts) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> getLLStarChoiceBlock(BlockAST blkAST, List<SrcOp> alts) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> getLL1EBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> getLLStarEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) { return null; }
|
|
||||||
|
|
||||||
public List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST) { return null; }
|
|
||||||
|
|
||||||
public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) { return false; }
|
|
||||||
|
|
||||||
|
|
||||||
// SET CONTEXT
|
|
||||||
|
|
||||||
public OutputModelObject getRoot() { return root; }
|
public OutputModelObject getRoot() { return root; }
|
||||||
|
|
||||||
public void setRoot(OutputModelObject root) { this.root = root; }
|
public void setRoot(OutputModelObject root) { this.root = root; }
|
||||||
|
|
|
@ -31,6 +31,7 @@ package org.antlr.v4.codegen;
|
||||||
|
|
||||||
import org.antlr.runtime.tree.*;
|
import org.antlr.runtime.tree.*;
|
||||||
import org.antlr.v4.codegen.model.*;
|
import org.antlr.v4.codegen.model.*;
|
||||||
|
import org.antlr.v4.codegen.model.ast.TreeRewrite;
|
||||||
import org.antlr.v4.parse.*;
|
import org.antlr.v4.parse.*;
|
||||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.tool.*;
|
||||||
|
@ -76,7 +77,7 @@ public class OutputModelController implements OutputModelFactory {
|
||||||
CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
|
CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor,blk);
|
||||||
SourceGenTriggers genTriggers = new SourceGenTriggers(nodes, this);
|
SourceGenTriggers genTriggers = new SourceGenTriggers(nodes, this);
|
||||||
try {
|
try {
|
||||||
function.code = genTriggers.block(null,null); // walk AST of rule alts/elements
|
function.code = DefaultOutputModelFactory.list(genTriggers.block(null, null)); // walk AST of rule alts/elements
|
||||||
}
|
}
|
||||||
catch (Exception e){
|
catch (Exception e){
|
||||||
e.printStackTrace(System.err);
|
e.printStackTrace(System.err);
|
||||||
|
@ -138,10 +139,10 @@ public class OutputModelController implements OutputModelFactory {
|
||||||
|
|
||||||
public CodeGenerator getGenerator() { return delegate.getGenerator(); }
|
public CodeGenerator getGenerator() { return delegate.getGenerator(); }
|
||||||
|
|
||||||
public List<SrcOp> alternative(List<SrcOp> elems) {
|
public CodeBlockForAlt alternative(List<SrcOp> elems) {
|
||||||
List<SrcOp> ops = delegate.alternative(elems);
|
CodeBlockForAlt code = delegate.alternative(elems);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.alternative(ops);
|
for (CodeGeneratorExtension ext : extensions) code = ext.alternative(code);
|
||||||
return ops;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
|
public List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args) {
|
||||||
|
@ -178,10 +179,10 @@ public class OutputModelController implements OutputModelFactory {
|
||||||
return ops;
|
return ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> epsilon() {
|
public CodeBlockForAlt epsilon() {
|
||||||
List<SrcOp> ops = delegate.epsilon();
|
CodeBlockForAlt blk = delegate.epsilon();
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.epsilon(ops);
|
for (CodeGeneratorExtension ext : extensions) blk = ext.epsilon(blk);
|
||||||
return ops;
|
return blk;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> action(GrammarAST ast) {
|
public List<SrcOp> action(GrammarAST ast) {
|
||||||
|
@ -214,40 +215,46 @@ public class OutputModelController implements OutputModelFactory {
|
||||||
return ops;
|
return ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getChoiceBlock(BlockAST blkAST, List<SrcOp> alts) {
|
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
List<SrcOp> ops = delegate.getChoiceBlock(blkAST, alts);
|
Choice c = delegate.getChoiceBlock(blkAST, alts);
|
||||||
|
List<SrcOp> ops = DefaultOutputModelFactory.list(c);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.getChoiceBlock(ops);
|
for (CodeGeneratorExtension ext : extensions) ops = ext.getChoiceBlock(ops);
|
||||||
return ops;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) {
|
public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
|
||||||
List<SrcOp> ops = delegate.getEBNFBlock(ebnfRoot, alts);
|
Choice c = delegate.getEBNFBlock(ebnfRoot, alts);
|
||||||
|
List<SrcOp> ops = DefaultOutputModelFactory.list(c);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.getEBNFBlock(ops);
|
for (CodeGeneratorExtension ext : extensions) ops = ext.getEBNFBlock(ops);
|
||||||
return ops;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLL1ChoiceBlock(BlockAST blkAST, List<SrcOp> alts) {
|
public Choice getLL1ChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
List<SrcOp> ops = delegate.getLL1ChoiceBlock(blkAST, alts);
|
Choice c = delegate.getLL1ChoiceBlock(blkAST, alts);
|
||||||
|
List<SrcOp> ops = DefaultOutputModelFactory.list(c);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.getLL1ChoiceBlock(ops);
|
for (CodeGeneratorExtension ext : extensions) ops = ext.getLL1ChoiceBlock(ops);
|
||||||
return ops;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLLStarChoiceBlock(BlockAST blkAST, List<SrcOp> alts) {
|
public Choice getLLStarChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
List<SrcOp> ops = delegate.getLLStarChoiceBlock(blkAST, alts);
|
Choice c = delegate.getLLStarChoiceBlock(blkAST, alts);
|
||||||
|
List<SrcOp> ops = DefaultOutputModelFactory.list(c);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.getLLStarChoiceBlock(ops);
|
for (CodeGeneratorExtension ext : extensions) ops = ext.getLLStarChoiceBlock(ops);
|
||||||
return ops;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLL1EBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) {
|
public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
|
||||||
List<SrcOp> ops = delegate.getLL1EBNFBlock(ebnfRoot, alts);
|
Choice c = delegate.getLL1EBNFBlock(ebnfRoot, alts);
|
||||||
|
List<SrcOp> ops = DefaultOutputModelFactory.list(c);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.getLL1EBNFBlock(ops);
|
for (CodeGeneratorExtension ext : extensions) ops = ext.getLL1EBNFBlock(ops);
|
||||||
return ops;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLLStarEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) {
|
public Choice getLLStarEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
|
||||||
List<SrcOp> ops = delegate.getLLStarEBNFBlock(ebnfRoot, alts);
|
Choice c = delegate.getLLStarEBNFBlock(ebnfRoot, alts);
|
||||||
|
List<SrcOp> ops = DefaultOutputModelFactory.list(c);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.getLLStarEBNFBlock(ops);
|
for (CodeGeneratorExtension ext : extensions) ops = ext.getLLStarEBNFBlock(ops);
|
||||||
return ops;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST) {
|
public List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST) {
|
||||||
|
@ -262,6 +269,14 @@ public class OutputModelController implements OutputModelFactory {
|
||||||
return needs;
|
return needs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// REWRITES
|
||||||
|
|
||||||
|
public TreeRewrite treeRewrite(List<SrcOp> ops) {
|
||||||
|
TreeRewrite r = delegate.treeRewrite(ops);
|
||||||
|
for (CodeGeneratorExtension ext : extensions) r = ext.treeRewrite(r);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
public List<SrcOp> rewrite_ruleRef(GrammarAST ID) {
|
public List<SrcOp> rewrite_ruleRef(GrammarAST ID) {
|
||||||
List<SrcOp> ops = delegate.rewrite_ruleRef(ID);
|
List<SrcOp> ops = delegate.rewrite_ruleRef(ID);
|
||||||
for (CodeGeneratorExtension ext : extensions) ops = ext.rewrite_ruleRef(ops);
|
for (CodeGeneratorExtension ext : extensions) ops = ext.rewrite_ruleRef(ops);
|
||||||
|
@ -274,6 +289,8 @@ public class OutputModelController implements OutputModelFactory {
|
||||||
return ops;
|
return ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<SrcOp> rewrite_stringRef(GrammarAST ID) { return rewrite_tokenRef(ID); }
|
||||||
|
|
||||||
public OutputModelObject getRoot() { return delegate.getRoot(); }
|
public OutputModelObject getRoot() { return delegate.getRoot(); }
|
||||||
|
|
||||||
public void setRoot(OutputModelObject root) { delegate.setRoot(root); }
|
public void setRoot(OutputModelObject root) { delegate.setRoot(root); }
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
package org.antlr.v4.codegen;
|
package org.antlr.v4.codegen;
|
||||||
|
|
||||||
import org.antlr.v4.codegen.model.*;
|
import org.antlr.v4.codegen.model.*;
|
||||||
|
import org.antlr.v4.codegen.model.ast.TreeRewrite;
|
||||||
import org.antlr.v4.runtime.misc.IntervalSet;
|
import org.antlr.v4.runtime.misc.IntervalSet;
|
||||||
import org.antlr.v4.tool.*;
|
import org.antlr.v4.tool.*;
|
||||||
|
|
||||||
|
@ -54,7 +55,9 @@ public interface OutputModelFactory {
|
||||||
|
|
||||||
// ELEMENT TRIGGERS
|
// ELEMENT TRIGGERS
|
||||||
|
|
||||||
List<SrcOp> alternative(List<SrcOp> elems);
|
CodeBlockForAlt alternative(List<SrcOp> elems);
|
||||||
|
|
||||||
|
CodeBlockForAlt epsilon();
|
||||||
|
|
||||||
List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args);
|
List<SrcOp> ruleRef(GrammarAST ID, GrammarAST label, GrammarAST args);
|
||||||
|
|
||||||
|
@ -62,8 +65,6 @@ public interface OutputModelFactory {
|
||||||
|
|
||||||
List<SrcOp> stringRef(GrammarAST ID, GrammarAST label);
|
List<SrcOp> stringRef(GrammarAST ID, GrammarAST label);
|
||||||
|
|
||||||
List<SrcOp> epsilon();
|
|
||||||
|
|
||||||
List<SrcOp> action(GrammarAST ast);
|
List<SrcOp> action(GrammarAST ast);
|
||||||
|
|
||||||
List<SrcOp> forcedAction(GrammarAST ast);
|
List<SrcOp> forcedAction(GrammarAST ast);
|
||||||
|
@ -74,17 +75,17 @@ public interface OutputModelFactory {
|
||||||
|
|
||||||
List<SrcOp> rootRule(List<SrcOp> ops);
|
List<SrcOp> rootRule(List<SrcOp> ops);
|
||||||
|
|
||||||
List<SrcOp> getChoiceBlock(BlockAST blkAST, List<SrcOp> alts);
|
Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts);
|
||||||
|
|
||||||
List<SrcOp> getEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts);
|
Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts);
|
||||||
|
|
||||||
List<SrcOp> getLL1ChoiceBlock(BlockAST blkAST, List<SrcOp> alts);
|
Choice getLL1ChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts);
|
||||||
|
|
||||||
List<SrcOp> getLLStarChoiceBlock(BlockAST blkAST, List<SrcOp> alts);
|
Choice getLLStarChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts);
|
||||||
|
|
||||||
List<SrcOp> getLL1EBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts);
|
Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts);
|
||||||
|
|
||||||
List<SrcOp> getLLStarEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts);
|
Choice getLLStarEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts);
|
||||||
|
|
||||||
List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST);
|
List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST);
|
||||||
|
|
||||||
|
@ -92,10 +93,14 @@ public interface OutputModelFactory {
|
||||||
|
|
||||||
// AST REWRITE TRIGGERS
|
// AST REWRITE TRIGGERS
|
||||||
|
|
||||||
|
TreeRewrite treeRewrite(List<SrcOp> ops);
|
||||||
|
|
||||||
List<SrcOp> rewrite_ruleRef(GrammarAST ID);
|
List<SrcOp> rewrite_ruleRef(GrammarAST ID);
|
||||||
|
|
||||||
List<SrcOp> rewrite_tokenRef(GrammarAST ID);
|
List<SrcOp> rewrite_tokenRef(GrammarAST ID);
|
||||||
|
|
||||||
|
List<SrcOp> rewrite_stringRef(GrammarAST ID);
|
||||||
|
|
||||||
// CONTEXT MANIPULATION
|
// CONTEXT MANIPULATION
|
||||||
|
|
||||||
OutputModelObject getRoot();
|
OutputModelObject getRoot();
|
||||||
|
|
|
@ -82,12 +82,15 @@ public class ParserASTExtension extends CodeGeneratorExtension {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SrcOp> leafRule(List<SrcOp> ops) {
|
public List<SrcOp> leafRule(List<SrcOp> ops) {
|
||||||
|
InvokeRule invokeOp = (InvokeRule)Utils.find(ops, InvokeRule.class);
|
||||||
Alternative alt = factory.getCurrentAlt();
|
Alternative alt = factory.getCurrentAlt();
|
||||||
if ( alt.hasRewrite() ) {
|
if ( alt.hasRewrite() ) {
|
||||||
return ops;
|
RuleFunction rf = factory.getCurrentRule();
|
||||||
|
rf.addLocalDecl(new ElementListDecl(factory, invokeOp.ast));
|
||||||
|
TrackRuleElement t = new TrackRuleElement(factory, invokeOp.ast, invokeOp);
|
||||||
|
return DefaultOutputModelFactory.list(ops, t);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
InvokeRule invokeOp = (InvokeRule)Utils.find(ops, InvokeRule.class);
|
|
||||||
SrcOp treeOp = new AddRuleLeaf(factory, invokeOp.ast, invokeOp);
|
SrcOp treeOp = new AddRuleLeaf(factory, invokeOp.ast, invokeOp);
|
||||||
return DefaultOutputModelFactory.list(ops, treeOp);
|
return DefaultOutputModelFactory.list(ops, treeOp);
|
||||||
}
|
}
|
||||||
|
@ -100,7 +103,7 @@ public class ParserASTExtension extends CodeGeneratorExtension {
|
||||||
if ( alt.hasRewrite() ) {
|
if ( alt.hasRewrite() ) {
|
||||||
RuleFunction rf = factory.getCurrentRule();
|
RuleFunction rf = factory.getCurrentRule();
|
||||||
rf.addLocalDecl(new ElementListDecl(factory, matchOp.ast));
|
rf.addLocalDecl(new ElementListDecl(factory, matchOp.ast));
|
||||||
TrackElement t = new TrackElement(factory, matchOp.ast, matchOp);
|
TrackTokenElement t = new TrackTokenElement(factory, matchOp.ast, matchOp);
|
||||||
return DefaultOutputModelFactory.list(ops, t);
|
return DefaultOutputModelFactory.list(ops, t);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -109,8 +112,29 @@ public class ParserASTExtension extends CodeGeneratorExtension {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SrcOp> stringRef(List<SrcOp> ops) { return leafToken(ops); }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) {
|
public boolean needsImplicitLabel(GrammarAST ID, LabeledOp op) {
|
||||||
return op.getLabels().size()==0 && factory.getGrammar().hasASTOption();
|
return op.getLabels().size()==0 && factory.getGrammar().hasASTOption();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// REWRITES
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SrcOp> rewrite_ruleRef(List<SrcOp> ops) {
|
||||||
|
return super.rewrite_ruleRef(ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SrcOp> rewrite_tokenRef(List<SrcOp> ops) {
|
||||||
|
return super.rewrite_tokenRef(ops);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<SrcOp> rewrite_stringRef(List<SrcOp> ops) {
|
||||||
|
return super.rewrite_stringRef(ops);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ package org.antlr.v4.codegen;
|
||||||
|
|
||||||
import org.antlr.v4.analysis.AnalysisPipeline;
|
import org.antlr.v4.analysis.AnalysisPipeline;
|
||||||
import org.antlr.v4.codegen.model.*;
|
import org.antlr.v4.codegen.model.*;
|
||||||
|
import org.antlr.v4.codegen.model.ast.*;
|
||||||
import org.antlr.v4.codegen.model.decl.*;
|
import org.antlr.v4.codegen.model.decl.*;
|
||||||
import org.antlr.v4.parse.ANTLRParser;
|
import org.antlr.v4.parse.ANTLRParser;
|
||||||
import org.antlr.v4.runtime.atn.*;
|
import org.antlr.v4.runtime.atn.*;
|
||||||
|
@ -55,9 +56,9 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
return new RuleFunction(this, r);
|
return new RuleFunction(this, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> epsilon() { return list(new CodeBlock(this)); }
|
public CodeBlockForAlt epsilon() { return new CodeBlockForAlt(this); }
|
||||||
|
|
||||||
public List<SrcOp> alternative(List<SrcOp> elems) { return list(new CodeBlock(this, elems)); }
|
public CodeBlockForAlt alternative(List<SrcOp> elems) { return new CodeBlockForAlt(this, elems); }
|
||||||
|
|
||||||
public List<SrcOp> action(GrammarAST ast) { return list(new Action(this, ast)); }
|
public List<SrcOp> action(GrammarAST ast) { return list(new Action(this, ast)); }
|
||||||
|
|
||||||
|
@ -81,11 +82,7 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
return list(matchOp, listLabelOp);
|
return list(matchOp, listLabelOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> stringRef(GrammarAST ID, GrammarAST label) {
|
public Choice getChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
return tokenRef(ID, label, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SrcOp> getChoiceBlock(BlockAST blkAST, List<SrcOp> alts) {
|
|
||||||
int decision = ((DecisionState)blkAST.atnState).decision;
|
int decision = ((DecisionState)blkAST.atnState).decision;
|
||||||
if ( AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) {
|
if ( AnalysisPipeline.disjoint(g.decisionLOOK.get(decision)) ) {
|
||||||
return getLL1ChoiceBlock(blkAST, alts);
|
return getLL1ChoiceBlock(blkAST, alts);
|
||||||
|
@ -95,7 +92,7 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) {
|
public Choice getEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
|
||||||
int decision;
|
int decision;
|
||||||
if ( ebnfRoot.getType()==ANTLRParser.POSITIVE_CLOSURE ) {
|
if ( ebnfRoot.getType()==ANTLRParser.POSITIVE_CLOSURE ) {
|
||||||
decision = ((PlusBlockStartState)ebnfRoot.atnState).loopBackState.decision;
|
decision = ((PlusBlockStartState)ebnfRoot.atnState).loopBackState.decision;
|
||||||
|
@ -114,15 +111,15 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLL1ChoiceBlock(BlockAST blkAST, List<SrcOp> alts) {
|
public Choice getLL1ChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
return list(new LL1AltBlock(this, blkAST, alts));
|
return new LL1AltBlock(this, blkAST, alts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLLStarChoiceBlock(BlockAST blkAST, List<SrcOp> alts) {
|
public Choice getLLStarChoiceBlock(BlockAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
return list(new AltBlock(this, blkAST, alts));
|
return new AltBlock(this, blkAST, alts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLL1EBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) {
|
public Choice getLL1EBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
|
||||||
int ebnf = 0;
|
int ebnf = 0;
|
||||||
if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType();
|
if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType();
|
||||||
Choice c = null;
|
Choice c = null;
|
||||||
|
@ -140,10 +137,10 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
else c = new LL1PlusBlock(this, ebnfRoot, alts);
|
else c = new LL1PlusBlock(this, ebnfRoot, alts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return list(c);
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLLStarEBNFBlock(GrammarAST ebnfRoot, List<SrcOp> alts) {
|
public Choice getLLStarEBNFBlock(GrammarAST ebnfRoot, List<CodeBlockForAlt> alts) {
|
||||||
int ebnf = 0;
|
int ebnf = 0;
|
||||||
if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType();
|
if ( ebnfRoot!=null ) ebnf = ebnfRoot.getType();
|
||||||
Choice c = null;
|
Choice c = null;
|
||||||
|
@ -158,7 +155,7 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
c = new PlusBlock(this, ebnfRoot, alts);
|
c = new PlusBlock(this, ebnfRoot, alts);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return list(c);
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST) {
|
public List<SrcOp> getLL1Test(IntervalSet look, GrammarAST blkAST) {
|
||||||
|
@ -173,12 +170,18 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
||||||
|
|
||||||
// AST REWRITE
|
// AST REWRITE
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TreeRewrite treeRewrite(List<SrcOp> ops) {
|
||||||
|
return new TreeRewrite(this, ops);
|
||||||
|
}
|
||||||
|
|
||||||
public List<SrcOp> rewrite_ruleRef(GrammarAST ID) {
|
public List<SrcOp> rewrite_ruleRef(GrammarAST ID) {
|
||||||
return null;
|
return list(new RewriteRuleRef(this, ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<SrcOp> rewrite_tokenRef(GrammarAST ID) {
|
public List<SrcOp> rewrite_tokenRef(GrammarAST ID) {
|
||||||
return null;
|
return list(new RewriteTokenRef(this, ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
// support
|
// support
|
||||||
|
|
|
@ -25,35 +25,41 @@ import java.util.HashMap;
|
||||||
|
|
||||||
dummy : block[null, null] ;
|
dummy : block[null, null] ;
|
||||||
|
|
||||||
block[GrammarAST label, GrammarAST ebnfRoot] returns [List<SrcOp> omos]
|
block[GrammarAST label, GrammarAST ebnfRoot] returns [List<? extends SrcOp> omos]
|
||||||
: ^( blk=BLOCK (^(OPTIONS .+))?
|
: ^( blk=BLOCK (^(OPTIONS .+))?
|
||||||
{List<SrcOp> alts = new ArrayList<SrcOp>();}
|
{List<CodeBlockForAlt> alts = new ArrayList<CodeBlockForAlt>();}
|
||||||
( alternative {alts.addAll($alternative.omos);} )+
|
( alternative {alts.add($alternative.altCodeBlock);} )+
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if ( alts.size()==1 && ebnfRoot==null) return alts;
|
if ( alts.size()==1 && ebnfRoot==null) return alts;
|
||||||
if ( ebnfRoot==null ) {
|
if ( ebnfRoot==null ) {
|
||||||
$omos = factory.getChoiceBlock((BlockAST)$blk, alts);
|
$omos = DefaultOutputModelFactory.list(factory.getChoiceBlock((BlockAST)$blk, alts));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$omos = factory.getEBNFBlock($ebnfRoot, alts);
|
$omos = DefaultOutputModelFactory.list(factory.getEBNFBlock($ebnfRoot, alts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
alternative returns [List<SrcOp> omos]
|
alternative returns [CodeBlockForAlt altCodeBlock]
|
||||||
@init {
|
@init {
|
||||||
List<SrcOp> elems = new ArrayList<SrcOp>();
|
List<SrcOp> elems = new ArrayList<SrcOp>();
|
||||||
// set alt if outer ALT only
|
// set alt if outer ALT only
|
||||||
if ( inContext("RULE BLOCK") && ((AltAST)$start).alt!=null ) factory.setCurrentAlt(((AltAST)$start).alt);
|
if ( inContext("RULE BLOCK") && ((AltAST)$start).alt!=null ) factory.setCurrentAlt(((AltAST)$start).alt);
|
||||||
}
|
}
|
||||||
: ^(ALT_REWRITE a=alternative {$omos=$a.omos;} (rewrite {DefaultOutputModelFactory.list($omos, $rewrite.omos);} | ))
|
: ^(ALT_REWRITE
|
||||||
| ^(ALT EPSILON) {$omos = factory.epsilon();}
|
a=alternative
|
||||||
|
( rewrite {$a.altCodeBlock.ops.add($rewrite.code);} // insert at end of alt's code
|
||||||
|
|
|
||||||
|
)
|
||||||
|
{$altCodeBlock=$a.altCodeBlock;}
|
||||||
|
)
|
||||||
|
| ^(ALT EPSILON) {$altCodeBlock = factory.epsilon();}
|
||||||
| ^( ALT ( element {if ($element.omos!=null) elems.addAll($element.omos);} )+ )
|
| ^( ALT ( element {if ($element.omos!=null) elems.addAll($element.omos);} )+ )
|
||||||
{$omos = factory.alternative(elems);}
|
{$altCodeBlock = factory.alternative(elems);}
|
||||||
;
|
;
|
||||||
|
|
||||||
element returns [List<SrcOp> omos]
|
element returns [List<? extends SrcOp> omos]
|
||||||
: labeledElement {$omos = $labeledElement.omos;}
|
: labeledElement {$omos = $labeledElement.omos;}
|
||||||
| atom[null] {$omos = $atom.omos;}
|
| atom[null] {$omos = $atom.omos;}
|
||||||
| ebnf {$omos = $ebnf.omos;}
|
| ebnf {$omos = $ebnf.omos;}
|
||||||
|
@ -64,7 +70,7 @@ element returns [List<SrcOp> omos]
|
||||||
| treeSpec
|
| treeSpec
|
||||||
;
|
;
|
||||||
|
|
||||||
labeledElement returns [List<SrcOp> omos]
|
labeledElement returns [List<? extends SrcOp> omos]
|
||||||
: ^(ASSIGN ID atom[$ID] ) {$omos = $atom.omos;}
|
: ^(ASSIGN ID atom[$ID] ) {$omos = $atom.omos;}
|
||||||
| ^(ASSIGN ID block[$ID,null]) {$omos = $block.omos;}
|
| ^(ASSIGN ID block[$ID,null]) {$omos = $block.omos;}
|
||||||
| ^(PLUS_ASSIGN ID atom[$ID]) {$omos = $atom.omos;}
|
| ^(PLUS_ASSIGN ID atom[$ID]) {$omos = $atom.omos;}
|
||||||
|
@ -75,7 +81,7 @@ treeSpec returns [SrcOp omo]
|
||||||
: ^(TREE_BEGIN (e=element )+)
|
: ^(TREE_BEGIN (e=element )+)
|
||||||
;
|
;
|
||||||
|
|
||||||
ebnf returns [List<SrcOp> omos]
|
ebnf returns [List<? extends SrcOp> omos]
|
||||||
: ^(astBlockSuffix block[null,null])
|
: ^(astBlockSuffix block[null,null])
|
||||||
| ^(OPTIONAL block[null,$OPTIONAL]) {$omos = $block.omos;}
|
| ^(OPTIONAL block[null,$OPTIONAL]) {$omos = $block.omos;}
|
||||||
| ^(CLOSURE block[null,$CLOSURE]) {$omos = $block.omos;}
|
| ^(CLOSURE block[null,$CLOSURE]) {$omos = $block.omos;}
|
||||||
|
@ -142,8 +148,8 @@ elementOption
|
||||||
|
|
||||||
// R E W R I T E S T U F F
|
// R E W R I T E S T U F F
|
||||||
|
|
||||||
rewrite returns [List<SrcOp> omos]
|
rewrite returns [Rewrite code]
|
||||||
: predicatedRewrite* nakedRewrite {$omos = nakedRewrite.omos;}
|
: predicatedRewrite* nakedRewrite {$code = factory.treeRewrite($nakedRewrite.omos);}
|
||||||
;
|
;
|
||||||
|
|
||||||
predicatedRewrite returns [List<SrcOp> omos]
|
predicatedRewrite returns [List<SrcOp> omos]
|
||||||
|
@ -157,15 +163,19 @@ nakedRewrite returns [List<SrcOp> omos]
|
||||||
;
|
;
|
||||||
|
|
||||||
rewriteTreeAlt returns [List<SrcOp> omos]
|
rewriteTreeAlt returns [List<SrcOp> omos]
|
||||||
: ^(ALT rewriteTreeElement+)
|
: ^(ALT
|
||||||
|
{List<SrcOp> elems = new ArrayList<SrcOp>();}
|
||||||
|
( rewriteTreeElement {elems.addAll($rewriteTreeElement.omos);} )+
|
||||||
|
)
|
||||||
|
{$omos = elems;}
|
||||||
| ETC
|
| ETC
|
||||||
| EPSILON
|
| EPSILON
|
||||||
;
|
;
|
||||||
|
|
||||||
rewriteTreeElement returns [List<SrcOp> omos]
|
rewriteTreeElement returns [List<SrcOp> omos]
|
||||||
: rewriteTreeAtom
|
: rewriteTreeAtom {$omos = $rewriteTreeAtom.omos;}
|
||||||
| rewriteTree
|
| rewriteTree {$omos = $rewriteTree.omos;}
|
||||||
| rewriteTreeEbnf
|
| rewriteTreeEbnf {$omos = $rewriteTreeEbnf.omos;}
|
||||||
;
|
;
|
||||||
|
|
||||||
rewriteTreeAtom returns [List<SrcOp> omos]
|
rewriteTreeAtom returns [List<SrcOp> omos]
|
||||||
|
@ -173,16 +183,16 @@ rewriteTreeAtom returns [List<SrcOp> omos]
|
||||||
| ^(TOKEN_REF elementOptions)
|
| ^(TOKEN_REF elementOptions)
|
||||||
| ^(TOKEN_REF ARG_ACTION)
|
| ^(TOKEN_REF ARG_ACTION)
|
||||||
| TOKEN_REF {$omos = factory.rewrite_tokenRef($TOKEN_REF);}
|
| TOKEN_REF {$omos = factory.rewrite_tokenRef($TOKEN_REF);}
|
||||||
| RULE_REF {$omos = factory.rewrite_ruleRef($TOKEN_REF);}
|
| RULE_REF {$omos = factory.rewrite_ruleRef($RULE_REF);}
|
||||||
| ^(STRING_LITERAL elementOptions)
|
| ^(STRING_LITERAL elementOptions) {$omos = factory.rewrite_stringRef($STRING_LITERAL);}
|
||||||
| STRING_LITERAL
|
| STRING_LITERAL {$omos = factory.rewrite_stringRef($STRING_LITERAL);}
|
||||||
| LABEL
|
| LABEL
|
||||||
| ACTION
|
| ACTION
|
||||||
;
|
;
|
||||||
|
|
||||||
rewriteTreeEbnf returns [List<SrcOp> omos]
|
rewriteTreeEbnf returns [List<SrcOp> omos]
|
||||||
: ^('?' ^(REWRITE_BLOCK rewriteTreeAlt))
|
: ^('?' ^(REWRITE_BLOCK rewriteTreeAlt))
|
||||||
: ^('*' ^(REWRITE_BLOCK rewriteTreeAlt))
|
| ^('*' ^(REWRITE_BLOCK rewriteTreeAlt))
|
||||||
;
|
;
|
||||||
|
|
||||||
rewriteTree returns [List<SrcOp> omos]
|
rewriteTree returns [List<SrcOp> omos]
|
||||||
|
|
|
@ -208,7 +208,9 @@ public class Target {
|
||||||
// should be same for all refs to same token like $ID within single rule function
|
// should be same for all refs to same token like $ID within single rule function
|
||||||
public String getImplicitTokenLabel(String tokenName) {
|
public String getImplicitTokenLabel(String tokenName) {
|
||||||
ST st = gen.templates.getInstanceOf("ImplicitTokenLabel");
|
ST st = gen.templates.getInstanceOf("ImplicitTokenLabel");
|
||||||
st.add("tokenName", tokenName);
|
int ttype = gen.g.getTokenType(tokenName);
|
||||||
|
String text = getTokenTypeAsTargetLabel(gen.g, ttype);
|
||||||
|
st.add("tokenName", text);
|
||||||
return st.render();
|
return st.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +230,13 @@ public class Target {
|
||||||
|
|
||||||
public String getElementListName(GrammarAST elem) {
|
public String getElementListName(GrammarAST elem) {
|
||||||
ST st = gen.templates.getInstanceOf("ElementListName");
|
ST st = gen.templates.getInstanceOf("ElementListName");
|
||||||
st.add("elemName", elem.getText()); // TODO: not right for literals
|
String text = elem.getText();
|
||||||
|
if ( gen.g.getRule(text)!=null ) st.add("elemName", text);
|
||||||
|
else {
|
||||||
|
int ttype = gen.g.getTokenType(text);
|
||||||
|
text = getTokenTypeAsTargetLabel(gen.g, ttype);
|
||||||
|
st.add("elemName", text);
|
||||||
|
}
|
||||||
return st.render();
|
return st.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class AltBlock extends Choice {
|
||||||
|
|
||||||
public AltBlock(OutputModelFactory factory,
|
public AltBlock(OutputModelFactory factory,
|
||||||
GrammarAST blkOrEbnfRootAST,
|
GrammarAST blkOrEbnfRootAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkOrEbnfRootAST, alts);
|
super(factory, blkOrEbnfRootAST, alts);
|
||||||
decision = ((BlockStartState)blkOrEbnfRootAST.atnState).decision;
|
decision = ((BlockStartState)blkOrEbnfRootAST.atnState).decision;
|
||||||
|
|
|
@ -50,12 +50,12 @@ import java.util.*;
|
||||||
public abstract class Choice extends RuleElement {
|
public abstract class Choice extends RuleElement {
|
||||||
public int decision = -1;
|
public int decision = -1;
|
||||||
|
|
||||||
@ModelElement public List<SrcOp> alts;
|
@ModelElement public List<CodeBlockForAlt> alts;
|
||||||
@ModelElement public List<SrcOp> preamble;
|
@ModelElement public List<SrcOp> preamble;
|
||||||
|
|
||||||
public Choice(OutputModelFactory factory,
|
public Choice(OutputModelFactory factory,
|
||||||
GrammarAST blkOrEbnfRootAST,
|
GrammarAST blkOrEbnfRootAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkOrEbnfRootAST);
|
super(factory, blkOrEbnfRootAST);
|
||||||
this.alts = alts;
|
this.alts = alts;
|
||||||
|
|
|
@ -34,17 +34,17 @@ import org.antlr.v4.codegen.OutputModelFactory;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
public class CodeBlock extends SrcOp {
|
public class CodeBlockForAlt extends SrcOp {
|
||||||
@ModelElement public List<SrcOp> ops;
|
@ModelElement public List ops; // has to be unchecked so we can add different subclasses of SrcOp :(
|
||||||
|
|
||||||
public CodeBlock(OutputModelFactory factory) { this.factory = factory; }
|
public CodeBlockForAlt(OutputModelFactory factory) { this.factory = factory; }
|
||||||
|
|
||||||
public CodeBlock(OutputModelFactory factory, List<SrcOp> ops) {
|
public CodeBlockForAlt(OutputModelFactory factory, List<SrcOp> ops) {
|
||||||
super(factory);
|
super(factory);
|
||||||
this.ops = ops;
|
this.ops = ops;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CodeBlock(OutputModelFactory factory, final SrcOp elem) {
|
public CodeBlockForAlt(OutputModelFactory factory, final SrcOp elem) {
|
||||||
this(factory, new ArrayList<SrcOp>() {{ add(elem); }});
|
this(factory, new ArrayList<SrcOp>() {{ add(elem); }});
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -38,7 +38,7 @@ import java.util.List;
|
||||||
|
|
||||||
/** (A | B | C) */
|
/** (A | B | C) */
|
||||||
public class LL1AltBlock extends LL1Choice {
|
public class LL1AltBlock extends LL1Choice {
|
||||||
public LL1AltBlock(OutputModelFactory factory, GrammarAST blkAST, List<SrcOp> alts) {
|
public LL1AltBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
super(factory, blkAST, alts);
|
super(factory, blkAST, alts);
|
||||||
this.decision = ((DecisionState)blkAST.atnState).decision;
|
this.decision = ((DecisionState)blkAST.atnState).decision;
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public abstract class LL1Choice extends Choice {
|
||||||
@ModelElement public ThrowNoViableAlt error;
|
@ModelElement public ThrowNoViableAlt error;
|
||||||
|
|
||||||
public LL1Choice(OutputModelFactory factory, GrammarAST blkAST,
|
public LL1Choice(OutputModelFactory factory, GrammarAST blkAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkAST, alts);
|
super(factory, blkAST, alts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public abstract class LL1Loop extends Choice {
|
||||||
|
|
||||||
public LL1Loop(OutputModelFactory factory,
|
public LL1Loop(OutputModelFactory factory,
|
||||||
GrammarAST blkAST,
|
GrammarAST blkAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkAST, alts);
|
super(factory, blkAST, alts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ import java.util.List;
|
||||||
* (A | B | C)?
|
* (A | B | C)?
|
||||||
*/
|
*/
|
||||||
public class LL1OptionalBlock extends LL1AltBlock {
|
public class LL1OptionalBlock extends LL1AltBlock {
|
||||||
public LL1OptionalBlock(OutputModelFactory factory, GrammarAST blkAST, List<SrcOp> alts) {
|
public LL1OptionalBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
super(factory, blkAST, alts);
|
super(factory, blkAST, alts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class LL1OptionalBlockSingleAlt extends LL1Choice {
|
||||||
|
|
||||||
public LL1OptionalBlockSingleAlt(OutputModelFactory factory,
|
public LL1OptionalBlockSingleAlt(OutputModelFactory factory,
|
||||||
GrammarAST blkAST,
|
GrammarAST blkAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkAST, alts);
|
super(factory, blkAST, alts);
|
||||||
this.decision = ((DecisionState)blkAST.atnState).decision;
|
this.decision = ((DecisionState)blkAST.atnState).decision;
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class LL1PlusBlock extends LL1Loop {
|
||||||
@ModelElement public SrcOp loopExpr;
|
@ModelElement public SrcOp loopExpr;
|
||||||
@ModelElement public ThrowNoViableAlt error;
|
@ModelElement public ThrowNoViableAlt error;
|
||||||
|
|
||||||
public LL1PlusBlock(OutputModelFactory factory, GrammarAST plusRoot, List<SrcOp> alts) {
|
public LL1PlusBlock(OutputModelFactory factory, GrammarAST plusRoot, List<CodeBlockForAlt> alts) {
|
||||||
super(factory, plusRoot, alts);
|
super(factory, plusRoot, alts);
|
||||||
|
|
||||||
PlusBlockStartState blkStart = (PlusBlockStartState)plusRoot.atnState;
|
PlusBlockStartState blkStart = (PlusBlockStartState)plusRoot.atnState;
|
||||||
|
|
|
@ -40,7 +40,7 @@ import java.util.List;
|
||||||
public class LL1PlusBlockSingleAlt extends LL1Loop {
|
public class LL1PlusBlockSingleAlt extends LL1Loop {
|
||||||
@ModelElement public Sync iterationSync;
|
@ModelElement public Sync iterationSync;
|
||||||
|
|
||||||
public LL1PlusBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<SrcOp> alts) {
|
public LL1PlusBlockSingleAlt(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
super(factory, blkAST, alts);
|
super(factory, blkAST, alts);
|
||||||
|
|
||||||
PlusBlockStartState plus = (PlusBlockStartState)blkAST.atnState;
|
PlusBlockStartState plus = (PlusBlockStartState)blkAST.atnState;
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class LL1StarBlock extends LL1Loop {
|
||||||
public String loopLabel;
|
public String loopLabel;
|
||||||
public String[] exitLook;
|
public String[] exitLook;
|
||||||
|
|
||||||
public LL1StarBlock(OutputModelFactory factory, GrammarAST blkAST, List<SrcOp> alts) {
|
public LL1StarBlock(OutputModelFactory factory, GrammarAST blkAST, List<CodeBlockForAlt> alts) {
|
||||||
super(factory, blkAST, alts);
|
super(factory, blkAST, alts);
|
||||||
|
|
||||||
StarBlockStartState blkStart = (StarBlockStartState)blkAST.atnState;
|
StarBlockStartState blkStart = (StarBlockStartState)blkAST.atnState;
|
||||||
|
|
|
@ -38,7 +38,7 @@ import java.util.List;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
public class LL1StarBlockSingleAlt extends LL1Loop {
|
public class LL1StarBlockSingleAlt extends LL1Loop {
|
||||||
public LL1StarBlockSingleAlt(OutputModelFactory factory, GrammarAST starRoot, List<SrcOp> alts) {
|
public LL1StarBlockSingleAlt(OutputModelFactory factory, GrammarAST starRoot, List<CodeBlockForAlt> alts) {
|
||||||
super(factory, starRoot, alts);
|
super(factory, starRoot, alts);
|
||||||
|
|
||||||
StarBlockStartState star = (StarBlockStartState)starRoot.atnState;
|
StarBlockStartState star = (StarBlockStartState)starRoot.atnState;
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class Loop extends Choice {
|
||||||
public int exitAlt;
|
public int exitAlt;
|
||||||
public Loop(OutputModelFactory factory,
|
public Loop(OutputModelFactory factory,
|
||||||
GrammarAST blkOrEbnfRootAST,
|
GrammarAST blkOrEbnfRootAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkOrEbnfRootAST, alts);
|
super(factory, blkOrEbnfRootAST, alts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import java.util.List;
|
||||||
public class OptionalBlock extends AltBlock {
|
public class OptionalBlock extends AltBlock {
|
||||||
public OptionalBlock(OutputModelFactory factory,
|
public OptionalBlock(OutputModelFactory factory,
|
||||||
GrammarAST questionAST,
|
GrammarAST questionAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, questionAST, alts);
|
super(factory, questionAST, alts);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class PlusBlock extends Loop {
|
||||||
|
|
||||||
public PlusBlock(OutputModelFactory factory,
|
public PlusBlock(OutputModelFactory factory,
|
||||||
GrammarAST ebnfRootAST,
|
GrammarAST ebnfRootAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, ebnfRootAST, alts);
|
super(factory, ebnfRootAST, alts);
|
||||||
PlusLoopbackState loop = ((PlusBlockStartState)ebnfRootAST.atnState).loopBackState;
|
PlusLoopbackState loop = ((PlusBlockStartState)ebnfRootAST.atnState).loopBackState;
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
[The "BSD license"]
|
||||||
|
Copyright (c) 2011 Terence Parr
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.antlr.v4.codegen.model;
|
||||||
|
|
||||||
|
import org.antlr.v4.codegen.OutputModelFactory;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Rewrite extends SrcOp {
|
||||||
|
@ModelElement public List<? extends SrcOp> ops;
|
||||||
|
|
||||||
|
public Rewrite(OutputModelFactory factory, List<SrcOp> ops) {
|
||||||
|
super(factory);
|
||||||
|
this.ops = ops;
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,7 +40,7 @@ public class StarBlock extends Loop {
|
||||||
|
|
||||||
public StarBlock(OutputModelFactory factory,
|
public StarBlock(OutputModelFactory factory,
|
||||||
GrammarAST blkOrEbnfRootAST,
|
GrammarAST blkOrEbnfRootAST,
|
||||||
List<SrcOp> alts)
|
List<CodeBlockForAlt> alts)
|
||||||
{
|
{
|
||||||
super(factory, blkOrEbnfRootAST, alts);
|
super(factory, blkOrEbnfRootAST, alts);
|
||||||
loopLabel = factory.getGenerator().target.getLoopLabel(blkOrEbnfRootAST);
|
loopLabel = factory.getGenerator().target.getLoopLabel(blkOrEbnfRootAST);
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
[The "BSD license"]
|
||||||
|
Copyright (c) 2011 Terence Parr
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.antlr.v4.codegen.model.ast;
|
||||||
|
|
||||||
|
import org.antlr.v4.codegen.OutputModelFactory;
|
||||||
|
import org.antlr.v4.codegen.model.SrcOp;
|
||||||
|
import org.antlr.v4.tool.GrammarAST;
|
||||||
|
|
||||||
|
public class RewriteRuleRef extends SrcOp {
|
||||||
|
public RewriteRuleRef(OutputModelFactory factory, GrammarAST ast) {
|
||||||
|
super(factory, ast);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
[The "BSD license"]
|
||||||
|
Copyright (c) 2011 Terence Parr
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.antlr.v4.codegen.model.ast;
|
||||||
|
|
||||||
|
import org.antlr.v4.codegen.OutputModelFactory;
|
||||||
|
import org.antlr.v4.codegen.model.SrcOp;
|
||||||
|
import org.antlr.v4.tool.GrammarAST;
|
||||||
|
|
||||||
|
public class RewriteTokenRef extends SrcOp {
|
||||||
|
public RewriteTokenRef(OutputModelFactory factory, GrammarAST ast) {
|
||||||
|
super(factory, ast);
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,10 +33,10 @@ import org.antlr.v4.codegen.OutputModelFactory;
|
||||||
import org.antlr.v4.codegen.model.LabeledOp;
|
import org.antlr.v4.codegen.model.LabeledOp;
|
||||||
import org.antlr.v4.tool.GrammarAST;
|
import org.antlr.v4.tool.GrammarAST;
|
||||||
|
|
||||||
public class TrackElement extends ElementASTOp {
|
public class TrackRuleElement extends ElementASTOp {
|
||||||
public String name; // ID, r, ...
|
public String name;
|
||||||
public TrackElement(OutputModelFactory factory, GrammarAST ast, LabeledOp opWithResultToAdd) {
|
public TrackRuleElement(OutputModelFactory factory, GrammarAST ast, LabeledOp opWithResultToAdd) {
|
||||||
super(factory, ast, opWithResultToAdd);
|
super(factory, ast, opWithResultToAdd);
|
||||||
name = ast.getText();
|
name = factory.getGenerator().target.getElementListName(ast);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
[The "BSD license"]
|
||||||
|
Copyright (c) 2011 Terence Parr
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.antlr.v4.codegen.model.ast;
|
||||||
|
|
||||||
|
import org.antlr.v4.codegen.OutputModelFactory;
|
||||||
|
import org.antlr.v4.codegen.model.LabeledOp;
|
||||||
|
import org.antlr.v4.tool.GrammarAST;
|
||||||
|
|
||||||
|
public class TrackTokenElement extends ElementASTOp {
|
||||||
|
public String name;
|
||||||
|
public TrackTokenElement(OutputModelFactory factory, GrammarAST ast, LabeledOp opWithResultToAdd) {
|
||||||
|
super(factory, ast, opWithResultToAdd);
|
||||||
|
name = factory.getGenerator().target.getElementListName(ast);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
[The "BSD license"]
|
||||||
|
Copyright (c) 2011 Terence Parr
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.antlr.v4.codegen.model.ast;
|
||||||
|
|
||||||
|
import org.antlr.v4.codegen.OutputModelFactory;
|
||||||
|
import org.antlr.v4.codegen.model.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TreeRewrite extends Rewrite {
|
||||||
|
public TreeRewrite(OutputModelFactory factory, List<SrcOp> ops) {
|
||||||
|
super(factory, ops);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue