Skip to content

Commit 30218cd

Browse files
committed
Fixed handling of empty lists when rendering the Python3 generated files
1 parent 7a89e15 commit 30218cd

File tree

1 file changed

+10
-9
lines changed
  • tool/resources/org/antlr/v4/tool/templates/codegen/Python3

1 file changed

+10
-9
lines changed

tool/resources/org/antlr/v4/tool/templates/codegen/Python3/Python3.stg

+10-9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def exit<lname; format="cap">(self, ctx: <file.parserName>.<lname; format="cap">
8484
}; separator="\n">
8585

8686
del <file.parserName>
87+
8788
>>
8889

8990

@@ -108,6 +109,7 @@ def visit<lname; format="cap">(self, ctx: <file.parserName>.<lname; format="cap"
108109
}; separator="\n">
109110

110111
del <file.parserName>
112+
111113
>>
112114

113115

@@ -141,19 +143,19 @@ class <parser.name>(<if(superClass)><superClass><else>Parser<endif>):
141143
sharedContextCache = PredictionContextCache()
142144

143145
literalNames = [
144-
<parser.literalNames:{t | <t>}; null="\"\<INVALID>\"", separator=",\n", anchor>,
146+
<parser.literalNames:{t | <t>}; null="\"\<INVALID>\"", separator=",\n", anchor><if(parser.literalNames)>,<endif>
145147
]
146148

147149
symbolicNames = [
148-
<parser.symbolicNames:{t | <t>}; null="\"\<INVALID>\"", separator=",\n", anchor>,
150+
<parser.symbolicNames:{t | <t>}; null="\"\<INVALID>\"", separator=",\n", anchor><if(parser.symbolicNames)>,<endif>
149151
]
150152

151153
<if(parser.rules)>
152154
<parser.rules:{r | RULE_<r.name> = <r.index>}; separator="\n", wrap, anchor>
153155
<endif>
154156

155157
ruleNames = [
156-
<parser.ruleNames:{r | "<r>"}; separator=",\n", wrap, anchor>,
158+
<parser.ruleNames:{r | "<r>"}; separator=",\n", wrap, anchor><if(parser.ruleNames)>,<endif>
157159
]
158160

159161
EOF = <TokenLabelType()>.EOF
@@ -825,22 +827,21 @@ class <lexer.name>(<if(superClass)><superClass><else>Lexer<endif>):
825827
channelNames = [
826828
"DEFAULT_TOKEN_CHANNEL",
827829
"HIDDEN"<if (lexer.channelNames)>,
828-
<lexer.channelNames:{c| "<c>"}; separator=",\n", anchor>
829-
<endif>,
830+
<lexer.channelNames:{c| "<c>"}; separator=",\n", anchor><endif>,
830831
]
831832

832833
modeNames = [
833834
<lexer.modes:{m| "<m>"}; separator=",\n", anchor>,
834835
]
835836

836837
literalNames = [
837-
"\<INVALID>",
838-
<lexer.literalNames:{t | <t>}; separator=",\n", anchor>,
838+
"\<INVALID>"<if (lexer.literalNames)>,
839+
<lexer.literalNames:{t | <t>}; separator=",\n", anchor><endif>,
839840
]
840841

841842
symbolicNames = [
842-
"\<INVALID>",
843-
<lexer.symbolicNames:{t | <t>}; separator=",\n", anchor>,
843+
"\<INVALID>"<if (lexer.symbolicNames)>,
844+
<lexer.symbolicNames:{t | <t>}; separator=",\n", anchor><endif>,
844845
]
845846

846847
ruleNames = [

0 commit comments

Comments
 (0)