diff --git a/pb/src/parserTest/test.go b/pb/src/parserTest/test.go index 0d6ecf414..7213d9fd4 100644 --- a/pb/src/parserTest/test.go +++ b/pb/src/parserTest/test.go @@ -27,11 +27,11 @@ func main() { a := antlr4.NewFileStream("foo.txt") - l := parser.NewTLexer(a) + l := parser.NewExprLexer(a) s := antlr4.NewCommonTokenStream(l, 0) - p := parser.NewTParser(s) + p := parser.NewExprParser(s) p.BuildParseTrees = true 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 0ddc659f9..dc28a8f2d 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 @@ -163,7 +163,7 @@ Assert(s) ::= <)>> Cast(t,v) ::= "(())" -Append(a,b) ::= " + " +Append(a,b) ::= " + fmt.Sprint()" Concat(a,b) ::= "" @@ -173,9 +173,9 @@ AssertIsList(v) ::= "List\ __ttt__ = ;" // just use type system AssignLocal(s,v) ::= " = ;" -InitIntMember(n,v) ::= <%var int = ;%> +InitIntMember(n,v) ::= <%var int = ; var _ int = ; // to disable unused var %> -InitBooleanMember(n,v) ::= <%var bool= ;%> +InitBooleanMember(n,v) ::= <%var bool= ; var _ bool = ; // to disable unused var %> GetMember(n) ::= <%this.%> @@ -197,7 +197,7 @@ Pass() ::= "" StringList() ::= "[]string" -BuildParseTrees() ::= "this.BuildParseTrees = true" +BuildParseTrees() ::= "p.BuildParseTrees = true" BailErrorStrategy() ::= <%SetErrorHandler(NewBailErrorStrategy())%> diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestCompositeParsers.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestCompositeParsers.java index 108f92544..84f66f95e 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestCompositeParsers.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestCompositeParsers.java @@ -379,7 +379,7 @@ public class TestCompositeParsers extends BaseTest { mkdir(parserpkgdir); String slave_S = "parser grammar S;\n" + - "a @after {var x int = 0;} : B;"; + "a @after {var x int = 0; var _ int = x; // to disable unused var } : B;"; writeFile(parserpkgdir, "S.g4", slave_S); StringBuilder grammarBuilder = new StringBuilder(62); @@ -406,10 +406,10 @@ public class TestCompositeParsers extends BaseTest { "ID : 'a'..'z'+;"; writeFile(parserpkgdir, "S.g4", slave_S); - StringBuilder grammarBuilder = new StringBuilder(113); + StringBuilder grammarBuilder = new StringBuilder(125); grammarBuilder.append("grammar M;\n"); grammarBuilder.append("import S;\n"); - grammarBuilder.append("a : A {fmt.Println(\"M.a: \" + $A)};\n"); + grammarBuilder.append("a : A {fmt.Println(\"M.a: \" + fmt.Sprint($A))};\n"); grammarBuilder.append("A : 'abc' {fmt.Println(\"M.A\")};\n"); grammarBuilder.append("WS : (' '|'\\n') -> skip ;"); String grammar = grammarBuilder.toString(); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParseTrees.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParseTrees.java index 762fc2309..1591e070f 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParseTrees.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParseTrees.java @@ -12,11 +12,11 @@ public class TestParseTrees extends BaseTest { @Test public void test2AltLoop() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(136); + StringBuilder grammarBuilder = new StringBuilder(133); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); @@ -37,11 +37,11 @@ public class TestParseTrees extends BaseTest { @Test public void test2Alts() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(129); + StringBuilder grammarBuilder = new StringBuilder(126); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); @@ -62,11 +62,11 @@ public class TestParseTrees extends BaseTest { @Test public void testExtraToken() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(142); + StringBuilder grammarBuilder = new StringBuilder(139); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); @@ -91,11 +91,11 @@ public class TestParseTrees extends BaseTest { @Test public void testNoViableAlt() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(144); + StringBuilder grammarBuilder = new StringBuilder(141); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); @@ -120,11 +120,11 @@ public class TestParseTrees extends BaseTest { @Test public void testRuleRef() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(138); + StringBuilder grammarBuilder = new StringBuilder(135); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); @@ -147,11 +147,11 @@ public class TestParseTrees extends BaseTest { @Test public void testSync() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(145); + StringBuilder grammarBuilder = new StringBuilder(142); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); @@ -175,11 +175,11 @@ public class TestParseTrees extends BaseTest { @Test public void testToken2() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(127); + StringBuilder grammarBuilder = new StringBuilder(124); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); @@ -200,11 +200,11 @@ public class TestParseTrees extends BaseTest { @Test public void testTokenAndRuleContextString() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(166); + StringBuilder grammarBuilder = new StringBuilder(163); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("s\n"); grammarBuilder.append("@init {\n"); - grammarBuilder.append("this.BuildParseTrees = true\n"); + grammarBuilder.append("p.BuildParseTrees = true\n"); grammarBuilder.append("}\n"); grammarBuilder.append("@after {\n"); grammarBuilder.append("fmt.Println($r.ctx.ToStringTree(nil,p))\n"); diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserErrors.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserErrors.java index 37eccb4b2..3d11f54a1 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserErrors.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestParserErrors.java @@ -12,9 +12,9 @@ public class TestParserErrors extends BaseTest { @Test public void testConjuringUpToken() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(62); + StringBuilder grammarBuilder = new StringBuilder(74); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : 'a' x='b' {fmt.Println(\"conjured=\" + $x)} 'c' ;"); + grammarBuilder.append("a : 'a' x='b' {fmt.Println(\"conjured=\" + fmt.Sprint($x))} 'c' ;"); String grammar = grammarBuilder.toString(); String input ="ac"; String found = execParser("T.g4", grammar, "TParser", "TLexer", @@ -29,9 +29,9 @@ public class TestParserErrors extends BaseTest { @Test public void testConjuringUpTokenFromSet() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(68); + StringBuilder grammarBuilder = new StringBuilder(80); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("a : 'a' x=('b'|'c') {fmt.Println(\"conjured=\" + $x)} 'd' ;"); + grammarBuilder.append("a : 'a' x=('b'|'c') {fmt.Println(\"conjured=\" + fmt.Sprint($x))} 'd' ;"); String grammar = grammarBuilder.toString(); String input ="ad"; String found = execParser("T.g4", grammar, "TParser", "TLexer", @@ -383,10 +383,10 @@ public class TestParserErrors extends BaseTest { @Test public void testSingleSetInsertionConsumption() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(81); + StringBuilder grammarBuilder = new StringBuilder(93); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("myset: ('b'|'c') ;\n"); - grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + $myset.stop)} ; "); + grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + fmt.Sprint($myset.stop))} ; "); String grammar = grammarBuilder.toString(); String input ="ad"; String found = execParser("T.g4", grammar, "TParser", "TLexer", @@ -496,10 +496,10 @@ public class TestParserErrors extends BaseTest { @Test public void testSingleTokenDeletionConsumption() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(81); + StringBuilder grammarBuilder = new StringBuilder(93); grammarBuilder.append("grammar T;\n"); grammarBuilder.append("myset: ('b'|'c') ;\n"); - grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + $myset.stop)} ; "); + grammarBuilder.append("a: 'a' myset 'd' {fmt.Println(\"\" + fmt.Sprint($myset.stop))} ; "); String grammar = grammarBuilder.toString(); String input ="aabd"; String found = execParser("T.g4", grammar, "TParser", "TLexer", diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java index 02d336d88..990c078c0 100644 --- a/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java +++ b/runtime-testsuite/test/org/antlr/v4/test/runtime/go/TestSemPredEvalParser.java @@ -74,9 +74,9 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testActionHidesPreds() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(227); + StringBuilder grammarBuilder = new StringBuilder(268); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {var i int = 0;}\n"); + grammarBuilder.append("@members {var i int = 0; var _ int = i; // to disable unused var }\n"); grammarBuilder.append("s : a+ ;\n"); grammarBuilder.append("a : {this.i = 1;} ID {this.i == 1}? {fmt.Println(\"alt 1\")}\n"); grammarBuilder.append(" | {this.i = 2;} ID {this.i == 2}? {fmt.Println(\"alt 2\")}\n"); @@ -352,9 +352,9 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testPredTestedEvenWhenUnAmbig_1() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(202); + StringBuilder grammarBuilder = new StringBuilder(254); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {var enumKeyword bool= true;}\n"); + grammarBuilder.append("@members {var enumKeyword bool= true; var _ bool = enumKeyword; // to disable unused var }\n"); grammarBuilder.append("primary\n"); grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n"); grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n"); @@ -374,9 +374,9 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testPredTestedEvenWhenUnAmbig_2() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(202); + StringBuilder grammarBuilder = new StringBuilder(254); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {var enumKeyword bool= true;}\n"); + grammarBuilder.append("@members {var enumKeyword bool= true; var _ bool = enumKeyword; // to disable unused var }\n"); grammarBuilder.append("primary\n"); grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n"); grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n"); @@ -397,9 +397,9 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testPredicateDependentOnArg() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(202); + StringBuilder grammarBuilder = new StringBuilder(243); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {var i int = 0;}\n"); + grammarBuilder.append("@members {var i int = 0; var _ int = i; // to disable unused var }\n"); grammarBuilder.append("s : a[2] a[1];\n"); grammarBuilder.append("a[int i]\n"); grammarBuilder.append(" : {$i==1}? ID {fmt.Println(\"alt 1\")}\n"); @@ -423,9 +423,9 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testPredicateDependentOnArg2() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(158); + StringBuilder grammarBuilder = new StringBuilder(199); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {var i int = 0;}\n"); + grammarBuilder.append("@members {var i int = 0; var _ int = i; // to disable unused var }\n"); grammarBuilder.append("s : a[2] a[1];\n"); grammarBuilder.append("a[int i]\n"); grammarBuilder.append(" : {$i==1}? ID \n"); @@ -599,9 +599,9 @@ public class TestSemPredEvalParser extends BaseTest { @Test public void testToLeftWithVaryingPredicate() throws Exception { mkdir(parserpkgdir); - StringBuilder grammarBuilder = new StringBuilder(251); + StringBuilder grammarBuilder = new StringBuilder(292); grammarBuilder.append("grammar T;\n"); - grammarBuilder.append("@members {var i int = 0;}\n"); + grammarBuilder.append("@members {var i int = 0; var _ int = i; // to disable unused var }\n"); grammarBuilder.append("s : ({this.i += 1;\n"); grammarBuilder.append("fmt.Println(\"i=\" + this.i)} a)+ ;\n"); grammarBuilder.append("a : {this.i % 2 == 0}? ID {fmt.Println(\"alt 1\")}\n"); diff --git a/runtime/Go/src/antlr4/ATNDeserializer.go b/runtime/Go/src/antlr4/ATNDeserializer.go index 522fd3781..1bac1d117 100644 --- a/runtime/Go/src/antlr4/ATNDeserializer.go +++ b/runtime/Go/src/antlr4/ATNDeserializer.go @@ -458,8 +458,7 @@ func (this *ATNDeserializer) stateIsEndStateFor(state ATNState, idx int) ATNStat // @param atn The ATN. // func (this *ATNDeserializer) markPrecedenceDecisions(atn *ATN) { - for i := 0; i < len(atn.states); i++ { - var state = atn.states[i] + for _, state := range atn.states { if _, ok := state.(*StarLoopEntryState); !ok { continue } @@ -468,12 +467,15 @@ func (this *ATNDeserializer) markPrecedenceDecisions(atn *ATN) { // precedence rule should continue or complete. // if atn.ruleToStartState[state.GetRuleIndex()].isPrecedenceRule { + var maybeLoopEndState = state.GetTransitions()[len(state.GetTransitions())-1].getTarget() + if s3, ok := maybeLoopEndState.(*LoopEndState); ok { - s := maybeLoopEndState.GetTransitions()[0].getTarget() - _, ok2 := s.(*RuleStopState) + + _, ok2 := maybeLoopEndState.GetTransitions()[0].getTarget().(*RuleStopState) + if s3.epsilonOnlyTransitions && ok2 { - s.(*StarLoopEntryState).precedenceRuleDecision = true + state.(*StarLoopEntryState).precedenceRuleDecision = true } } } diff --git a/runtime/Go/src/antlr4/Parser.go b/runtime/Go/src/antlr4/Parser.go index 06a6f375e..4727e5293 100644 --- a/runtime/Go/src/antlr4/Parser.go +++ b/runtime/Go/src/antlr4/Parser.go @@ -13,6 +13,7 @@ type Parser interface { GetTokenStream() TokenStream GetTokenFactory() TokenFactory GetParserRuleContext() ParserRuleContext + SetParserRuleContext(ParserRuleContext) Consume() Token GetParseListeners() []ParseTreeListener @@ -192,6 +193,10 @@ func (p *BaseParser) GetParserRuleContext() ParserRuleContext { return p._ctx } +func (p *BaseParser) SetParserRuleContext(v ParserRuleContext) { + p._ctx = v +} + func (p *BaseParser) GetParseListeners() []ParseTreeListener { if p._parseListeners == nil { return make([]ParseTreeListener, 0) 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 186f5b3b2..0925c64e4 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 @@ -170,7 +170,7 @@ const ( func (p *) Sempred(localctx antlr4.RuleContext, ruleIndex, predIndex int) bool { switch ruleIndex { : - return p._Sempred(localctx, predIndex);}; separator="\n"> + return p._Sempred(localctx.(*Context), predIndex)}; separator="\n"> default: panic("No predicate with index:" + fmt.Sprint(ruleIndex)) } @@ -187,7 +187,7 @@ func (l *) Action(localctx antlr4.RuleContext, ruleIndex, actionInde switch ruleIndex { : - l._Action(localctx, actionIndex) + l._Action(localctx.(*), actionIndex) }; separator="\n"> default: panic("No registered action for:" + fmt.Sprint(ruleIndex)) @@ -200,7 +200,7 @@ case : func (l *) Sempred(localctx antlr4.RuleContext, ruleIndex, predIndex int) bool { switch ruleIndex { : - return l._Sempred(localctx, predIndex);}; separator="\n"> + return l._Sempred(localctx.(*), predIndex);}; separator="\n"> default: panic("No registered predicate for:" + fmt.Sprint(ruleIndex)) } @@ -216,7 +216,7 @@ func (l *) Sempred(localctx antlr4.RuleContext, ruleIndex, predIndex */ RuleActionFunction(r, actions) ::= << -func (l *) _Action(localctx antlr4.RuleContext, actionIndex int) { +func (l *) _Action(localctx antlr4.RuleContext*, actionIndex int) { switch actionIndex { : @@ -232,7 +232,7 @@ case : * overriding implementation impossible to maintain. */ RuleSempredFunction(r, actions) ::= << -func (p *) _Sempred(localctx antlr4.RuleContext, predIndex int) bool { +func (p *) _Sempred(localctx antlr4.RuleContext*, predIndex int) bool { switch predIndex { : return ;}; separator="\n"> @@ -251,9 +251,9 @@ RuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,namedActions,fina }; separator="\n"> -func (p *) ( }; separator=", ">) * { +func (p *) ( }; separator=", ">) antlr4.ParserRuleContext { - localctx := New(p, p.GetParserRuleContext(), p.GetState()}>) + var localctx antlr4.ParserRuleContext = New(p, p.GetParserRuleContext(), p.GetState()}>) p.EnterRule(localctx, , RULE_) var @@ -295,12 +295,12 @@ LeftRecursiveRuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs, }; separator="\n"> -func (p *) (_p int, }>) * { +func (p *) (_p int, }>) antlr4.ParserRuleContext { - _parentctx := p.GetParserRuleContext() + var _parentctx antlr4.ParserRuleContext = p.GetParserRuleContext() _parentState := p.GetState() - localctx := New(p, p.GetParserRuleContext(), _parentState}>) - _prevctx := localctx + var localctx antlr4.ParserRuleContext = New(p, p.GetParserRuleContext(), _parentState}>) + var _prevctx antlr4.ParserRuleContext = localctx var _ antlr4.ParserRuleContext = _prevctx // to prevent unused variable warning _startState := p.EnterRecursionRule(localctx, , RULE_, _p) @@ -605,9 +605,10 @@ AddToLabelList(a) ::= ". = append(.() interface{} { @@ -687,6 +688,9 @@ func New(parser antlr4.Parser, parent antlr4.ParserRuleContext, inv p.parser = parser p.RuleIndex = RULE_ + + // TODO initialize list attrs + = }; separator="\n"> return p } @@ -791,7 +795,7 @@ p.PushNewRecursionContext(localctx, _startState, RULE_) recRuleReplaceContext(ctxName) ::= << localctx = NewContext(p, localctx) -p.GetParserRuleContext() = localctx +p.SetParserRuleContext(localctx) _prevctx = localctx >> diff --git a/tool/src/org/antlr/v4/codegen/model/RuleActionFunction.java b/tool/src/org/antlr/v4/codegen/model/RuleActionFunction.java index 8e6546237..a11b3ac4d 100644 --- a/tool/src/org/antlr/v4/codegen/model/RuleActionFunction.java +++ b/tool/src/org/antlr/v4/codegen/model/RuleActionFunction.java @@ -38,6 +38,7 @@ import java.util.LinkedHashMap; public class RuleActionFunction extends OutputModelObject { public String name; public String ctxType; + public boolean isRuleContext; public int ruleIndex; /** Map actionIndex to Action */ @@ -48,6 +49,7 @@ public class RuleActionFunction extends OutputModelObject { super(factory); name = r.name; ruleIndex = r.index; + isRuleContext = ctxType.equals("RuleContext"); this.ctxType = ctxType; } }