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 6627820d7..17bfda1ae 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 @@ -229,6 +229,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { bool Property() { diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg index be79a1f4e..5e0c50342 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/go/Go.test.stg @@ -194,7 +194,7 @@ StringList() ::= "[]string" BuildParseTrees() ::= "p.BuildParseTrees = true" -BailErrorStrategy() ::= <%p.SetErrorHandler(p.NewBailErrorStrategy())%> +BailErrorStrategy() ::= <%p.SetErrorHandler(antlr.NewBailErrorStrategy())%> ToStringTree(s) ::= <%.ToStringTree(nil, p)%> @@ -226,6 +226,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <%> +Production(p) ::= <%%> + +Result(r) ::= <%Get()%> + ParserPropertyMember() ::= << @members { func Property() bool { @@ -356,7 +360,7 @@ func NewLeafListener() *LeafListener { func (*LeafListener) ExitA(ctx *AContext) { if ctx.GetChildCount() == 2 { - fmt.Printf("%s %s %s", ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(), ctx.INT(0)[0]) + fmt.Printf("%s %s %s", ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(), ctx.AllINT()) } else { fmt.Println(ctx.ID().GetSymbol()) } @@ -374,9 +378,9 @@ func NewLeafListener() *LeafListener { func (*LeafListener) ExitA(ctx *AContext) { if ctx.GetChildCount() == 2 { - fmt.Printf("%s %s %s", ctx.B(0)[0].GetStart().GetText(), ctx.B(1)[0].GetStart().GetText(), ctx.B(-1)[0].GetStart().GetText()) + fmt.Printf("%s %s %s", ctx.B(0).GetStart().GetText(), ctx.B(1).GetStart().GetText(), ctx.AllB()[0].GetStart().GetText()) } else { - fmt.Println(ctx.B(0)[0].GetStart().GetText()) + fmt.Println(ctx.B(0).GetStart().GetText()) } } >> @@ -392,7 +396,7 @@ func NewLeafListener() *LeafListener { func (*LeafListener) ExitE(ctx *EContext) { if ctx.GetChildCount() == 3 { - fmt.Printf("%s %s %s\n", ctx.E(0)[0].GetStart().GetText(), ctx.E(1)[0].GetStart().GetText(), ctx.E(-1)[0].GetStart().GetText()) + fmt.Printf("%s %s %s\n", ctx.E(0).GetStart().GetText(), ctx.E(1).GetStart().GetText(), ctx.AllE()[0].GetStart().GetText()) } else { fmt.Println(ctx.INT().GetSymbol().GetText()) } 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 9600a5d0d..210b1682e 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 @@ -235,6 +235,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <<_interp.setPredictionMode(PredictionMode.LL_EXA ParserToken(parser, token) ::= <%.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { boolean Property() { 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 2a0b27ebc..4022ca552 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 @@ -235,6 +235,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { this.Property = function() { 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 0d084b09a..69f89741b 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 @@ -235,6 +235,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { this.Property = function() { 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 7254725f8..d814179a1 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 @@ -237,6 +237,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { this.Property = function() { 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 31debe16c..3cc616318 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 @@ -235,6 +235,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { this.Property = function() { 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 0293b5703..d5d6f8d76 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 @@ -235,6 +235,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { this.Property = function() { 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 881a567f4..13aea5457 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 @@ -239,6 +239,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { def Property(self): 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 7dea67cf6..73ba0197f 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 @@ -241,6 +241,10 @@ LL_EXACT_AMBIG_DETECTION() ::= <.%> +Production(p) ::= <%

%> + +Result(r) ::= <%%> + ParserPropertyMember() ::= << @members { def Property(self): diff --git a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/LeftRecursion/MultipleAlternativesWithCommonLabel.stg b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/LeftRecursion/MultipleAlternativesWithCommonLabel.stg index 1fc0c9700..ccb1a522b 100644 --- a/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/LeftRecursion/MultipleAlternativesWithCommonLabel.stg +++ b/runtime-testsuite/resources/org/antlr/v4/test/runtime/templates/LeftRecursion/MultipleAlternativesWithCommonLabel.stg @@ -21,8 +21,8 @@ grammar(grammarName) ::= << grammar ; s : e {}; e returns [int v] - : e '*' e {$v = .e(0).v * .e(1).v;} # binary - | e '+' e {$v = .e(0).v + .e(1).v;} # binary + : e '*' e {$v = .(0). * .(1).;} # binary + | e '+' e {$v = .(0). + .(1).;} # binary | INT {$v = $INT.int;} # anInt | '(' e ')' {$v = $e.v;} # parens | left=e INC {$v = $left.v + 1;} # unary diff --git a/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java b/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java index 34837d3dd..7b908ce31 100644 --- a/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java +++ b/runtime-testsuite/src/org/antlr/v4/testgen/TestGenerator.java @@ -42,6 +42,7 @@ import java.util.Map; import org.stringtemplate.v4.ST; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupFile; +import org.stringtemplate.v4.StringRenderer; import org.stringtemplate.v4.gui.STViz; public class TestGenerator { @@ -169,6 +170,7 @@ public class TestGenerator { public void execute() { STGroup targetGroup = new STGroupFile(runtimeTemplate.getPath()); targetGroup.registerModelAdaptor(STGroup.class, new STGroupModelAdaptor()); + targetGroup.registerRenderer(String.class, new StringRenderer(), true); targetGroup.defineDictionary("escape", new JavaEscapeStringMap()); targetGroup.defineDictionary("lines", new LinesStringMap()); targetGroup.defineDictionary("strlen", new StrlenStringMap()); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLeftRecursion.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLeftRecursion.java index 9c7a588de..7b765a484 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLeftRecursion.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestLeftRecursion.java @@ -1723,12 +1723,12 @@ public class TestLeftRecursion extends BaseTest { @Test public void testMultipleAlternativesWithCommonLabel_1() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(576); + StringBuilder grammarBuilder = new StringBuilder(596); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : e {fmt.Println($e.v)};\n"); grammarBuilder.append("e returns [int v]\n"); - grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n"); - grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n"); + grammarBuilder.append(" : e '*' e {$v = ($ctx).E(0).GetV() * ($ctx).E(1).GetV();} # binary\n"); + grammarBuilder.append(" | e '+' e {$v = ($ctx).E(0).GetV() + ($ctx).E(1).GetV();} # binary\n"); grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n"); grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n"); grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n"); @@ -1752,12 +1752,12 @@ public class TestLeftRecursion extends BaseTest { @Test public void testMultipleAlternativesWithCommonLabel_2() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(576); + StringBuilder grammarBuilder = new StringBuilder(596); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : e {fmt.Println($e.v)};\n"); grammarBuilder.append("e returns [int v]\n"); - grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n"); - grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n"); + grammarBuilder.append(" : e '*' e {$v = ($ctx).E(0).GetV() * ($ctx).E(1).GetV();} # binary\n"); + grammarBuilder.append(" | e '+' e {$v = ($ctx).E(0).GetV() + ($ctx).E(1).GetV();} # binary\n"); grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n"); grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n"); grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n"); @@ -1781,12 +1781,12 @@ public class TestLeftRecursion extends BaseTest { @Test public void testMultipleAlternativesWithCommonLabel_3() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(576); + StringBuilder grammarBuilder = new StringBuilder(596); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : e {fmt.Println($e.v)};\n"); grammarBuilder.append("e returns [int v]\n"); - grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n"); - grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n"); + grammarBuilder.append(" : e '*' e {$v = ($ctx).E(0).GetV() * ($ctx).E(1).GetV();} # binary\n"); + grammarBuilder.append(" | e '+' e {$v = ($ctx).E(0).GetV() + ($ctx).E(1).GetV();} # binary\n"); grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n"); grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n"); grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n"); @@ -1810,12 +1810,12 @@ public class TestLeftRecursion extends BaseTest { @Test public void testMultipleAlternativesWithCommonLabel_4() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(576); + StringBuilder grammarBuilder = new StringBuilder(596); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s : e {fmt.Println($e.v)};\n"); grammarBuilder.append("e returns [int v]\n"); - grammarBuilder.append(" : e '*' e {$v = ($ctx).e(0).v * ($ctx).e(1).v;} # binary\n"); - grammarBuilder.append(" | e '+' e {$v = ($ctx).e(0).v + ($ctx).e(1).v;} # binary\n"); + grammarBuilder.append(" : e '*' e {$v = ($ctx).E(0).GetV() * ($ctx).E(1).GetV();} # binary\n"); + grammarBuilder.append(" | e '+' e {$v = ($ctx).E(0).GetV() + ($ctx).E(1).GetV();} # binary\n"); grammarBuilder.append(" | INT {$v = $INT.int;} # anInt\n"); grammarBuilder.append(" | '(' e ')' {$v = $e.v;} # parens\n"); grammarBuilder.append(" | left=e INC {$v = $left.v + 1;} # unary\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java index 66300878c..43c5817de 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestListeners.java @@ -62,7 +62,7 @@ public class TestListeners extends BaseTest { @Test public void testLR() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(723); + StringBuilder grammarBuilder = new StringBuilder(718); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@parser::header {\n"); grammarBuilder.append("}\n"); @@ -78,7 +78,7 @@ public class TestListeners extends BaseTest { grammarBuilder.append("\n"); grammarBuilder.append("func (*LeafListener) ExitE(ctx *EContext) {\n"); grammarBuilder.append(" if ctx.GetChildCount() == 3 {\n"); - grammarBuilder.append(" fmt.Printf(\"%s %s %s\\n\", ctx.E(0)[0].GetStart().GetText(), ctx.E(1)[0].GetStart().GetText(), ctx.E(-1)[0].GetStart().GetText())\n"); + grammarBuilder.append(" fmt.Printf(\"%s %s %s\\n\", ctx.E(0).GetStart().GetText(), ctx.E(1).GetStart().GetText(), ctx.AllE()[0].GetStart().GetText())\n"); grammarBuilder.append(" } else {\n"); grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText())\n"); grammarBuilder.append(" }\n"); @@ -177,7 +177,7 @@ public class TestListeners extends BaseTest { @Test public void testRuleGetters_1() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(749); + StringBuilder grammarBuilder = new StringBuilder(741); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@parser::header {\n"); grammarBuilder.append("}\n"); @@ -193,9 +193,9 @@ public class TestListeners extends BaseTest { grammarBuilder.append("\n"); grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n"); grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n"); - grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.B(0)[0].GetStart().GetText(), ctx.B(1)[0].GetStart().GetText(), ctx.B(-1)[0].GetStart().GetText())\n"); + grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.B(0).GetStart().GetText(), ctx.B(1).GetStart().GetText(), ctx.AllB()[0].GetStart().GetText())\n"); grammarBuilder.append(" } else {\n"); - grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText())\n"); + grammarBuilder.append(" fmt.Println(ctx.B(0).GetStart().GetText())\n"); grammarBuilder.append(" }\n"); grammarBuilder.append("}\n"); grammarBuilder.append("}\n"); @@ -231,7 +231,7 @@ public class TestListeners extends BaseTest { @Test public void testRuleGetters_2() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(749); + StringBuilder grammarBuilder = new StringBuilder(741); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@parser::header {\n"); grammarBuilder.append("}\n"); @@ -247,9 +247,9 @@ public class TestListeners extends BaseTest { grammarBuilder.append("\n"); grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n"); grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n"); - grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.B(0)[0].GetStart().GetText(), ctx.B(1)[0].GetStart().GetText(), ctx.B(-1)[0].GetStart().GetText())\n"); + grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.B(0).GetStart().GetText(), ctx.B(1).GetStart().GetText(), ctx.AllB()[0].GetStart().GetText())\n"); grammarBuilder.append(" } else {\n"); - grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText())\n"); + grammarBuilder.append(" fmt.Println(ctx.B(0).GetStart().GetText())\n"); grammarBuilder.append(" }\n"); grammarBuilder.append("}\n"); grammarBuilder.append("}\n"); @@ -285,7 +285,7 @@ public class TestListeners extends BaseTest { @Test public void testTokenGetters_1() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(681); + StringBuilder grammarBuilder = new StringBuilder(674); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@parser::header {\n"); grammarBuilder.append("}\n"); @@ -301,7 +301,7 @@ public class TestListeners extends BaseTest { grammarBuilder.append("\n"); grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n"); grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n"); - grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(), ctx.INT(0)[0])\n"); + grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(), ctx.AllINT())\n"); grammarBuilder.append(" } else {\n"); grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n"); grammarBuilder.append(" }\n"); @@ -338,7 +338,7 @@ public class TestListeners extends BaseTest { @Test public void testTokenGetters_2() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(681); + StringBuilder grammarBuilder = new StringBuilder(674); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("@parser::header {\n"); grammarBuilder.append("}\n"); @@ -354,7 +354,7 @@ public class TestListeners extends BaseTest { grammarBuilder.append("\n"); grammarBuilder.append("func (*LeafListener) ExitA(ctx *AContext) {\n"); grammarBuilder.append(" if ctx.GetChildCount() == 2 {\n"); - grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(), ctx.INT(0)[0])\n"); + grammarBuilder.append(" fmt.Printf(\"%s %s %s\", ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(), ctx.AllINT())\n"); grammarBuilder.append(" } else {\n"); grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n"); grammarBuilder.append(" }\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java index 2da44533b..5a1fc3d51 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserExec.java @@ -599,10 +599,10 @@ public class TestParserExec extends BaseTest { @Test public void testPredictionIssue334() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(251); + StringBuilder grammarBuilder = new StringBuilder(255); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("file_ @init{\n"); - grammarBuilder.append("p.SetErrorHandler(p.NewBailErrorStrategy())\n"); + grammarBuilder.append("p.SetErrorHandler(antlr.NewBailErrorStrategy())\n"); grammarBuilder.append("} \n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($ctx.ToStringTree(nil, p))\n"); diff --git a/runtime/Go/antlr/error_strategy.go b/runtime/Go/antlr/error_strategy.go index 8b2b14254..848f3d2d4 100644 --- a/runtime/Go/antlr/error_strategy.go +++ b/runtime/Go/antlr/error_strategy.go @@ -26,6 +26,8 @@ type DefaultErrorStrategy struct { lastErrorStates *IntervalSet } +var _ ErrorStrategy = &DefaultErrorStrategy{} + func NewDefaultErrorStrategy() *DefaultErrorStrategy { d := new(DefaultErrorStrategy) @@ -737,6 +739,8 @@ type BailErrorStrategy struct { *DefaultErrorStrategy } +var _ ErrorStrategy = &BailErrorStrategy{} + func NewBailErrorStrategy() *BailErrorStrategy { b := new(BailErrorStrategy) @@ -763,8 +767,10 @@ func (b *BailErrorStrategy) Recover(recognizer Parser, e RecognitionException) { // Make sure we don't attempt to recover inline if the parser // successfully recovers, it won't panic an exception. // -func (b *BailErrorStrategy) RecoverInline(recognizer Parser) { +func (b *BailErrorStrategy) RecoverInline(recognizer Parser) Token { b.Recover(recognizer, NewInputMisMatchException(recognizer)) + + return nil } // Make sure we don't attempt to recover from problems in subrules.// diff --git a/runtime/Go/antlr/rule_context.go b/runtime/Go/antlr/rule_context.go index 5387ec196..753b7390b 100644 --- a/runtime/Go/antlr/rule_context.go +++ b/runtime/Go/antlr/rule_context.go @@ -63,7 +63,11 @@ func (b *BaseRuleContext) GetBaseRuleContext() *BaseRuleContext { } func (b *BaseRuleContext) SetParent(v Tree) { - b.parentCtx = v.(RuleContext) + if v == nil { + b.parentCtx = nil + } else { + b.parentCtx = v.(RuleContext) + } } func (b *BaseRuleContext) GetInvokingState() int { diff --git a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg index f55a4e917..59c1100eb 100644 --- a/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg +++ b/tool/resources/org/antlr/v4/tool/templates/codegen/Go/Go.stg @@ -347,7 +347,7 @@ func (l *) _Action(localctx ) _Sempred(localctx antlr.RuleContext, predIndex int) bool { +func (p *) _Sempred(localctx antlr.RuleContext, predIndex int) bool { switch predIndex { : @@ -371,7 +371,7 @@ RuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs, namedAction -func (p *) ( }; separator=", ">) (localctx I) { +func (p *) ( }; separator=", ">) (localctx I) { localctx = New(p, p.GetParserRuleContext(), p.GetState()}>) p.EnterRule(localctx, , RULE_) @@ -429,13 +429,18 @@ LeftRecursiveRuleFunction(currentRule, args, code, locals, ruleCtx, altLabelCtxs + }; separator="\n\n"> -func (p *) (_p int, }>) (localctx I) { +func (p *) ( }; separator=", ">) (localctx I) { + return p.(0}>) +} + +func (p *) (_p int }>) (localctx I) { var _parentctx antlr.ParserRuleContext = p.GetParserRuleContext() _parentState := p.GetState() localctx = New(p, p.GetParserRuleContext(), _parentState}>) @@ -731,11 +736,20 @@ InvokeRule(r, argExprsChunks) ::= << p.SetState() -var _x = p.(,) + +var _x = p.(, ) + +var _x = p.() + + = _x}; separator="\n"> -p.(,) + +p.(, ) + +p.() + >> @@ -881,53 +895,37 @@ ContextTokenGetterDecl(t) ::= << } >> -// should never be called ContextTokenListGetterDecl(t) ::= << -fail: ContextTokenListGetterDecl should never be called! +All() []antlr.TerminalNode { + return s.GetTokens() +} >> ContextTokenListIndexedGetterDecl(t) ::= << -(i int) []antlr.TerminalNode { - if i \< 0 { - return s.GetTokens() - } else { - return []antlr.TerminalNode{s.GetToken(, i)} - } +(i int) antlr.TerminalNode { + return s.GetToken(, i) } >> ContextRuleGetterDecl(r) ::= << () I { - v := s.GetTypedRuleContext(reflect.TypeOf((*I)(nil)).Elem(), 0) + var t = s.GetTypedRuleContext(reflect.TypeOf((*I)(nil)).Elem(), 0) - if v == nil { + if t == nil { return nil } - return v.(I) + return t.(I) } >> -// should never be called ContextRuleListGetterDecl(r) ::= << -fail: ContextRuleListGetterDecl should never be called! ->> +All() []I { + var ts = s.GetTypedRuleContexts(reflect.TypeOf((*I)(nil)).Elem()) + var tst = make([]I, len(ts)) -ContextRuleListIndexedGetterDecl(r) ::= << -(i int) []I { - var ts []antlr.RuleContext - - if i \< 0 { - ts = s.GetTypedRuleContexts(reflect.TypeOf((*I)(nil)).Elem()) - } else { - ts = []antlr.RuleContext{s.GetTypedRuleContext(reflect.TypeOf((*I)(nil)).Elem(), i)} - } - - var tst []I = make([]I, len(ts)) for i, t := range ts { - if t == nil { - tst[i] = nil - } else { + if t != nil { tst[i] = t.(I) } } @@ -936,6 +934,18 @@ ContextRuleListIndexedGetterDecl(r) ::= << } >> +ContextRuleListIndexedGetterDecl(r) ::= << +(i int) I { + var t = s.GetTypedRuleContext(reflect.TypeOf((*I)(nil)).Elem(), i) + + if t == nil { + return nil + } + + return t.(I) +} +>> + LexerRuleContext() ::= "RuleContext" /** The rule context name is the rule followed by a suffix; e.g., diff --git a/tool/src/org/antlr/v4/codegen/model/LeftRecursiveRuleFunction.java b/tool/src/org/antlr/v4/codegen/model/LeftRecursiveRuleFunction.java index adbc3a623..73155f440 100644 --- a/tool/src/org/antlr/v4/codegen/model/LeftRecursiveRuleFunction.java +++ b/tool/src/org/antlr/v4/codegen/model/LeftRecursiveRuleFunction.java @@ -42,6 +42,8 @@ import org.antlr.v4.tool.Rule; import org.antlr.v4.tool.ast.GrammarAST; public class LeftRecursiveRuleFunction extends RuleFunction { + public String recognizerName; + public LeftRecursiveRuleFunction(OutputModelFactory factory, LeftRecursiveRule r) { super(factory, r); @@ -72,5 +74,7 @@ public class LeftRecursiveRuleFunction extends RuleFunction { struct.addDecl(d); // stick in overall rule's ctx } } + + recognizerName = factory.getGrammar().getRecognizerName(); } } diff --git a/tool/src/org/antlr/v4/codegen/model/RuleFunction.java b/tool/src/org/antlr/v4/codegen/model/RuleFunction.java index 25d6d0f79..75cd3fe0c 100644 --- a/tool/src/org/antlr/v4/codegen/model/RuleFunction.java +++ b/tool/src/org/antlr/v4/codegen/model/RuleFunction.java @@ -81,6 +81,7 @@ public class RuleFunction extends OutputModelObject { public Rule rule; public AltLabelStructDecl[] altToContext; public boolean hasLookaheadBlock; + public String recognizerName; @ModelElement public List code; @ModelElement public OrderedHashSet locals; // TODO: move into ctx? @@ -138,6 +139,7 @@ public class RuleFunction extends OutputModelObject { } startState = factory.getGrammar().atn.ruleToStartState[r.index]; + recognizerName = factory.getGrammar().getRecognizerName(); } public void addContextGetters(OutputModelFactory factory, Rule r) { diff --git a/tool/src/org/antlr/v4/codegen/model/RuleSempredFunction.java b/tool/src/org/antlr/v4/codegen/model/RuleSempredFunction.java index 2b1f6a1c9..9ac99b796 100644 --- a/tool/src/org/antlr/v4/codegen/model/RuleSempredFunction.java +++ b/tool/src/org/antlr/v4/codegen/model/RuleSempredFunction.java @@ -34,7 +34,10 @@ import org.antlr.v4.codegen.OutputModelFactory; import org.antlr.v4.tool.Rule; public class RuleSempredFunction extends RuleActionFunction { + public String recognizerName; + public RuleSempredFunction(OutputModelFactory factory, Rule r, String ctxType) { super(factory, r, ctxType); + recognizerName = factory.getGrammar().getRecognizerName(); } } diff --git a/tool/src/org/antlr/v4/codegen/target/GoTarget.java b/tool/src/org/antlr/v4/codegen/target/GoTarget.java index 0dc2f21f8..b642784ef 100644 --- a/tool/src/org/antlr/v4/codegen/target/GoTarget.java +++ b/tool/src/org/antlr/v4/codegen/target/GoTarget.java @@ -147,17 +147,5 @@ public class GoTarget extends Target { } } - - public boolean wantsBaseListener() { - return true; - } - - public boolean wantsBaseVisitor() { - return true; - } - - public boolean supportsOverloadedMethods() { - return false; - } }