forked from jasder/antlr
reorg to get tree parser gen'd
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9070]
This commit is contained in:
parent
a126e2043a
commit
0c1716d062
|
@ -70,8 +70,16 @@ public void exitRule(<listener.parserName>.<lname>Context ctx) { \}}; separator=
|
|||
>>
|
||||
|
||||
Parser(parser, scopes, funcs, atn, sempredFuncs) ::= <<
|
||||
<Parser_(ctor="parser_ctor", ...)>
|
||||
>>
|
||||
|
||||
TreeParserModel(parser, scopes, funcs, atn, sempredFuncs) ::= <<
|
||||
<Parser_(ctor="treeparser_ctor", ...)>
|
||||
>>
|
||||
|
||||
Parser_(parser, scopes, funcs, atn, sempredFuncs, ctor) ::= <<
|
||||
@SuppressWarnings({"all", "warnings", "unchecked", "unused"})
|
||||
public class <parser.name> extends Parser {
|
||||
public class <parser.name> extends <parser.superclass> {
|
||||
public static final int
|
||||
<parser.tokens:{k | <k>=<parser.tokens.(k)>}; separator=", ", wrap, anchor>;
|
||||
public static final String[] tokenNames = {
|
||||
|
@ -85,7 +93,7 @@ public class <parser.name> extends Parser {
|
|||
};
|
||||
<scopes>
|
||||
<namedActions.members>
|
||||
<parser:ctor()>
|
||||
<parser:(ctor)()>
|
||||
<funcs; separator="\n">
|
||||
|
||||
@Override
|
||||
|
@ -110,10 +118,6 @@ public class <parser.name> extends Parser {
|
|||
}
|
||||
>>
|
||||
|
||||
TreeParserModel(parser, scopes, funcs, atn, sempredFuncs) ::= <<
|
||||
<Parser(...)>
|
||||
>>
|
||||
|
||||
dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
|
||||
<if(actionFuncs)>
|
||||
public void action(RuleContext _localctx, int ruleIndex, int actionIndex) {
|
||||
|
@ -136,13 +140,20 @@ case <f.ruleIndex> : return <f.name>_sempred((<f.ctxType>)_localctx, predIndex);
|
|||
<endif>
|
||||
>>
|
||||
|
||||
ctor(p) ::= <<
|
||||
parser_ctor(p) ::= <<
|
||||
public <p.name>(TokenStream input) {
|
||||
super(input);
|
||||
_interp = new ParserATNSimulator(this,_ATN);
|
||||
}
|
||||
>>
|
||||
|
||||
treeparser_ctor(p) ::= <<
|
||||
public <p.name>(TreeNodeStream input) {
|
||||
super(input);
|
||||
_interp = new ParserATNSimulator(this,_ATN);
|
||||
}
|
||||
>>
|
||||
|
||||
RuleActionFunction(r, actions) ::= <<
|
||||
public void <r.name>_action(<r.ctxType> _localctx, int actionIndex) {
|
||||
switch ( actionIndex ) {
|
||||
|
|
|
@ -30,8 +30,7 @@
|
|||
package org.antlr.v4.codegen.model;
|
||||
|
||||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
import org.antlr.v4.tool.Rule;
|
||||
import org.antlr.v4.tool.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -39,6 +38,7 @@ import java.util.*;
|
|||
public class Parser extends OutputModelObject {
|
||||
public String name;
|
||||
public String grammarName;
|
||||
public String superclass;
|
||||
public Map<String,Integer> tokens;
|
||||
public String[] tokenNames;
|
||||
public Set<String> ruleNames;
|
||||
|
@ -65,5 +65,6 @@ public class Parser extends OutputModelObject {
|
|||
ruleNames = g.rules.keySet();
|
||||
rules = g.rules.values();
|
||||
atn = new SerializedATN(factory, g.atn);
|
||||
superclass = g.getOption("superClass", "Parser");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,12 @@
|
|||
package org.antlr.v4.codegen.model;
|
||||
|
||||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
import org.antlr.v4.tool.Grammar;
|
||||
|
||||
public class TreeParserModel extends Parser {
|
||||
public TreeParserModel(OutputModelFactory factory, ParserFile file) {
|
||||
super(factory, file);
|
||||
Grammar g = factory.getGrammar();
|
||||
superclass = g.getOption("superClass", "TreeParser");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue