Move the Token declarations into an enum.
This avoids the naming conflict in the tests between the use of ATN as a token name and as a type name.
This commit is contained in:
parent
869bcfe429
commit
6d6327aa9d
|
@ -239,6 +239,12 @@ RuleInvocationStack() ::= "getRuleInvocationStack().description.replacingOccurre
|
||||||
|
|
||||||
LL_EXACT_AMBIG_DETECTION() ::= <<_interp.setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);>>
|
LL_EXACT_AMBIG_DETECTION() ::= <<_interp.setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);>>
|
||||||
|
|
||||||
|
ParserToken(parser, token) ::= <%<parser>.Tokens.<token>.rawValue%>
|
||||||
|
|
||||||
|
Production(p) ::= <%<p>%>
|
||||||
|
|
||||||
|
Result(r) ::= <%<r>%>
|
||||||
|
|
||||||
ParserPropertyMember() ::= <<
|
ParserPropertyMember() ::= <<
|
||||||
@members {
|
@members {
|
||||||
func Property() -> Bool {
|
func Property() -> Bool {
|
||||||
|
|
|
@ -243,8 +243,10 @@ open class <parser.name>: <superClass; null="Parser"> {
|
||||||
}()
|
}()
|
||||||
internal static let _sharedContextCache: PredictionContextCache = PredictionContextCache()
|
internal static let _sharedContextCache: PredictionContextCache = PredictionContextCache()
|
||||||
<if(parser.tokens)>
|
<if(parser.tokens)>
|
||||||
public static let <parser.tokens:{k | <k>=<parser.tokens.(k)>}; separator=", ", wrap, anchor>
|
public enum Tokens: Int {
|
||||||
<endif>
|
case EOF = -1, <parser.tokens:{k | <k> = <parser.tokens.(k)>}; separator=", ", wrap, anchor>
|
||||||
|
}
|
||||||
|
<endif>
|
||||||
public static let <parser.rules:{r | RULE_<r.name> = <r.index>}; separator=", ", wrap, anchor>
|
public static let <parser.rules:{r | RULE_<r.name> = <r.index>}; separator=", ", wrap, anchor>
|
||||||
public static let ruleNames: [String] = [
|
public static let ruleNames: [String] = [
|
||||||
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
|
<parser.ruleNames:{r | "<r>"}; separator=", ", wrap, anchor>
|
||||||
|
@ -492,7 +494,7 @@ setState(<choice.stateNumber>)
|
||||||
<!try _errHandler.sync(self);!>
|
<!try _errHandler.sync(self);!>
|
||||||
<if(choice.label)><labelref(choice.label)> = try _input.LT(1)<endif>
|
<if(choice.label)><labelref(choice.label)> = try _input.LT(1)<endif>
|
||||||
<preamble; separator="\n">
|
<preamble; separator="\n">
|
||||||
switch (try _input.LA(1)) {
|
switch (<parser.name>.Tokens(rawValue: try _input.LA(1))!) {
|
||||||
<choice.altLook,alts:{look,alt | <cases(ttypes=look)>
|
<choice.altLook,alts:{look,alt | <cases(ttypes=look)>
|
||||||
<alt>
|
<alt>
|
||||||
break}; separator="\n">
|
break}; separator="\n">
|
||||||
|
@ -504,7 +506,7 @@ default:
|
||||||
LL1OptionalBlock(choice, alts, error) ::= <<
|
LL1OptionalBlock(choice, alts, error) ::= <<
|
||||||
setState(<choice.stateNumber>)
|
setState(<choice.stateNumber>)
|
||||||
<!try _errHandler.sync(self);!>
|
<!try _errHandler.sync(self);!>
|
||||||
switch (try _input.LA(1)) {
|
switch (<parser.name>.Tokens(rawValue: try _input.LA(1))!) {
|
||||||
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
||||||
<alt>
|
<alt>
|
||||||
break}; separator="\n">
|
break}; separator="\n">
|
||||||
|
@ -649,7 +651,7 @@ isZero ::= [
|
||||||
default: false
|
default: false
|
||||||
]
|
]
|
||||||
parserName(ttype) ::= <%
|
parserName(ttype) ::= <%
|
||||||
<parser.name>.<ttype>
|
<parser.name>.Tokens.<ttype>.rawValue
|
||||||
%>
|
%>
|
||||||
offsetShift(shiftAmount, offset) ::= <%
|
offsetShift(shiftAmount, offset) ::= <%
|
||||||
<if(!isZero.(offset))>(<shiftAmount> - <offset>)<else><shiftAmount><endif>
|
<if(!isZero.(offset))>(<shiftAmount> - <offset>)<else><shiftAmount><endif>
|
||||||
|
@ -657,12 +659,12 @@ offsetShift(shiftAmount, offset) ::= <%
|
||||||
|
|
||||||
// produces more efficient bytecode when bits.ttypes contains at most two items
|
// produces more efficient bytecode when bits.ttypes contains at most two items
|
||||||
bitsetInlineComparison(s, bits) ::= <%
|
bitsetInlineComparison(s, bits) ::= <%
|
||||||
<bits.ttypes:{ttype | <s.varName> == <parser.name>.<ttype>}; separator=" || ">
|
<bits.ttypes:{ttype | <s.varName> == <parser.name>.Tokens.<ttype>.rawValue}; separator=" || ">
|
||||||
%>
|
%>
|
||||||
|
|
||||||
cases(ttypes) ::= <<
|
cases(ttypes) ::= <<
|
||||||
<trunc(ttypes): {t | case <parser.name>.<t>:fallthrough} ; separator="\n">
|
<trunc(ttypes): {t | case .<t>:fallthrough} ; separator="\n">
|
||||||
<last(ttypes): {t | case <parser.name>.<t>:} ; separator="\n">
|
<last(ttypes): {t | case .<t>:} ; separator="\n">
|
||||||
>>
|
>>
|
||||||
|
|
||||||
InvokeRule(r, argExprsChunks) ::= <<
|
InvokeRule(r, argExprsChunks) ::= <<
|
||||||
|
@ -679,10 +681,10 @@ MatchToken(m) ::= <<
|
||||||
setState(<m.stateNumber>)
|
setState(<m.stateNumber>)
|
||||||
<if(m.labels)>
|
<if(m.labels)>
|
||||||
try {
|
try {
|
||||||
let assignmentValue = try match(<parser.name>.<m.name>)
|
let assignmentValue = try match(<parser.name>.Tokens.<m.name>.rawValue)
|
||||||
<m.labels:{l | <labelref(l)> = assignmentValue} ; separator="\n">
|
<m.labels:{l | <labelref(l)> = assignmentValue} ; separator="\n">
|
||||||
}()
|
}()
|
||||||
<else>try match(<parser.name>.<m.name>)<endif>
|
<else>try match(<parser.name>.Tokens.<m.name>.rawValue)<endif>
|
||||||
>>
|
>>
|
||||||
|
|
||||||
MatchSet(m, expr, capture) ::= "<CommonSetStuff(m, expr, capture, false)>"
|
MatchSet(m, expr, capture) ::= "<CommonSetStuff(m, expr, capture, false)>"
|
||||||
|
@ -783,12 +785,12 @@ RuleContextDecl(r) ::= "<r.name>: <r.ctxName>!"
|
||||||
RuleContextListDecl(rdecl) ::= "<rdecl.name>:Array\<<rdecl.ctxName>> = Array\<<rdecl.ctxName>>()"
|
RuleContextListDecl(rdecl) ::= "<rdecl.name>:Array\<<rdecl.ctxName>> = Array\<<rdecl.ctxName>>()"
|
||||||
|
|
||||||
ContextTokenGetterDecl(t) ::=
|
ContextTokenGetterDecl(t) ::=
|
||||||
"open func <t.name>() -> TerminalNode? { return getToken(<parser.name>.<t.name>, 0) }"
|
"open func <t.name>() -> TerminalNode? { return getToken(<parser.name>.Tokens.<t.name>.rawValue, 0) }"
|
||||||
ContextTokenListGetterDecl(t) ::=
|
ContextTokenListGetterDecl(t) ::=
|
||||||
"open func <t.name>() -> Array\<TerminalNode> { return getTokens(<parser.name>.<t.name>) }"
|
"open func <t.name>() -> Array\<TerminalNode> { return getTokens(<parser.name>.Tokens.<t.name>.rawValue) }"
|
||||||
ContextTokenListIndexedGetterDecl(t) ::= <<
|
ContextTokenListIndexedGetterDecl(t) ::= <<
|
||||||
open func <t.name>(_ i:Int) -> TerminalNode?{
|
open func <t.name>(_ i:Int) -> TerminalNode?{
|
||||||
return getToken(<parser.name>.<t.name>, i)
|
return getToken(<parser.name>.Tokens.<t.name>.rawValue, i)
|
||||||
}
|
}
|
||||||
>>
|
>>
|
||||||
ContextRuleGetterDecl(r) ::= <<
|
ContextRuleGetterDecl(r) ::= <<
|
||||||
|
|
Loading…
Reference in New Issue