diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg index 95e23c671..ca6182b47 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/csharp/CSharp.test.stg @@ -327,6 +327,19 @@ ParseTreeWalker walker = new ParseTreeWalker(); walker.Walk(new LeafListener(), ); >> +TreeNodeWithAltNumField(X) ::= << +@parser::members { +public class MyRuleNode : ParserRuleContext { + public int altNum; + public MyRuleNode(ParserRuleContext parent, int invokingStateNumber): base(parent, invokingStateNumber) + { + } + public override int getAltNumber() { return altNum; } + public override void setAltNumber(int altNum) { this.altNum = altNum; } +} +} +>> + TokenGetterListener(X) ::= << public class LeafListener : TBaseListener { public override void ExitA(TParser.AContext ctx) { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg index 49a1ab461..45c6e1a63 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/java/Java.test.stg @@ -335,6 +335,19 @@ ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(new LeafListener(), ); >> +TreeNodeWithAltNumField(X) ::= << +@parser::members { +public static class MyRuleNode extends ParserRuleContext { + public int altNum; + public MyRuleNode(ParserRuleContext parent, int invokingStateNumber) { + super(parent, invokingStateNumber); + } + @Override public int getAltNumber() { return altNum; } + @Override public void setAltNumber(int altNum) { this.altNum = altNum; } +} +} +>> + TokenGetterListener(X) ::= << public static class LeafListener extends TBaseListener { public void exitA(TParser.AContext ctx) { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/chrome/Chrome.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/chrome/Chrome.test.stg index 56f70b081..649d3a127 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/chrome/Chrome.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/chrome/Chrome.test.stg @@ -322,6 +322,20 @@ var walker = new antlr4.tree.ParseTreeWalker(); walker.walk(new this.LeafListener(), ); >> +TreeNodeWithAltNumField(X) ::= << + +@parser::header { +MyRuleNode = function(parent, invokingState) { + antlr4.ParserRuleContext.call(this, parent, invokingState); + this.altNum = 0; + return this; +}; + +MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype); +MyRuleNode.prototype.constructor = MyRuleNode; +} +>> + TokenGetterListener(X) ::= << this.LeafListener = function() { this.exitA = function(ctx) { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg index e85e5c8eb..7dba81947 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/explorer/Explorer.test.stg @@ -322,6 +322,20 @@ var walker = new antlr4.tree.ParseTreeWalker(); walker.walk(new this.LeafListener(), ); >> +TreeNodeWithAltNumField(X) ::= << + +@parser::header { +MyRuleNode = function(parent, invokingState) { + antlr4.ParserRuleContext.call(this, parent, invokingState); + this.altNum = 0; + return this; +}; + +MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype); +MyRuleNode.prototype.constructor = MyRuleNode; +} +>> + TokenGetterListener(X) ::= << this.LeafListener = function() { this.exitA = function(ctx) { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg index 892c2c924..f1a91fbea 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/firefox/Firefox.test.stg @@ -324,6 +324,20 @@ var walker = new antlr4.tree.ParseTreeWalker(); walker.walk(new this.LeafListener(), ); >> +TreeNodeWithAltNumField(X) ::= << + +@parser::header { +MyRuleNode = function(parent, invokingState) { + antlr4.ParserRuleContext.call(this, parent, invokingState); + this.altNum = 0; + return this; +}; + +MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype); +MyRuleNode.prototype.constructor = MyRuleNode; +} +>> + TokenGetterListener(X) ::= << this.LeafListener = function() { this.exitA = function(ctx) { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg index 2d37b028a..5bca3c134 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/node/Node.test.stg @@ -322,6 +322,24 @@ var walker = new antlr4.tree.ParseTreeWalker(); walker.walk(new this.LeafListener(), ); >> +TreeNodeWithAltNumField(X) ::= << + +@parser::header { +MyRuleNode = function(parent, invokingState) { + antlr4.ParserRuleContext.call(this, parent, invokingState); + + this.altNum = 0; + return this; +}; + +MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype); +MyRuleNode.prototype.constructor = MyRuleNode; +MyRuleNode.prototype.getAltNumber = function() { return this.altNum; } +MyRuleNode.prototype.setAltNumber = function(altNumber) { this.altNum = altNumber; } + +} +>> + TokenGetterListener(X) ::= << this.LeafListener = function() { this.exitA = function(ctx) { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg index a78e877aa..c05024066 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/javascript/safari/Safari.test.stg @@ -322,6 +322,21 @@ var walker = new antlr4.tree.ParseTreeWalker(); walker.walk(new this.LeafListener(), ); >> +TreeNodeWithAltNumField(X) ::= << + +@parser::header { +MyRuleNode = function(parent, invokingState) { + antlr4.ParserRuleContext.call(this, parent, invokingState); + this.altNum = 0; + return this; +}; + +MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype); +MyRuleNode.prototype.constructor = MyRuleNode; +} +>> + + TokenGetterListener(X) ::= << this.LeafListener = function() { this.exitA = function(ctx) { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg index 401d28190..c86f4a646 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python2/Python2.test.stg @@ -312,6 +312,19 @@ walker = ParseTreeWalker() walker.walk(TParser.LeafListener(), ) >> +TreeNodeWithAltNumField(X) ::= << +@parser::members { +class MyRuleNode(ParserRuleContext): + def __init__(self, parent = None, invokingStateNumber = None ): + super(Parser.MyRuleNode, self).__init__(parent, invokingStateNumber) + self.altNum = 0; + def getAltNumber(self): + return self.altNum + def setAltNumber(self, altNum): + self.altNum = altNum +} +>> + TokenGetterListener(X) ::= << if __name__ is not None and "." in __name__: from .Listener import Listener diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg index 21315805d..d57f6146e 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/python3/Python3.test.stg @@ -314,6 +314,19 @@ walker = ParseTreeWalker() walker.walk(TParser.LeafListener(), ) >> +TreeNodeWithAltNumField(X) ::= << +@parser::members { +class MyRuleNode(ParserRuleContext): + def __init__(self, parent:ParserRuleContext = None, invokingStateNumber:int = None ): + super(Parser.MyRuleNode, self).__init__(parent, invokingStateNumber) + self.altNum = 0; + def getAltNumber(self): + return self.altNum + def setAltNumber(self, altNum): + self.altNum = altNum +} +>> + TokenGetterListener(X) ::= << class LeafListener(MockListener): def exitA(self, ctx): diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParseTrees/AltNum.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParseTrees/AltNum.stg new file mode 100644 index 000000000..124112c1f --- /dev/null +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParseTrees/AltNum.stg @@ -0,0 +1,40 @@ +TestType() ::= "Parser" + +Grammar ::= [ + "T": {} +] + +Input() ::= "xyz" + +Rule() ::= "s" + +Output() ::= << +(a:3 x (b:2 y) z)<\n> +>> + +Errors() ::= "" + +grammar(grammarName) ::= << +grammar ; + +options { contextSuperClass=MyRuleNode; } + + + + +s +@init { + +} +@after { + +} + : r=a ; + +a : 'f' + | 'g' + | 'x' b 'z' + ; +b : 'e' {} | 'y' + ; +>> diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParseTrees/Index.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParseTrees/Index.stg index 5f71a146c..a8bc31d2d 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParseTrees/Index.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/ParseTrees/Index.stg @@ -6,5 +6,6 @@ TestTemplates ::= [ "RuleRef": [], "ExtraToken": [], "NoViableAlt": [], - "Sync": [] + "Sync": [], + "AltNum": [] ] diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestParseTrees.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestParseTrees.java index 4f6e1b322..3ff7bb4e1 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestParseTrees.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/csharp/TestParseTrees.java @@ -2,7 +2,6 @@ package org.antlr.v4.test.runtime.csharp; import org.junit.Test; -import org.junit.Ignore; @SuppressWarnings("unused") public class TestParseTrees extends BaseTest { @@ -52,6 +51,49 @@ public class TestParseTrees extends BaseTest { assertEquals("(a y)\n", found); assertNull(this.stderrDuringParse); + } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ + @Test + public void testAltNum() throws Exception { + mkdir(tmpdir); + StringBuilder grammarBuilder = new StringBuilder(547); + grammarBuilder.append("grammar T;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("@parser::members {\n"); + grammarBuilder.append("public class MyRuleNode : ParserRuleContext {\n"); + grammarBuilder.append(" public int altNum;\n"); + grammarBuilder.append(" public MyRuleNode(ParserRuleContext parent, int invokingStateNumber): base(parent, invokingStateNumber)\n"); + grammarBuilder.append(" {\n"); + grammarBuilder.append(" }\n"); + grammarBuilder.append(" public override int getAltNumber() { return altNum; }\n"); + grammarBuilder.append(" public override void setAltNumber(int altNum) { this.altNum = altNum; }\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("s\n"); + grammarBuilder.append("@init {\n"); + grammarBuilder.append("this.BuildParseTree = true;\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("@after {\n"); + grammarBuilder.append("Console.WriteLine($r.ctx.ToStringTree(this));\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append(" : r=a ;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("a : 'f'\n"); + grammarBuilder.append(" | 'g'\n"); + grammarBuilder.append(" | 'x' b 'z'\n"); + grammarBuilder.append(" ;\n"); + grammarBuilder.append("b : 'e' {} | 'y'\n"); + grammarBuilder.append(" ;"); + String grammar = grammarBuilder.toString(); + String input ="xyz"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false); + assertEquals("(a:3 x (b:2 y) z)\n", found); + assertNull(this.stderrDuringParse); + } /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ @Test diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestParseTrees.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestParseTrees.java index 7067a2b53..7a0a944df 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestParseTrees.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/java/TestParseTrees.java @@ -1,10 +1,10 @@ /* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */ package org.antlr.v4.test.runtime.java; -import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; public class TestParseTrees extends BaseTest { @@ -62,6 +62,53 @@ public class TestParseTrees extends BaseTest { } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ + @Test + public void testAltNum() throws Exception { + mkdir(tmpdir); + + StringBuilder grammarBuilder = new StringBuilder(562); + grammarBuilder.append("grammar T;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("@parser::members {\n"); + grammarBuilder.append("public static class MyRuleNode extends ParserRuleContext {\n"); + grammarBuilder.append(" public int altNum;\n"); + grammarBuilder.append(" public MyRuleNode(ParserRuleContext parent, int invokingStateNumber) {\n"); + grammarBuilder.append(" super(parent, invokingStateNumber);\n"); + grammarBuilder.append(" }\n"); + grammarBuilder.append(" @Override public int getAltNumber() { return altNum; }\n"); + grammarBuilder.append(" @Override public void setAltNumber(int altNum) { this.altNum = altNum; }\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("s\n"); + grammarBuilder.append("@init {\n"); + grammarBuilder.append("setBuildParseTree(true);\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("@after {\n"); + grammarBuilder.append("System.out.println($r.ctx.toStringTree(this));\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append(" : r=a ;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("a : 'f'\n"); + grammarBuilder.append(" | 'g'\n"); + grammarBuilder.append(" | 'x' b 'z'\n"); + grammarBuilder.append(" ;\n"); + grammarBuilder.append("b : 'e' {} | 'y'\n"); + grammarBuilder.append(" ;"); + String grammar = grammarBuilder.toString(); + + + String input ="xyz"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", "s", input, false); + assertEquals("(a:3 x (b:2 y) z)\n", found); + assertNull(this.stderrDuringParse); + + } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ @Test public void testExtraToken() throws Exception { diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestParseTrees.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestParseTrees.java index c1f9afa92..2dd5b992d 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestParseTrees.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/node/TestParseTrees.java @@ -1,10 +1,10 @@ /* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */ package org.antlr.v4.test.runtime.javascript.node; -import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; @SuppressWarnings("unused") public class TestParseTrees extends BaseTest { @@ -58,6 +58,55 @@ public class TestParseTrees extends BaseTest { assertEquals("(a y)\n", found); assertNull(this.stderrDuringParse); + } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ + @Test + public void testAltNum() throws Exception { + mkdir(tmpdir); + StringBuilder grammarBuilder = new StringBuilder(663); + grammarBuilder.append("grammar T;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("@parser::header {\n"); + grammarBuilder.append("MyRuleNode = function(parent, invokingState) {\n"); + grammarBuilder.append(" antlr4.ParserRuleContext.call(this, parent, invokingState);\n"); + grammarBuilder.append("\n"); + grammarBuilder.append(" this.altNum = 0;\n"); + grammarBuilder.append(" return this;\n"); + grammarBuilder.append("};\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);\n"); + grammarBuilder.append("MyRuleNode.prototype.constructor = MyRuleNode;\n"); + grammarBuilder.append("MyRuleNode.prototype.getAltNumber = function() { return this.altNum; }\n"); + grammarBuilder.append("MyRuleNode.prototype.setAltNumber = function(altNumber) { this.altNum = altNumber; }\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("s\n"); + grammarBuilder.append("@init {\n"); + grammarBuilder.append("this.buildParseTrees = true;\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("@after {\n"); + grammarBuilder.append("console.log($r.ctx.toStringTree(null, this));\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append(" : r=a ;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("a : 'f'\n"); + grammarBuilder.append(" | 'g'\n"); + grammarBuilder.append(" | 'x' b 'z'\n"); + grammarBuilder.append(" ;\n"); + grammarBuilder.append("b : 'e' {} | 'y'\n"); + grammarBuilder.append(" ;"); + String grammar = grammarBuilder.toString(); + String input ="xyz"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", + "TListener", "TVisitor", + "s", input, false); + assertEquals("(a:3 x (b:2 y) z)\n", found); + assertNull(this.stderrDuringParse); + } /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ @Test diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestParseTrees.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestParseTrees.java index b94a2959e..da8e26f07 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestParseTrees.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python2/TestParseTrees.java @@ -1,9 +1,10 @@ /* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */ package org.antlr.v4.test.runtime.python2; -import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; @SuppressWarnings("unused") public class TestParseTrees extends BasePython2Test { @@ -64,6 +65,54 @@ public class TestParseTrees extends BasePython2Test { } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ + @Test + public void testAltNum() throws Exception { + mkdir(tmpdir); + + StringBuilder grammarBuilder = new StringBuilder(562); + grammarBuilder.append("grammar T;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("@parser::members {\n"); + grammarBuilder.append("class MyRuleNode(ParserRuleContext):\n"); + grammarBuilder.append(" def __init__(self, parent = None, invokingStateNumber = None ):\n"); + grammarBuilder.append(" super(TParser.MyRuleNode, self).__init__(parent, invokingStateNumber)\n"); + grammarBuilder.append(" self.altNum = 0;\n"); + grammarBuilder.append(" def getAltNumber(self):\n"); + grammarBuilder.append(" return self.altNum\n"); + grammarBuilder.append(" def setAltNumber(self, altNum):\n"); + grammarBuilder.append(" self.altNum = altNum\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("s\n"); + grammarBuilder.append("@init {\n"); + grammarBuilder.append("self._buildParseTrees = True\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("@after {\n"); + grammarBuilder.append("print($r.ctx.toStringTree(recog=self))\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append(" : r=a ;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("a : 'f'\n"); + grammarBuilder.append(" | 'g'\n"); + grammarBuilder.append(" | 'x' b 'z'\n"); + grammarBuilder.append(" ;\n"); + grammarBuilder.append("b : 'e' {} | 'y'\n"); + grammarBuilder.append(" ;"); + String grammar = grammarBuilder.toString(); + + + String input ="xyz"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false); + + assertEquals("(a:3 x (b:2 y) z)\n", found); + assertNull(this.stderrDuringParse); + + } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ @Test public void testExtraToken() throws Exception { diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java index 8afe1c6da..8f55dabd3 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/BasePython3Test.java @@ -41,7 +41,7 @@ public abstract class BasePython3Test extends BasePythonTest { @Override protected String getPythonExecutable() { - return "python3.5"; + return "python3"; } @Override diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestParseTrees.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestParseTrees.java index cb4d137e6..5d1b0da2d 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestParseTrees.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/python3/TestParseTrees.java @@ -1,9 +1,10 @@ /* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */ package org.antlr.v4.test.runtime.python3; -import org.junit.Ignore; import org.junit.Test; -import static org.junit.Assert.*; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; @SuppressWarnings("unused") public class TestParseTrees extends BasePython3Test { @@ -64,6 +65,54 @@ public class TestParseTrees extends BasePython3Test { } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ + @Test + public void testAltNum() throws Exception { + mkdir(tmpdir); + + StringBuilder grammarBuilder = new StringBuilder(584); + grammarBuilder.append("grammar T;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("options { contextSuperClass=MyRuleNode; }\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("@parser::members {\n"); + grammarBuilder.append("class MyRuleNode(ParserRuleContext):\n"); + grammarBuilder.append(" def __init__(self, parent:ParserRuleContext = None, invokingStateNumber:int = None ):\n"); + grammarBuilder.append(" super(TParser.MyRuleNode, self).__init__(parent, invokingStateNumber)\n"); + grammarBuilder.append(" self.altNum = 0;\n"); + grammarBuilder.append(" def getAltNumber(self):\n"); + grammarBuilder.append(" return self.altNum\n"); + grammarBuilder.append(" def setAltNumber(self, altNum):\n"); + grammarBuilder.append(" self.altNum = altNum\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("s\n"); + grammarBuilder.append("@init {\n"); + grammarBuilder.append("self._buildParseTrees = True\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append("@after {\n"); + grammarBuilder.append("print($r.ctx.toStringTree(recog=self))\n"); + grammarBuilder.append("}\n"); + grammarBuilder.append(" : r=a ;\n"); + grammarBuilder.append("\n"); + grammarBuilder.append("a : 'f'\n"); + grammarBuilder.append(" | 'g'\n"); + grammarBuilder.append(" | 'x' b 'z'\n"); + grammarBuilder.append(" ;\n"); + grammarBuilder.append("b : 'e' {} | 'y'\n"); + grammarBuilder.append(" ;"); + String grammar = grammarBuilder.toString(); + + + String input ="xyz"; + String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "s", input, false); + + assertEquals("(a:3 x (b:2 y) z)\n", found); + assertNull(this.stderrDuringParse); + + } + /* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */ @Test public void testExtraToken() throws Exception { diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Parser.cs b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Parser.cs index 8d13cf52f..9df0b4270 100644 --- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Parser.cs +++ b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Parser.cs @@ -352,7 +352,7 @@ namespace Antlr4.Runtime /// for a newly constructed parser. /// /// - /// + /// /// /// if a complete parse tree will be constructed while /// parsing, otherwise @@ -378,14 +378,14 @@ namespace Antlr4.Runtime /// by default for a newly constructed parser. /// /// - /// + /// /// /// to trim the capacity of the /// /// list to its size after a rule is parsed. /// /// - /// + /// /// /// if the /// @@ -649,9 +649,9 @@ namespace Antlr4.Runtime } } - public override IIntStream InputStream + public override IIntStream InputStream { - get + get { return _input; } @@ -659,11 +659,11 @@ namespace Antlr4.Runtime public ITokenStream TokenStream { - get + get { return _input; } - set + set { this._input = null; Reset (); @@ -842,6 +842,7 @@ namespace Antlr4.Runtime public virtual void EnterOuterAlt(ParserRuleContext localctx, int altNum) { + localctx.setAltNumber(altNum); // if we have new localctx, make sure we replace existing ctx // that is previous child of parse tree if (_buildParseTrees && _ctx != localctx) @@ -1004,7 +1005,7 @@ namespace Antlr4.Runtime /// /// the symbol type to check /// - /// + /// /// /// if /// diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/RuleContext.cs b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/RuleContext.cs index 6cb5fe96d..54a968ffa 100644 --- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/RuleContext.cs +++ b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/RuleContext.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Text; using Antlr4.Runtime; +using Antlr4.Runtime.Atn; using Antlr4.Runtime.Misc; using Antlr4.Runtime.Sharpen; using Antlr4.Runtime.Tree; @@ -139,7 +140,7 @@ namespace Antlr4.Runtime { return _parent; } - set + set { _parent = value; } @@ -216,6 +217,23 @@ namespace Antlr4.Runtime } } + /* For rule associated with this parse tree internal node, return + * the outer alternative number used to match the input. Default + * implementation does not compute nor store this alt num. Create + * a subclass of ParserRuleContext with backing field and set + * option contextSuperClass. + * to set it. + */ + public virtual int getAltNumber() { return Atn.ATN.InvalidAltNumber; } + + /* Set the outer alternative number for this context node. Default + * implementation does nothing to avoid backing field overhead for + * trees that don't need it. Create + * a subclass of ParserRuleContext with backing field and set + * option contextSuperClass. + */ + public virtual void setAltNumber(int altNumber) { } + public virtual IParseTree GetChild(int i) { return null; diff --git a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Tree/Trees.cs b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Tree/Trees.cs index bb70f7329..c77866920 100644 --- a/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Tree/Trees.cs +++ b/runtime/CSharp/runtime/CSharp/Antlr4.Runtime/Tree/Trees.cs @@ -30,6 +30,7 @@ using System.Collections.Generic; using System.Text; using Antlr4.Runtime; +using Antlr4.Runtime.Atn; using Antlr4.Runtime.Misc; using Antlr4.Runtime.Sharpen; using Antlr4.Runtime.Tree; @@ -111,10 +112,14 @@ namespace Antlr4.Runtime.Tree { if (ruleNames != null) { - if (t is IRuleNode) + if (t is RuleContext) { - int ruleIndex = ((IRuleNode)t).RuleContext.RuleIndex; + int ruleIndex = ((RuleContext)t).RuleIndex; string ruleName = ruleNames[ruleIndex]; + int altNumber = ((RuleContext)t).getAltNumber(); + if ( altNumber!=Atn.ATN.InvalidAltNumber ) { + return ruleName+":"+altNumber; + } return ruleName; } else diff --git a/runtime/Java/src/org/antlr/v4/runtime/RuleContextWithAltNum.java b/runtime/Java/src/org/antlr/v4/runtime/RuleContextWithAltNum.java new file mode 100644 index 000000000..0cd5b11a6 --- /dev/null +++ b/runtime/Java/src/org/antlr/v4/runtime/RuleContextWithAltNum.java @@ -0,0 +1,20 @@ +package org.antlr.v4.runtime; + +/** A handy class for use with + * + * options {contextSuperClass=org.antlr.v4.runtime.RuleContextWithAltNum;} + * + * that provides a backing field / impl for the outer alternative number + * matched for an internal parse tree node. + * + * I'm only putting into Java runtime as I'm certain I'm the only one that + * will really every use this. + */ +public class RuleContextWithAltNum extends ParserRuleContext { + public int altNum; + public RuleContextWithAltNum(ParserRuleContext parent, int invokingStateNumber) { + super(parent, invokingStateNumber); + } + @Override public int getAltNumber() { return altNum; } + @Override public void setAltNumber(int altNum) { this.altNum = altNum; } +} diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java b/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java index c58ee3dbe..3cb86683b 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/Trees.java @@ -33,7 +33,9 @@ package org.antlr.v4.runtime.tree; import org.antlr.v4.runtime.CommonToken; import org.antlr.v4.runtime.Parser; import org.antlr.v4.runtime.ParserRuleContext; +import org.antlr.v4.runtime.RuleContext; import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.atn.ATN; import org.antlr.v4.runtime.misc.Interval; import org.antlr.v4.runtime.misc.Predicate; import org.antlr.v4.runtime.misc.Utils; @@ -91,9 +93,13 @@ public class Trees { public static String getNodeText(Tree t, List ruleNames) { if ( ruleNames!=null ) { - if ( t instanceof RuleNode ) { - int ruleIndex = ((RuleNode)t).getRuleContext().getRuleIndex(); + if ( t instanceof RuleContext ) { + int ruleIndex = ((RuleContext)t).getRuleContext().getRuleIndex(); String ruleName = ruleNames.get(ruleIndex); + int altNumber = ((RuleContext) t).getAltNumber(); + if ( altNumber!=ATN.INVALID_ALT_NUMBER ) { + return ruleName+":"+altNumber; + } return ruleName; } else if ( t instanceof ErrorNode) { diff --git a/runtime/JavaScript/src/antlr4/Parser.js b/runtime/JavaScript/src/antlr4/Parser.js index 38e66dc74..1ec5cc014 100644 --- a/runtime/JavaScript/src/antlr4/Parser.js +++ b/runtime/JavaScript/src/antlr4/Parser.js @@ -451,6 +451,7 @@ Parser.prototype.exitRule = function() { }; Parser.prototype.enterOuterAlt = function(localctx, altNum) { + localctx.setAltNumber(altNum); // if we have new localctx, make sure we replace existing ctx // that is previous child of parse tree if (this.buildParseTrees && this._ctx !== localctx) { diff --git a/runtime/JavaScript/src/antlr4/RuleContext.js b/runtime/JavaScript/src/antlr4/RuleContext.js index 7299357b9..c3631bab6 100644 --- a/runtime/JavaScript/src/antlr4/RuleContext.js +++ b/runtime/JavaScript/src/antlr4/RuleContext.js @@ -51,6 +51,7 @@ var RuleNode = require('./tree/Tree').RuleNode; var INVALID_INTERVAL = require('./tree/Tree').INVALID_INTERVAL; +var INVALID_ALT_NUMBER = require('./atn/ATN').INVALID_ALT_NUMBER; function RuleContext(parent, invokingState) { RuleNode.call(this); @@ -113,6 +114,21 @@ RuleContext.prototype.getText = function() { } }; +// For rule associated with this parse tree internal node, return +// the outer alternative number used to match the input. Default +// implementation does not compute nor store this alt num. Create +// a subclass of ParserRuleContext with backing field and set +// option contextSuperClass. +// to set it. +RuleContext.prototype.getAltNumber = function() { return INVALID_ALT_NUMBER; } + +// Set the outer alternative number for this context node. Default +// implementation does nothing to avoid backing field overhead for +// trees that don't need it. Create +// a subclass of ParserRuleContext with backing field and set +// option contextSuperClass. +RuleContext.prototype.setAltNumber = function(altNumber) { } + RuleContext.prototype.getChild = function(i) { return null; }; diff --git a/runtime/JavaScript/src/antlr4/tree/Trees.js b/runtime/JavaScript/src/antlr4/tree/Trees.js index 38a039b2e..d20258e73 100644 --- a/runtime/JavaScript/src/antlr4/tree/Trees.js +++ b/runtime/JavaScript/src/antlr4/tree/Trees.js @@ -34,6 +34,8 @@ var RuleNode = require('./Tree').RuleNode; var ErrorNode = require('./Tree').ErrorNode; var TerminalNode = require('./Tree').TerminalNode; var ParserRuleContext = require('./../ParserRuleContext').ParserRuleContext; +var RuleContext = require('./../RuleContext').RuleContext; +var INVALID_ALT_NUMBER = require('./../atn/ATN').INVALID_ALT_NUMBER; /** A set of utility routines useful for all kinds of ANTLR trees. */ @@ -75,8 +77,12 @@ Trees.getNodeText = function(t, ruleNames, recog) { ruleNames = recog.ruleNames; } if(ruleNames!==null) { - if (t instanceof RuleNode) { - return ruleNames[t.getRuleContext().ruleIndex]; + if (t instanceof RuleContext) { + var altNumber = t.getAltNumber(); + if ( altNumber!=INVALID_ALT_NUMBER ) { + return ruleNames[t.ruleIndex]+":"+altNumber; + } + return ruleNames[t.ruleIndex]; } else if ( t instanceof ErrorNode) { return t.toString(); } else if(t instanceof TerminalNode) { @@ -115,7 +121,7 @@ Trees.getAncestors = function(t) { } return ancestors; }; - + Trees.findAllTokenNodes = function(t, ttype) { return Trees.findAllNodes(t, ttype, true); }; diff --git a/runtime/Python2/setup.py b/runtime/Python2/setup.py index 42dbc86b5..b4815753e 100644 --- a/runtime/Python2/setup.py +++ b/runtime/Python2/setup.py @@ -2,12 +2,12 @@ from distutils.core import setup setup( name='antlr4-python2-runtime', - version='4.5.2.1', + version='4.5.3', packages=['antlr4', 'antlr4.atn', 'antlr4.dfa', 'antlr4.tree', 'antlr4.error', 'antlr4.xpath'], package_dir={'': 'src'}, url='http://www.antlr.org', license='BSD', author='Eric Vergnaud, Terence Parr, Sam Harwell', author_email='eric.vergnaud@wanadoo.fr', - description='ANTLR 4.5.2.1 runtime for Python 2.7.6' + description='ANTLR 4.5.3 runtime for Python 2.7.6' ) diff --git a/runtime/Python2/src/antlr4/Parser.py b/runtime/Python2/src/antlr4/Parser.py index 47e58d073..0439df2c4 100644 --- a/runtime/Python2/src/antlr4/Parser.py +++ b/runtime/Python2/src/antlr4/Parser.py @@ -38,7 +38,7 @@ from antlr4.tree.ParseTreePatternMatcher import ParseTreePatternMatcher from antlr4.tree.Tree import ParseTreeListener class TraceListener(ParseTreeListener): - + def __init__(self, parser): self._parser = parser @@ -152,7 +152,7 @@ class Parser (Recognizer): # @throws RecognitionException if the current input symbol did not match # a wildcard and the error strategy could not recover from the mismatched # symbol - + def matchWildcard(self): t = self.getCurrentToken() if t.type > 0: @@ -382,6 +382,7 @@ class Parser (Recognizer): self._ctx = self._ctx.parentCtx def enterOuterAlt(self, localctx, altNum): + localctx.setAltNumber(altNum) # if we have new localctx, make sure we replace existing ctx # that is previous child of parse tree if self.buildParseTrees and self._ctx != localctx: diff --git a/runtime/Python2/src/antlr4/RuleContext.py b/runtime/Python2/src/antlr4/RuleContext.py index 26e7c90c3..517f873d6 100644 --- a/runtime/Python2/src/antlr4/RuleContext.py +++ b/runtime/Python2/src/antlr4/RuleContext.py @@ -52,6 +52,7 @@ from io import StringIO from antlr4.tree.Tree import RuleNode, INVALID_INTERVAL from antlr4.tree.Trees import Trees +from antlr4.atn.ATN import ATN class RuleContext(RuleNode): @@ -109,6 +110,23 @@ class RuleContext(RuleNode): def getRuleIndex(self): return -1 + # For rule associated with this parse tree internal node, return + # the outer alternative number used to match the input. Default + # implementation does not compute nor store this alt num. Create + # a subclass of ParserRuleContext with backing field and set + # option contextSuperClass. + # to set it. + def getAltNumber(self): + return ATN.INVALID_ALT_NUMBER + + # Set the outer alternative number for this context node. Default + # implementation does nothing to avoid backing field overhead for + # trees that don't need it. Create + # a subclass of ParserRuleContext with backing field and set + # option contextSuperClass. + def setAltNumber(self, altNumber): + pass + def getChild(self, i): return None diff --git a/runtime/Python2/src/antlr4/tree/Trees.py b/runtime/Python2/src/antlr4/tree/Trees.py index 61722faa9..d48f4a904 100644 --- a/runtime/Python2/src/antlr4/tree/Trees.py +++ b/runtime/Python2/src/antlr4/tree/Trees.py @@ -32,6 +32,8 @@ # A set of utility routines useful for all kinds of ANTLR trees.# from io import StringIO +import antlr4 +from antlr4.atn.ATN import ATN from antlr4.Token import Token from antlr4.Utils import escapeWhitespace from antlr4.tree.Tree import RuleNode, ErrorNode, TerminalNode @@ -65,7 +67,9 @@ class Trees(object): ruleNames = recog.ruleNames if ruleNames is not None: if isinstance(t, RuleNode): - return ruleNames[t.getRuleContext().getRuleIndex()] + if t.getAltNumber()!=ATN.INVALID_ALT_NUMBER: + return ruleNames[t.getRuleIndex()]+":"+str(t.getAltNumber()) + return ruleNames[t.getRuleIndex()] elif isinstance( t, ErrorNode): return unicode(t) elif isinstance(t, TerminalNode): diff --git a/runtime/Python3/setup.py b/runtime/Python3/setup.py index 65cdd8d27..2de08f223 100644 --- a/runtime/Python3/setup.py +++ b/runtime/Python3/setup.py @@ -2,12 +2,12 @@ from distutils.core import setup setup( name='antlr4-python3-runtime', - version='4.5.2.1', + version='4.5.3', packages=['antlr4', 'antlr4.atn', 'antlr4.dfa', 'antlr4.tree', 'antlr4.error', 'antlr4.xpath'], package_dir={'': 'src'}, url='http://www.antlr.org', license='BSD', author='Eric Vergnaud, Terence Parr, Sam Harwell', author_email='eric.vergnaud@wanadoo.fr', - description='ANTLR 4.5.2.1 runtime for Python 3.4.0' + description='ANTLR 4.5.3 runtime for Python 3.4.0' ) diff --git a/runtime/Python3/src/antlr4/Parser.py b/runtime/Python3/src/antlr4/Parser.py index 224cd4024..0d6824b20 100644 --- a/runtime/Python3/src/antlr4/Parser.py +++ b/runtime/Python3/src/antlr4/Parser.py @@ -159,7 +159,7 @@ class Parser (Recognizer): # @throws RecognitionException if the current input symbol did not match # a wildcard and the error strategy could not recover from the mismatched # symbol - + def matchWildcard(self): t = self.getCurrentToken() if t.type > 0: @@ -389,6 +389,7 @@ class Parser (Recognizer): self._ctx = self._ctx.parentCtx def enterOuterAlt(self, localctx:ParserRuleContext, altNum:int): + localctx.setAltNumber(altNum) # if we have new localctx, make sure we replace existing ctx # that is previous child of parse tree if self.buildParseTrees and self._ctx != localctx: diff --git a/runtime/Python3/src/antlr4/RuleContext.py b/runtime/Python3/src/antlr4/RuleContext.py index 496235715..c8f5ae053 100644 --- a/runtime/Python3/src/antlr4/RuleContext.py +++ b/runtime/Python3/src/antlr4/RuleContext.py @@ -113,6 +113,23 @@ class RuleContext(RuleNode): def getRuleIndex(self): return -1 + # For rule associated with this parse tree internal node, return + # the outer alternative number used to match the input. Default + # implementation does not compute nor store this alt num. Create + # a subclass of ParserRuleContext with backing field and set + # option contextSuperClass. + # to set it. + def getAltNumber(self): + return 0 # should use ATN.INVALID_ALT_NUMBER but won't compile + + # Set the outer alternative number for this context node. Default + # implementation does nothing to avoid backing field overhead for + # trees that don't need it. Create + # a subclass of ParserRuleContext with backing field and set + # option contextSuperClass. + def setAltNumber(self, altNumber:int): + pass + def getChild(self, i:int): return None diff --git a/runtime/Python3/src/antlr4/tree/Trees.py b/runtime/Python3/src/antlr4/tree/Trees.py index 234034586..101df6d9a 100644 --- a/runtime/Python3/src/antlr4/tree/Trees.py +++ b/runtime/Python3/src/antlr4/tree/Trees.py @@ -68,7 +68,9 @@ class Trees(object): ruleNames = recog.ruleNames if ruleNames is not None: if isinstance(t, RuleNode): - return ruleNames[t.getRuleContext().getRuleIndex()] + if t.getAltNumber()!=0: # should use ATN.INVALID_ALT_NUMBER but won't compile + return ruleNames[t.getRuleIndex()]+":"+str(t.getAltNumber()) + return ruleNames[t.getRuleIndex()] elif isinstance( t, ErrorNode): return str(t) elif isinstance(t, TerminalNode): diff --git a/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java b/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java index 1a555c4ed..bff84ae17 100644 --- a/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java +++ b/tool-testsuite/test/org/antlr/v4/test/tool/InterpreterTreeTextProvider.java @@ -1,10 +1,9 @@ package org.antlr.v4.test.tool; +import org.antlr.v4.gui.TreeTextProvider; import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.Tree; import org.antlr.v4.runtime.tree.Trees; -import org.antlr.v4.gui.TreeTextProvider; -import org.antlr.v4.tool.GrammarInterpreterRuleContext; import java.util.Arrays; import java.util.List; @@ -17,10 +16,6 @@ public class InterpreterTreeTextProvider implements TreeTextProvider { public String getText(Tree node) { if ( node==null ) return "null"; String nodeText = Trees.getNodeText(node, ruleNames); - if ( node instanceof GrammarInterpreterRuleContext) { - GrammarInterpreterRuleContext ctx = (GrammarInterpreterRuleContext) node; - return nodeText+":"+ctx.getOuterAltNum(); - } if ( node instanceof ErrorNode) { return ""; } diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/CSharp/CSharp.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/CSharp/CSharp.stg index 0617385b1..6d5710922 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/CSharp/CSharp.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/CSharp/CSharp.stg @@ -30,7 +30,7 @@ // args must be , -ParserFile(file, parser, namedActions) ::= << +ParserFile(file, parser, namedActions, contextSuperClass) ::= << namespace { @@ -839,7 +839,7 @@ CaptureNextTokenType(d) ::= " = TokenStream.La(1);" StructDecl(struct,ctorAttrs,attrs,getters,dispatchMethods,interfaces,extensionMembers, superClass={ParserRuleContext}) ::= << -public partial class : , { +public partial class : ParserRuleContext, { ;}; separator="\n"> }; separator="\n"> public (ParserRuleContext parent, int invokingState) : base(parent, invokingState) { } diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg index ea3dba1de..af925be25 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Java/Java.stg @@ -42,7 +42,7 @@ javaTypeInitMap ::= [ // args must be , -ParserFile(file, parser, namedActions) ::= << +ParserFile(file, parser, namedActions, contextSuperClass) ::= << package ; @@ -765,8 +765,9 @@ ListLabelName(label) ::= "