Skip to content

Commit e8bf978

Browse files
cyqwparrt
authored andcommitted
rule name 'state' conflict with Python runtime.
Signed-off-by: cyqw <[email protected]>
1 parent 88a0c7a commit e8bf978

File tree

15 files changed

+144
-17
lines changed

15 files changed

+144
-17
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[type]
2+
Parser
3+
4+
[grammar]
5+
grammar T;
6+
7+
program : state*{<writeln("$text")>} EOF ;
8+
state: 'break;' | 'continue;' | 'return;' ;
9+
10+
[start]
11+
program
12+
13+
[input]
14+
break;continue;return;
15+
16+
[output]
17+
"""break;continue;return;
18+
"""
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[type]
2+
Parser
3+
4+
[grammar]
5+
grammar T;
6+
7+
program : sempred*{<writeln("$text")>} EOF ;
8+
sempred: 'break;' | 'continue;' | 'return;' ;
9+
10+
[start]
11+
program
12+
13+
[input]
14+
break;continue;return;
15+
16+
[output]
17+
"""break;continue;return;
18+
"""
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[type]
2+
Parser
3+
4+
[grammar]
5+
grammar T;
6+
7+
program : action*{<writeln("$text")>} EOF ;
8+
action: 'break;' | 'continue;' | 'return;' ;
9+
10+
[start]
11+
program
12+
13+
[input]
14+
break;continue;return;
15+
16+
[output]
17+
"""break;continue;return;
18+
"""
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[type]
2+
Parser
3+
4+
[grammar]
5+
grammar T;
6+
7+
program : ruleIndexMap*{<writeln("$text")>} EOF ;
8+
ruleIndexMap: 'break;' | 'continue;' | 'return;' ;
9+
10+
[start]
11+
program
12+
13+
[input]
14+
break;continue;return;
15+
16+
[output]
17+
"""break;continue;return;
18+
"""
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[type]
2+
Parser
3+
4+
[grammar]
5+
grammar T;
6+
7+
program : addErrorListener*{<writeln("$text")>} EOF ;
8+
addErrorListener: 'break;' | 'continue;' | 'return;' ;
9+
10+
[start]
11+
program
12+
13+
[input]
14+
break;continue;return;
15+
16+
[output]
17+
"""break;continue;return;
18+
"""
19+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[type]
2+
Parser
3+
4+
[grammar]
5+
grammar T;
6+
7+
program : reset*{<writeln("$text")>} EOF ;
8+
reset: 'break;' | 'continue;' | 'return;' ;
9+
10+
[start]
11+
program
12+
13+
[input]
14+
break;continue;return;
15+
16+
[output]
17+
"""break;continue;return;
18+
"""
19+

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ RuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,namedActions,fina
449449
/**
450450
* @throws RecognitionException
451451
*/
452-
<if(currentRule.modifiers)><currentRule.modifiers:{f | <f> }><endif>public function <currentRule.name>(<args; separator=",">): Context\\<currentRule.ctxType>
452+
<if(currentRule.modifiers)><currentRule.modifiers:{f | <f> }><endif>public function <currentRule.escapedName>(<args; separator=",">): Context\\<currentRule.ctxType>
453453
{
454454
$localContext = new Context\\<currentRule.ctxType>($this->ctx, $this->getState()<currentRule.args:{a | , $<a.name>}>);
455455

@@ -701,7 +701,7 @@ cases(tokens) ::= <<
701701

702702
InvokeRule(r, argExprsChunks) ::= <<
703703
$this->setState(<r.stateNumber>);
704-
<if(r.labels)><r.labels:{l | <labelref(l)> = }><endif>$this-><if(r.ast.options.p)>recursive<r.name; format="cap"><else><r.name><endif>(<if(r.ast.options.p)><r.ast.options.p><if(argExprsChunks)>,<endif><endif><argExprsChunks>);
704+
<if(r.labels)><r.labels:{l | <labelref(l)> = }><endif>$this-><if(r.ast.options.p)>recursive<r.name; format="cap"><else><r.escapedName><endif>(<if(r.ast.options.p)><r.ast.options.p><if(argExprsChunks)>,<endif><endif><argExprsChunks>);
705705
>>
706706

707707
MatchToken(m) ::= <<

tool/src/org/antlr/v4/codegen/target/CppTarget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class CppTarget extends Target {
4848
"using", "virtual", "void", "volatile", "wchar_t", "while",
4949
"xor", "xor_eq",
5050

51-
"rule", "parserRule"
51+
"rule", "parserRule", "reset"
5252
));
5353

5454
public CppTarget(CodeGenerator gen) {

tool/src/org/antlr/v4/codegen/target/DartTarget.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,15 @@ public class DartTarget extends Target {
3636
"deferred", "hide", "return", "with",
3737
"do", "if", "set", "yield",
3838

39-
"rule", "parserRule"
39+
"rule", "parserRule",
40+
"interpreter", "state", "ruleNames", "vocabulary", "ruleIndexMap", "getTokenType", "grammarFileName", "getATN",
41+
"parseInfo", "getErrorHeader", "addErrorListener", "removeErrorListener", "removeErrorListeners","errorListeners",
42+
"errorListenerDispatch", "sempred", "precpred", "action", "inputStream", "tokenFactory",
43+
44+
"errorHandler", "context", "buildParseTree", "matchedEOF", "reset", "match", "matchWildcard", "trimParseTree",
45+
"addParseListener", "removeParseListener", "removeParseListeners", "triggerEnterRuleEvent", "triggerExitRuleEvent",
46+
"numberOfSyntaxErrors", "currentToken", "notifyErrorListeners", "consume", "createTerminalNode", "createErrorNode",
47+
"addContextToParseTree", "enterRule", "exitRule", "enterOuterAlt", "precedence", "enterRecursionRule"
4048
));
4149

4250
public DartTarget(CodeGenerator gen) {

tool/src/org/antlr/v4/codegen/target/GoTarget.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import org.antlr.v4.parse.ANTLRParser;
1212
import org.antlr.v4.tool.Grammar;
1313
import org.stringtemplate.v4.ST;
14-
import org.stringtemplate.v4.STGroup;
15-
import org.stringtemplate.v4.StringRenderer;
1614

1715
import java.io.File;
1816
import java.io.IOException;
1917
import java.io.InputStream;
20-
import java.util.*;
18+
import java.util.Arrays;
19+
import java.util.HashSet;
20+
import java.util.Set;
2121

2222
public class GoTarget extends Target {
2323
protected static final HashSet<String> reservedWords = new HashSet<>(Arrays.asList(
@@ -50,7 +50,8 @@ public class GoTarget extends Target {
5050
// then clashes with the GetStart() or GetStop() method that is generated by the code gen for the rule. So, we need to
5151
// convert it. This is not ideal as it will still probably confuse authors of parse listeners etc. but the code will
5252
// compile. This is a proof of Hyrum's law.
53-
"start", "stop", "exception"
53+
"start", "stop", "exception",
54+
"sempred", "precpred", "addErrorListener"
5455
));
5556

5657
private static final boolean DO_GOFMT = !Boolean.parseBoolean(System.getenv("ANTLR_GO_DISABLE_GOFMT"))

0 commit comments

Comments
 (0)