From 6d6327aa9dc72fd554f894ba89e4d3c4827cf484 Mon Sep 17 00:00:00 2001 From: Ewan Mellor Date: Sat, 5 Nov 2016 19:05:39 -0700 Subject: [PATCH] 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. --- .../v4/test/runtime/swift/Swift.test.stg | 6 ++++ .../v4/tool/templates/codegen/Swift/Swift.stg | 28 ++++++++++--------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/swift/Swift.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/swift/Swift.test.stg index 166581ab2..4eef14c50 100755 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/swift/Swift.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/swift/Swift.test.stg @@ -239,6 +239,12 @@ RuleInvocationStack() ::= "getRuleInvocationStack().description.replacingOccurre LL_EXACT_AMBIG_DETECTION() ::= <<_interp.setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);>> +ParserToken(parser, token) ::= <%.Tokens..rawValue%> + +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { func Property() -> Bool { diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Swift/Swift.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Swift/Swift.stg index 21c17dcec..48f873e58 100755 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Swift/Swift.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Swift/Swift.stg @@ -243,8 +243,10 @@ open class : { }() internal static let _sharedContextCache: PredictionContextCache = PredictionContextCache() - public static let =}; separator=", ", wrap, anchor> - + public enum Tokens: Int { + case EOF = -1, = }; separator=", ", wrap, anchor> + } + public static let = }; separator=", ", wrap, anchor> public static let ruleNames: [String] = [ "}; separator=", ", wrap, anchor> @@ -492,7 +494,7 @@ setState() = try _input.LT(1) -switch (try _input.LA(1)) { +switch (.Tokens(rawValue: try _input.LA(1))!) { break}; separator="\n"> @@ -504,7 +506,7 @@ default: LL1OptionalBlock(choice, alts, error) ::= << setState() -switch (try _input.LA(1)) { +switch (.Tokens(rawValue: try _input.LA(1))!) { break}; separator="\n"> @@ -649,7 +651,7 @@ isZero ::= [ default: false ] parserName(ttype) ::= <% - . + .Tokens..rawValue %> offsetShift(shiftAmount, offset) ::= <% ( - ) @@ -657,12 +659,12 @@ offsetShift(shiftAmount, offset) ::= <% // produces more efficient bytecode when bits.ttypes contains at most two items bitsetInlineComparison(s, bits) ::= <% - == .}; separator=" || "> + == .Tokens..rawValue}; separator=" || "> %> cases(ttypes) ::= << -.:fallthrough} ; separator="\n"> -.:} ; separator="\n"> +:fallthrough} ; separator="\n"> +:} ; separator="\n"> >> InvokeRule(r, argExprsChunks) ::= << @@ -679,10 +681,10 @@ MatchToken(m) ::= << setState() try { - let assignmentValue = try match(.) + let assignmentValue = try match(.Tokens..rawValue) = assignmentValue} ; separator="\n"> }() -try match(.) +try match(.Tokens..rawValue) >> MatchSet(m, expr, capture) ::= "" @@ -783,12 +785,12 @@ RuleContextDecl(r) ::= ": !" RuleContextListDecl(rdecl) ::= ":Array\<> = Array\<>()" ContextTokenGetterDecl(t) ::= - "open func () -> TerminalNode? { return getToken(., 0) }" + "open func () -> TerminalNode? { return getToken(.Tokens..rawValue, 0) }" ContextTokenListGetterDecl(t) ::= - "open func () -> Array\ { return getTokens(.) }" + "open func () -> Array\ { return getTokens(.Tokens..rawValue) }" ContextTokenListIndexedGetterDecl(t) ::= << open func (_ i:Int) -> TerminalNode?{ - return getToken(., i) + return getToken(.Tokens..rawValue, i) } >> ContextRuleGetterDecl(r) ::= <<