forked from jasder/antlr
fixup! Fix the layout of some generated Go code
This commit is contained in:
parent
c3d6c20ee4
commit
81b464a375
|
@ -139,7 +139,8 @@ type Base<file.grammarName>Visitor struct {
|
||||||
<file.visitorNames:{lname |
|
<file.visitorNames:{lname |
|
||||||
func (v *Base<file.grammarName>Visitor) Visit<lname; format="cap">(ctx *<lname; format="cap">Context) interface{\} {
|
func (v *Base<file.grammarName>Visitor) Visit<lname; format="cap">(ctx *<lname; format="cap">Context) interface{\} {
|
||||||
return v.VisitChildren(ctx)
|
return v.VisitChildren(ctx)
|
||||||
\}}; separator="\n">
|
\}}; separator="\n\n">
|
||||||
|
|
||||||
>>
|
>>
|
||||||
|
|
||||||
Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
|
Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
|
||||||
|
@ -167,12 +168,12 @@ var literalNames []string
|
||||||
<endif>
|
<endif>
|
||||||
|
|
||||||
|
|
||||||
<if(parser.literalNames)>
|
<if(parser.symbolicNames)>
|
||||||
var symbolicNames = []string{
|
var symbolicNames = []string{
|
||||||
<parser.symbolicNames; null="\"\"", separator=", ", wrap>,
|
<parser.symbolicNames; null="\"\"", separator=", ", wrap>,
|
||||||
}
|
}
|
||||||
<else>
|
<else>
|
||||||
var literalNames []string
|
var symbolicNames []string
|
||||||
<endif>
|
<endif>
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ var ruleNames = []string{
|
||||||
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap>,
|
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap>,
|
||||||
}
|
}
|
||||||
<else>
|
<else>
|
||||||
var literalNames []string
|
var ruleNames []string
|
||||||
<endif>
|
<endif>
|
||||||
|
|
||||||
|
|
||||||
|
@ -353,7 +354,7 @@ func (p *<if(parser)><parser.name><else><lexer.name><endif>) <r.name; format="ca
|
||||||
return <actions.(index)>}; separator="\n\n">
|
return <actions.(index)>}; separator="\n\n">
|
||||||
|
|
||||||
<endif>
|
<endif>
|
||||||
default:
|
default:<! TODO: Should this return true like C#/Java? !>
|
||||||
panic("No predicate with index: " + fmt.Sprint(predIndex))
|
panic("No predicate with index: " + fmt.Sprint(predIndex))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -600,7 +601,7 @@ for ok := true; ok; ok = <loopExpr> {
|
||||||
<if(alts)>
|
<if(alts)>
|
||||||
<alts; separator="\n">
|
<alts; separator="\n">
|
||||||
<endif>
|
<endif>
|
||||||
p.SetState(<choice.stateNumber>);<! loopback/exit decision !>
|
p.SetState(<choice.stateNumber>)<! loopback/exit decision !>
|
||||||
p.GetErrorHandler().Sync(p)
|
p.GetErrorHandler().Sync(p)
|
||||||
<if(iteration)>
|
<if(iteration)>
|
||||||
<iteration>
|
<iteration>
|
||||||
|
@ -728,12 +729,26 @@ bitsetInlineComparison(s, bits) ::= <%
|
||||||
|
|
||||||
InvokeRule(r, argExprsChunks) ::= <<
|
InvokeRule(r, argExprsChunks) ::= <<
|
||||||
p.SetState(<r.stateNumber>)
|
p.SetState(<r.stateNumber>)
|
||||||
<if(r.labels)><r.labels:{l | <labelref(l)> = }><endif>p.<r.name; format="cap">(<if(r.ast.options.p)><r.ast.options.p><if(argExprsChunks)>,<endif><endif><argExprsChunks>)
|
<if(r.labels)>
|
||||||
|
|
||||||
|
var _x = p.<r.name; format="cap">(<if(r.ast.options.p)><r.ast.options.p><if(argExprsChunks)>,<endif><endif><argExprsChunks>)
|
||||||
|
|
||||||
|
<r.labels:{l | <labelref(l)> = _x}; separator="\n">
|
||||||
|
<else>
|
||||||
|
p.<r.name; format="cap">(<if(r.ast.options.p)><r.ast.options.p><if(argExprsChunks)>,<endif><endif><argExprsChunks>)
|
||||||
|
<endif>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
MatchToken(m) ::= <<
|
MatchToken(m) ::= <<
|
||||||
p.SetState(<m.stateNumber>)
|
p.SetState(<m.stateNumber>)
|
||||||
<if(m.labels)><m.labels:{l | <labelref(l)> = }><endif>p.Match(<parser.name><m.name>)
|
<if(m.labels)>
|
||||||
|
|
||||||
|
var _m = p.Match(<parser.name><m.name>)
|
||||||
|
|
||||||
|
<m.labels:{l | <labelref(l)> = _m}; separator="\n">
|
||||||
|
<else>
|
||||||
|
p.Match(<parser.name><m.name>)
|
||||||
|
<endif>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
MatchSet(m, expr, capture) ::= "<CommonSetStuff(m, expr, capture, false)>"
|
MatchSet(m, expr, capture) ::= "<CommonSetStuff(m, expr, capture, false)>"
|
||||||
|
@ -743,7 +758,10 @@ MatchNotSet(m, expr, capture) ::= "<CommonSetStuff(m, expr, capture, true)>"
|
||||||
CommonSetStuff(m, expr, capture, invert) ::= <<
|
CommonSetStuff(m, expr, capture, invert) ::= <<
|
||||||
p.SetState(<m.stateNumber>)
|
p.SetState(<m.stateNumber>)
|
||||||
<if(m.labels)>
|
<if(m.labels)>
|
||||||
<m.labels:{l | <labelref(l)> = }>p.GetTokenStream().LT(1);
|
|
||||||
|
var _lt = p.GetTokenStream().LT(1)<! TODO: Should LT be called always like InvokeRule and MatchToken? !>
|
||||||
|
|
||||||
|
<m.labels:{l | <labelref(l)> = _lt}; separator="\n">
|
||||||
|
|
||||||
<endif>
|
<endif>
|
||||||
<if(capture)>
|
<if(capture)>
|
||||||
|
@ -751,7 +769,13 @@ p.SetState(<m.stateNumber>)
|
||||||
|
|
||||||
<endif>
|
<endif>
|
||||||
<if(invert)>if <m.varName> \<= 0 || <expr> <else>if !(<expr>)<endif> {
|
<if(invert)>if <m.varName> \<= 0 || <expr> <else>if !(<expr>)<endif> {
|
||||||
<if(m.labels)><m.labels:{l | <labelref(l)> = }><endif>p.GetErrorHandler().RecoverInline(p)
|
<if(m.labels)>
|
||||||
|
var _ri = p.GetErrorHandler().RecoverInline(p)
|
||||||
|
|
||||||
|
<m.labels:{l | <labelref(l)> = _ri}; separator="\n">
|
||||||
|
<else>
|
||||||
|
p.GetErrorHandler().RecoverInline(p)
|
||||||
|
<endif>
|
||||||
} else {
|
} else {
|
||||||
p.Consume()
|
p.Consume()
|
||||||
}
|
}
|
||||||
|
@ -759,7 +783,14 @@ p.SetState(<m.stateNumber>)
|
||||||
|
|
||||||
Wildcard(w) ::= <<
|
Wildcard(w) ::= <<
|
||||||
p.SetState(<w.stateNumber>)
|
p.SetState(<w.stateNumber>)
|
||||||
<if(w.labels)><w.labels:{l | <labelref(l)> = }><endif>p.MatchWildcard()
|
<if(w.labels)>
|
||||||
|
|
||||||
|
var _mwc = p.MatchWildcard()
|
||||||
|
|
||||||
|
<w.labels:{l | <labelref(l)> = _mwc}; separator="\n">
|
||||||
|
<else>
|
||||||
|
p.MatchWildcard()
|
||||||
|
<endif>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
// ACTION STUFF
|
// ACTION STUFF
|
||||||
|
@ -1245,7 +1276,7 @@ ctx(actionChunk) ::= "localctx.(*<actionChunk.ctx.name>)"
|
||||||
|
|
||||||
// used for left-recursive rules
|
// used for left-recursive rules
|
||||||
recRuleAltPredicate(ruleName, opPrec) ::= "p.Precpred(p.GetParserRuleContext(), <opPrec>)"
|
recRuleAltPredicate(ruleName, opPrec) ::= "p.Precpred(p.GetParserRuleContext(), <opPrec>)"
|
||||||
recRuleSetReturnAction(src, name) ::= "$<name>=$<src>.<name>"
|
recRuleSetReturnAction(src, name) ::= "$<name> = $<src>.<name>" // TODO: Is this valid Go syntax?
|
||||||
recRuleSetStopToken() ::= "p.GetParserRuleContext().SetStop(p.GetTokenStream().LT(-1))"
|
recRuleSetStopToken() ::= "p.GetParserRuleContext().SetStop(p.GetTokenStream().LT(-1))"
|
||||||
|
|
||||||
recRuleAltStartAction(ruleName, ctxName, label) ::= <<
|
recRuleAltStartAction(ruleName, ctxName, label) ::= <<
|
||||||
|
|
|
@ -40,6 +40,7 @@ import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
@ -55,10 +56,10 @@ public abstract class Recognizer extends OutputModelObject {
|
||||||
* {@link #literalNames} and {@link #symbolicNames}.
|
* {@link #literalNames} and {@link #symbolicNames}.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String[] tokenNames;
|
public List<String> tokenNames;
|
||||||
|
|
||||||
public String[] literalNames;
|
public List<String> literalNames;
|
||||||
public String[] symbolicNames;
|
public List<String> symbolicNames;
|
||||||
public Set<String> ruleNames;
|
public Set<String> ruleNames;
|
||||||
public Collection<Rule> rules;
|
public Collection<Rule> rules;
|
||||||
@ModelElement public ActionChunk superClass;
|
@ModelElement public ActionChunk superClass;
|
||||||
|
@ -98,7 +99,7 @@ public abstract class Recognizer extends OutputModelObject {
|
||||||
symbolicNames = translateTokenStringsToTarget(g.getTokenSymbolicNames(), gen);
|
symbolicNames = translateTokenStringsToTarget(g.getTokenSymbolicNames(), gen);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String[] translateTokenStringsToTarget(String[] tokenStrings, CodeGenerator gen) {
|
protected static List<String> translateTokenStringsToTarget(String[] tokenStrings, CodeGenerator gen) {
|
||||||
String[] result = tokenStrings.clone();
|
String[] result = tokenStrings.clone();
|
||||||
for (int i = 0; i < tokenStrings.length; i++) {
|
for (int i = 0; i < tokenStrings.length; i++) {
|
||||||
result[i] = translateTokenStringToTarget(tokenStrings[i], gen);
|
result[i] = translateTokenStringToTarget(tokenStrings[i], gen);
|
||||||
|
@ -113,7 +114,7 @@ public abstract class Recognizer extends OutputModelObject {
|
||||||
result = Arrays.copyOf(result, lastTrueEntry + 1);
|
result = Arrays.copyOf(result, lastTrueEntry + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return Arrays.asList(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String translateTokenStringToTarget(String tokenName, CodeGenerator gen) {
|
protected static String translateTokenStringToTarget(String tokenName, CodeGenerator gen) {
|
||||||
|
|
Loading…
Reference in New Issue