Even more test fixes yayaya
This commit is contained in:
parent
857600be43
commit
7473c21b1e
|
@ -177,19 +177,19 @@ InitIntMember(n,v) ::= <%var <n> int = <v>; var _ int = <n>; %>
|
|||
|
||||
InitBooleanMember(n,v) ::= <%var <n> bool= <v>; var _ bool = <n>; %>
|
||||
|
||||
GetMember(n) ::= <%this.<n>%>
|
||||
GetMember(n) ::= <%<n>%>
|
||||
|
||||
SetMember(n,v) ::= <%this.<n> = <v>;%>
|
||||
SetMember(n,v) ::= <%<n> = <v>;%>
|
||||
|
||||
AddMember(n,v) ::= <%this.<n> += <v>;%>
|
||||
AddMember(n,v) ::= <%<n> += <v>;%>
|
||||
|
||||
PlusMember(v,n) ::= <%<v> + this.<n>%>
|
||||
PlusMember(v,n) ::= <%<v> + <n>%>
|
||||
|
||||
MemberEquals(n,v) ::= <%this.<n> == <v>%>
|
||||
MemberEquals(n,v) ::= <%<n> == <v>%>
|
||||
|
||||
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
|
||||
ModMemberEquals(n,m,v) ::= <%<n> % <m> == <v>%>
|
||||
|
||||
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
|
||||
ModMemberNotEquals(n,m,v) ::= <%<n> % <m> != <v>%>
|
||||
|
||||
DumpDFA() ::= "p.DumpDFA()"
|
||||
|
||||
|
@ -203,13 +203,13 @@ BailErrorStrategy() ::= <%SetErrorHandler(NewBailErrorStrategy())%>
|
|||
|
||||
ToStringTree(s) ::= <%<s>.ToStringTree(nil,p)%>
|
||||
|
||||
Column() ::= "l.GetCharPositionInLine()"
|
||||
Column() ::= "p.GetCharPositionInLine()"
|
||||
|
||||
Text() ::= "l.GetText()"
|
||||
|
||||
ValEquals(a,b) ::= <%<a>==<b>%>
|
||||
|
||||
TextEquals(a) ::= <%l.GetText() == "<a>"%>
|
||||
TextEquals(a) ::= <%p.GetText() == "<a>"%>
|
||||
|
||||
PlusText(a) ::= <%"<a>" + l.GetText()%>
|
||||
|
||||
|
@ -219,7 +219,7 @@ LTEquals(i, v) ::= <%p.GetTokenStream().LT(<i>).GetText() == <v>%>
|
|||
|
||||
LANotEquals(i, v) ::= <%p.GetTokenStream().LA(<i>)!=<v>%>
|
||||
|
||||
TokenStartColumnEquals(i) ::= <%this.TokenStartCharPositionInLine==<i>%>
|
||||
TokenStartColumnEquals(i) ::= <%p.TokenStartColumn==<i>%>
|
||||
|
||||
ImportListener(X) ::= ""
|
||||
|
||||
|
@ -231,8 +231,8 @@ LL_EXACT_AMBIG_DETECTION() ::= <<p.Interpreter.SetPredictionMode(antlr4.Predicti
|
|||
|
||||
ParserPropertyMember() ::= <<
|
||||
@members {
|
||||
bool Property() {
|
||||
return true;
|
||||
func Property() bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
@ -330,13 +330,13 @@ func (this *NewPositionAdjustingLexerATNSimulator) ResetAcceptPosition(input Cha
|
|||
>>
|
||||
|
||||
BasicListener(X) ::= <<
|
||||
func LeafListener struct {
|
||||
*parser.BaseTListener
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
l := new(LeafListener)
|
||||
l.BaseTListener = new(parser.BaseTListener)
|
||||
l.BaseTListener = new(BaseTListener)
|
||||
return l
|
||||
}
|
||||
|
||||
|
@ -351,19 +351,19 @@ walker.Walk(NewLeafListener(), <s>);
|
|||
>>
|
||||
|
||||
TokenGetterListener(X) ::= <<
|
||||
func LeafListener struct {
|
||||
*parser.BaseTListener
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
l := new(LeafListener)
|
||||
l.BaseTListener = new(parser.BaseTListener)
|
||||
l.BaseTListener = new(BaseTListener)
|
||||
return l
|
||||
}
|
||||
|
||||
func (this *LeafListener) ExitA(ctx *parser.AContext) {
|
||||
func (this *LeafListener) ExitA(ctx *AContext) {
|
||||
if (ctx.GetChildCount()==2){
|
||||
fmt.Printf("%s %s %s",ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(),ctx.INT());
|
||||
fmt.Printf("%s %s %s",ctx.INT(0)[0].GetSymbol().GetText(), ctx.INT(1)[0].GetSymbol().GetText(),ctx.INT(0)[0]);
|
||||
} else {
|
||||
fmt.Println(ctx.ID().GetSymbol())
|
||||
}
|
||||
|
@ -371,39 +371,39 @@ func (this *LeafListener) ExitA(ctx *parser.AContext) {
|
|||
>>
|
||||
|
||||
RuleGetterListener(X) ::= <<
|
||||
func LeafListener struct {
|
||||
*parser.BaseTListener
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
l := new(LeafListener)
|
||||
l.BaseTListener = new(parser.BaseTListener)
|
||||
l.BaseTListener = new(BaseTListener)
|
||||
return l
|
||||
}
|
||||
|
||||
func (this *LeafListener) ExitA(ctx parser.AContext) {
|
||||
func (this *LeafListener) ExitA(ctx *AContext) {
|
||||
if (ctx.GetChildCount()==2) {
|
||||
fmt.Printf("%s %s %s",ctx.b(0).start.GetText(),ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());
|
||||
} else
|
||||
fmt.Println(ctx.b(0).start.GetText());
|
||||
fmt.Printf("%s %s %s",ctx.B(0)[0].GetStart().GetText(),ctx.B(1)[0].GetStart().GetText(),ctx.B(-1)[0].GetStart().GetText());
|
||||
} else {
|
||||
fmt.Println(ctx.B(0)[0].GetStart().GetText());
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
LRListener(X) ::= <<
|
||||
func LeafListener struct {
|
||||
*parser.BaseTListener
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
l := new(LeafListener)
|
||||
l.BaseTListener = new(parser.BaseTListener)
|
||||
l.BaseTListener = new(BaseTListener)
|
||||
return l
|
||||
}
|
||||
|
||||
func (this *LeafListener) ExitE(ctx *parser.EContext) {
|
||||
func (this *LeafListener) ExitE(ctx *EContext) {
|
||||
if (ctx.GetChildCount()==3) {
|
||||
fmt.Printf("%s %s %s\n",ctx.e(0).GetStart().GetText(), ctx.e(1).GetStart().GetText(), ctx.e().Get(0).GetStart().GetText());
|
||||
fmt.Printf("%s %s %s\n",ctx.E(0)[0].GetStart().GetText(), ctx.E(1)[0].GetStart().GetText(), ctx.E(-1)[0].GetStart().GetText());
|
||||
} else {
|
||||
fmt.Println(ctx.INT().GetSymbol().GetText())
|
||||
}
|
||||
|
@ -411,21 +411,21 @@ func (this *LeafListener) ExitE(ctx *parser.EContext) {
|
|||
>>
|
||||
|
||||
LRWithLabelsListener(X) ::= <<
|
||||
func LeafListener struct {
|
||||
*parser.BaseTListener
|
||||
type LeafListener struct {
|
||||
*BaseTListener
|
||||
}
|
||||
|
||||
func NewLeafListener() *LeafListener {
|
||||
l := new(LeafListener)
|
||||
l.BaseTListener = new(parser.BaseTListener)
|
||||
return l`
|
||||
l.BaseTListener = new(BaseTListener)
|
||||
return l
|
||||
}
|
||||
|
||||
func (this *LeafListener) ExitCall(ctx *parser.CallContext) {
|
||||
fmt.Printf("%s %s",ctx.e().GetStart().GetText(),ctx.eList());
|
||||
func (this *LeafListener) ExitCall(ctx *CallContext) {
|
||||
fmt.Printf("%s %s",ctx.E().GetStart().GetText(),ctx.EList());
|
||||
}
|
||||
|
||||
func (this *LeafListener) ExitInt(ctx *parser.IntContext) {
|
||||
func (this *LeafListener) ExitInt(ctx *IntContext) {
|
||||
fmt.Println(ctx.INT().GetSymbol().GetText());
|
||||
}
|
||||
>>
|
||||
|
@ -453,7 +453,7 @@ func pred(v bool) bool {
|
|||
}
|
||||
>>
|
||||
|
||||
Invoke_pred(v) ::= <<this.pred(<v>)>>
|
||||
Invoke_pred(v) ::= <<p.pred(<v>)>>
|
||||
|
||||
IgnoredTests ::= [
|
||||
default: false
|
||||
|
|
|
@ -12,19 +12,19 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(583);
|
||||
StringBuilder grammarBuilder = new StringBuilder(569);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("func LeafListener struct {\n");
|
||||
grammarBuilder.append(" *parser.BaseTListener\n");
|
||||
grammarBuilder.append("type LeafListener struct {\n");
|
||||
grammarBuilder.append(" *BaseTListener\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
|
@ -64,25 +64,25 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testLR() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(760);
|
||||
StringBuilder grammarBuilder = new StringBuilder(743);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("func LeafListener struct {\n");
|
||||
grammarBuilder.append(" *parser.BaseTListener\n");
|
||||
grammarBuilder.append("type LeafListener struct {\n");
|
||||
grammarBuilder.append(" *BaseTListener\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitE(ctx *parser.EContext) {\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitE(ctx *EContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==3) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\\n\",ctx.e(0).GetStart().GetText(), ctx.e(1).GetStart().GetText(), ctx.e().Get(0).GetStart().GetText());\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(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
|
@ -124,27 +124,27 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testLRWithLabels() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(763);
|
||||
StringBuilder grammarBuilder = new StringBuilder(734);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("func LeafListener struct {\n");
|
||||
grammarBuilder.append(" *parser.BaseTListener\n");
|
||||
grammarBuilder.append("type LeafListener struct {\n");
|
||||
grammarBuilder.append(" *BaseTListener\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
|
||||
grammarBuilder.append(" return l`\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitCall(ctx *parser.CallContext) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s\",ctx.e().GetStart().GetText(),ctx.eList());\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitCall(ctx *CallContext) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s\",ctx.E().GetStart().GetText(),ctx.EList());\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitInt(ctx *parser.IntContext) {\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitInt(ctx *IntContext) {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.INT().GetSymbol().GetText());\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -183,27 +183,27 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testRuleGetters_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(759);
|
||||
StringBuilder grammarBuilder = new StringBuilder(768);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("func LeafListener struct {\n");
|
||||
grammarBuilder.append(" *parser.BaseTListener\n");
|
||||
grammarBuilder.append("type LeafListener struct {\n");
|
||||
grammarBuilder.append(" *BaseTListener\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx parser.AContext) {\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.b(0).start.GetText(),ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());\n");
|
||||
grammarBuilder.append(" } else\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.b(0).start.GetText());\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(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText());\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -239,27 +239,27 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testRuleGetters_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(759);
|
||||
StringBuilder grammarBuilder = new StringBuilder(768);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("func LeafListener struct {\n");
|
||||
grammarBuilder.append(" *parser.BaseTListener\n");
|
||||
grammarBuilder.append("type LeafListener struct {\n");
|
||||
grammarBuilder.append(" *BaseTListener\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx parser.AContext) {\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2) {\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.b(0).start.GetText(),ctx.b(1).start.GetText(),ctx.b().Get(0).start.GetText());\n");
|
||||
grammarBuilder.append(" } else\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.b(0).start.GetText());\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(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.B(0)[0].GetStart().GetText());\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
|
@ -295,25 +295,25 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testTokenGetters_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(710);
|
||||
StringBuilder grammarBuilder = new StringBuilder(699);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("func LeafListener struct {\n");
|
||||
grammarBuilder.append(" *parser.BaseTListener\n");
|
||||
grammarBuilder.append("type LeafListener struct {\n");
|
||||
grammarBuilder.append(" *BaseTListener\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *parser.AContext) {\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2){\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(),ctx.INT());\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(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
|
@ -350,25 +350,25 @@ public class TestListeners extends BaseTest {
|
|||
@Test
|
||||
public void testTokenGetters_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(710);
|
||||
StringBuilder grammarBuilder = new StringBuilder(699);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@parser::header {\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("@parser::members {\n");
|
||||
grammarBuilder.append("func LeafListener struct {\n");
|
||||
grammarBuilder.append(" *parser.BaseTListener\n");
|
||||
grammarBuilder.append("type LeafListener struct {\n");
|
||||
grammarBuilder.append(" *BaseTListener\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func NewLeafListener() *LeafListener {\n");
|
||||
grammarBuilder.append(" l := new(LeafListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(parser.BaseTListener)\n");
|
||||
grammarBuilder.append(" l.BaseTListener = new(BaseTListener)\n");
|
||||
grammarBuilder.append(" return l\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *parser.AContext) {\n");
|
||||
grammarBuilder.append("func (this *LeafListener) ExitA(ctx *AContext) {\n");
|
||||
grammarBuilder.append(" if (ctx.GetChildCount()==2){\n");
|
||||
grammarBuilder.append(" fmt.Printf(\"%s %s %s\",ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(),ctx.INT());\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(" } else {\n");
|
||||
grammarBuilder.append(" fmt.Println(ctx.ID().GetSymbol())\n");
|
||||
grammarBuilder.append(" }\n");
|
||||
|
|
|
@ -584,11 +584,11 @@ public class TestParserExec extends BaseTest {
|
|||
@Test
|
||||
public void testParserProperty() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(157);
|
||||
StringBuilder grammarBuilder = new StringBuilder(161);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("bool Property() {\n");
|
||||
grammarBuilder.append(" return true;\n");
|
||||
grammarBuilder.append("func Property() bool {\n");
|
||||
grammarBuilder.append(" return true\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("a : {$parser.Property()}? ID {fmt.Println(\"valid\")}\n");
|
||||
|
|
|
@ -43,7 +43,7 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
|
||||
StringBuilder grammarBuilder = new StringBuilder(100);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("ENUM : [a-z]+ { l.GetText() == \"enum\" }? ;\n");
|
||||
grammarBuilder.append("ENUM : [a-z]+ { p.GetText() == \"enum\" }? ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
@ -113,10 +113,10 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
public void testIndent() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
|
||||
StringBuilder grammarBuilder = new StringBuilder(152);
|
||||
StringBuilder grammarBuilder = new StringBuilder(137);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("INDENT : [ \\t]+ { this.TokenStartCharPositionInLine==0 }?\n");
|
||||
grammarBuilder.append("INDENT : [ \\t]+ { p.TokenStartColumn==0 }?\n");
|
||||
grammarBuilder.append(" { fmt.Println(\"INDENT\") } ;\n");
|
||||
grammarBuilder.append("NL : '\\n';\n");
|
||||
grammarBuilder.append("WS : [ \\t]+ ;");
|
||||
|
@ -154,8 +154,8 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("WORD1 : ID1+ { fmt.Println(l.GetText()) } ;\n");
|
||||
grammarBuilder.append("WORD2 : ID2+ { fmt.Println(l.GetText()) } ;\n");
|
||||
grammarBuilder.append("fragment ID1 : { l.GetCharPositionInLine() < 2 }? [a-zA-Z];\n");
|
||||
grammarBuilder.append("fragment ID2 : { l.GetCharPositionInLine() >= 2 }? [a-zA-Z];\n");
|
||||
grammarBuilder.append("fragment ID1 : { p.GetCharPositionInLine() < 2 }? [a-zA-Z];\n");
|
||||
grammarBuilder.append("fragment ID2 : { p.GetCharPositionInLine() >= 2 }? [a-zA-Z];\n");
|
||||
grammarBuilder.append("WS : (' '|'\\n') -> skip;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
String input =
|
||||
|
@ -182,7 +182,7 @@ public class TestSemPredEvalLexer extends BaseTest {
|
|||
|
||||
StringBuilder grammarBuilder = new StringBuilder(160);
|
||||
grammarBuilder.append("lexer grammar L;\n");
|
||||
grammarBuilder.append("ENUM : [a-z]+ { l.GetText() == \"enum\" }? { fmt.Println(\"enum!\") } ;\n");
|
||||
grammarBuilder.append("ENUM : [a-z]+ { p.GetText() == \"enum\" }? { fmt.Println(\"enum!\") } ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ { fmt.Println(\"ID \" + l.GetText()) } ;\n");
|
||||
grammarBuilder.append("WS : [ \\n] -> skip ;");
|
||||
String grammar = grammarBuilder.toString();
|
||||
|
|
|
@ -74,12 +74,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testActionHidesPreds() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(243);
|
||||
StringBuilder grammarBuilder = new StringBuilder(223);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var i int = 0; var _ int = i; }\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");
|
||||
grammarBuilder.append("a : {i = 1;} ID {i == 1}? {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {i = 2;} ID {i == 2}? {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -100,7 +100,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testActionsHidePredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(285);
|
||||
StringBuilder grammarBuilder = new StringBuilder(279);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("func pred(v bool) bool {\n");
|
||||
|
@ -108,8 +108,8 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
grammarBuilder.append(" return v\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : e {} {this.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("t : e {} {this.pred(false)}? ID ;\n");
|
||||
grammarBuilder.append("s : e {} {p.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("t : e {} {p.pred(false)}? ID ;\n");
|
||||
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -148,7 +148,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testDepedentPredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(308);
|
||||
StringBuilder grammarBuilder = new StringBuilder(302);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("func pred(v bool) bool {\n");
|
||||
|
@ -157,8 +157,8 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : a[99] ;\n");
|
||||
grammarBuilder.append("a[int i] : e {this.pred($i==99)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("b[int i] : e {this.pred($i==99)}? ID ;\n");
|
||||
grammarBuilder.append("a[int i] : e {p.pred($i==99)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("b[int i] : e {p.pred($i==99)}? ID ;\n");
|
||||
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -352,12 +352,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredTestedEvenWhenUnAmbig_1() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(229);
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var enumKeyword bool= true; var _ bool = enumKeyword; }\n");
|
||||
grammarBuilder.append("primary\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
|
||||
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
grammarBuilder.append(" | {!enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;");
|
||||
|
@ -374,12 +374,12 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredTestedEvenWhenUnAmbig_2() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(229);
|
||||
StringBuilder grammarBuilder = new StringBuilder(224);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var enumKeyword bool= true; var _ bool = enumKeyword; }\n");
|
||||
grammarBuilder.append("primary\n");
|
||||
grammarBuilder.append(" : ID {fmt.Println(\"ID \"+$ID.text)}\n");
|
||||
grammarBuilder.append(" | {!this.enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
grammarBuilder.append(" | {!enumKeyword}? 'enum' {fmt.Println(\"enum\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : [a-z]+ ;\n");
|
||||
grammarBuilder.append("WS : [ \\t\\n\\r]+ -> skip ;");
|
||||
|
@ -447,7 +447,7 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testPredsInGlobalFOLLOW() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(279);
|
||||
StringBuilder grammarBuilder = new StringBuilder(273);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {\n");
|
||||
grammarBuilder.append("func pred(v bool) bool {\n");
|
||||
|
@ -455,8 +455,8 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
grammarBuilder.append(" return v\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("}\n");
|
||||
grammarBuilder.append("s : e {this.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("t : e {this.pred(false)}? ID ;\n");
|
||||
grammarBuilder.append("s : e {p.pred(true)}? {fmt.Println(\"parse\")} '!' ;\n");
|
||||
grammarBuilder.append("t : e {p.pred(false)}? ID ;\n");
|
||||
grammarBuilder.append("e : ID | ; // non-LL(1) so we use ATN\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
@ -599,13 +599,13 @@ public class TestSemPredEvalParser extends BaseTest {
|
|||
@Test
|
||||
public void testToLeftWithVaryingPredicate() throws Exception {
|
||||
mkdir(parserpkgdir);
|
||||
StringBuilder grammarBuilder = new StringBuilder(267);
|
||||
StringBuilder grammarBuilder = new StringBuilder(247);
|
||||
grammarBuilder.append("grammar T;\n");
|
||||
grammarBuilder.append("@members {var i int = 0; var _ int = i; }\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");
|
||||
grammarBuilder.append(" | {this.i % 2 != 0}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append("s : ({i += 1;\n");
|
||||
grammarBuilder.append("fmt.Println(\"i=\" + i)} a)+ ;\n");
|
||||
grammarBuilder.append("a : {i % 2 == 0}? ID {fmt.Println(\"alt 1\")}\n");
|
||||
grammarBuilder.append(" | {i % 2 != 0}? ID {fmt.Println(\"alt 2\")}\n");
|
||||
grammarBuilder.append(" ;\n");
|
||||
grammarBuilder.append("ID : 'a'..'z'+ ;\n");
|
||||
grammarBuilder.append("INT : '0'..'9'+;\n");
|
||||
|
|
|
@ -130,6 +130,10 @@ func (l *BaseLexer) reset() {
|
|||
l.Interpreter.reset()
|
||||
}
|
||||
|
||||
func (l *BaseLexer) GetInterpreter() *LexerATNSimulator {
|
||||
return l.Interpreter
|
||||
}
|
||||
|
||||
func (l *BaseLexer) GetInputStream() CharStream {
|
||||
return l._input
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ type LexerATNSimulator struct {
|
|||
|
||||
recog Lexer
|
||||
predictionMode int
|
||||
decisionToDFA []*DFA
|
||||
DecisionToDFA []*DFA
|
||||
mergeCache DoubleDict
|
||||
startIndex int
|
||||
line int
|
||||
|
@ -68,7 +68,7 @@ func NewLexerATNSimulator(recog Lexer, atn *ATN, decisionToDFA []*DFA, sharedCon
|
|||
|
||||
this.BaseATNSimulator = NewBaseATNSimulator(atn, sharedContextCache)
|
||||
|
||||
this.decisionToDFA = decisionToDFA
|
||||
this.DecisionToDFA = decisionToDFA
|
||||
this.recog = recog
|
||||
// The current token's starting index into the character stream.
|
||||
// Shared across DFA to ATN simulation in case the ATN fails and the
|
||||
|
@ -123,7 +123,7 @@ func (this *LexerATNSimulator) Match(input CharStream, mode int) int {
|
|||
this.startIndex = input.Index()
|
||||
this.prevAccept.reset()
|
||||
|
||||
var dfa = this.decisionToDFA[mode]
|
||||
var dfa = this.DecisionToDFA[mode]
|
||||
|
||||
if dfa.s0 == nil {
|
||||
if PortDebug {
|
||||
|
@ -160,13 +160,13 @@ func (this *LexerATNSimulator) MatchATN(input CharStream) int {
|
|||
var next = this.addDFAState(s0_closure.BaseATNConfigSet)
|
||||
|
||||
if !suppressEdge {
|
||||
this.decisionToDFA[this.mode].s0 = next
|
||||
this.DecisionToDFA[this.mode].s0 = next
|
||||
}
|
||||
|
||||
var predict = this.execATN(input, next)
|
||||
|
||||
if LexerATNSimulatorDebug {
|
||||
fmt.Println("DFA after MatchATN: " + this.decisionToDFA[old_mode].ToLexerString())
|
||||
fmt.Println("DFA after MatchATN: " + this.DecisionToDFA[old_mode].ToLexerString())
|
||||
}
|
||||
return predict
|
||||
}
|
||||
|
@ -639,7 +639,7 @@ func (this *LexerATNSimulator) addDFAState(configs ATNConfigSet) *DFAState {
|
|||
proposed.setPrediction(this.atn.ruleToTokenType[firstConfigWithRuleStopState.GetState().GetRuleIndex()])
|
||||
}
|
||||
var hash = proposed.Hash()
|
||||
var dfa = this.decisionToDFA[this.mode]
|
||||
var dfa = this.DecisionToDFA[this.mode]
|
||||
var existing = dfa.GetStates()[hash]
|
||||
if existing != nil {
|
||||
return existing
|
||||
|
@ -653,7 +653,7 @@ func (this *LexerATNSimulator) addDFAState(configs ATNConfigSet) *DFAState {
|
|||
}
|
||||
|
||||
func (this *LexerATNSimulator) getDFA(mode int) *DFA {
|
||||
return this.decisionToDFA[mode]
|
||||
return this.DecisionToDFA[mode]
|
||||
}
|
||||
|
||||
// Get the text Matched so far for the current token.
|
||||
|
|
|
@ -678,13 +678,13 @@ func (this *BaseParser) GetRuleInvocationStack(p ParserRuleContext) []string {
|
|||
|
||||
// For debugging and other purposes.//
|
||||
func (p *BaseParser) GetDFAStrings() string {
|
||||
return fmt.Sprint(p.Interpreter.decisionToDFA)
|
||||
return fmt.Sprint(p.Interpreter.DecisionToDFA)
|
||||
}
|
||||
|
||||
// For debugging and other purposes.//
|
||||
func (p *BaseParser) DumpDFA() {
|
||||
var seenOne = false
|
||||
for _, dfa := range p.Interpreter.decisionToDFA {
|
||||
for _, dfa := range p.Interpreter.DecisionToDFA {
|
||||
if ( len(dfa.GetStates()) > 0) {
|
||||
if (seenOne) {
|
||||
fmt.Println()
|
||||
|
|
|
@ -14,7 +14,7 @@ type ParserATNSimulator struct {
|
|||
_input TokenStream
|
||||
_startIndex int
|
||||
_dfa *DFA
|
||||
decisionToDFA []*DFA
|
||||
DecisionToDFA []*DFA
|
||||
mergeCache *DoubleDict
|
||||
_outerContext ParserRuleContext
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ func NewParserATNSimulator(parser Parser, atn *ATN, decisionToDFA []*DFA, shared
|
|||
this.BaseATNSimulator = NewBaseATNSimulator(atn, sharedContextCache)
|
||||
|
||||
this.parser = parser
|
||||
this.decisionToDFA = decisionToDFA
|
||||
this.DecisionToDFA = decisionToDFA
|
||||
// SLL, LL, or LL + exact ambig detection?//
|
||||
this.predictionMode = PredictionModeLL
|
||||
// LAME globals to avoid parameters!!!!! I need these down deep in predTransition
|
||||
|
@ -81,7 +81,7 @@ func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int,
|
|||
this._startIndex = input.Index()
|
||||
this._outerContext = outerContext
|
||||
|
||||
var dfa = this.decisionToDFA[decision]
|
||||
var dfa = this.DecisionToDFA[decision]
|
||||
this._dfa = dfa
|
||||
var m = input.Mark()
|
||||
var index = input.Index()
|
||||
|
|
|
@ -236,25 +236,47 @@ func (prc *BaseParserRuleContext) GetPayload() interface{}{
|
|||
return prc
|
||||
}
|
||||
|
||||
func (prc *BaseParserRuleContext) GetTypedRuleContext(ctxType reflect.Type, i int) interface{} {
|
||||
panic("GetTypedRuleContexts not implemented")
|
||||
// return prc.getChild(i, ctxType)
|
||||
func (prc *BaseParserRuleContext) getChild(ctxType reflect.Type, i int) RuleContext {
|
||||
if ( prc.children==nil || i < 0 || i >= len(prc.children) ) {
|
||||
return nil
|
||||
}
|
||||
|
||||
var j int = -1 // what element have we found with ctxType?
|
||||
for _,o := range prc.children {
|
||||
|
||||
childType := reflect.TypeOf(o)
|
||||
|
||||
if ( childType.ConvertibleTo(ctxType) ) {
|
||||
j++
|
||||
if ( j == i ) {
|
||||
return o.(RuleContext)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
// Go lacks generics, so it's not possible for us to return the child with the correct type, but we do
|
||||
// check for convertibility
|
||||
|
||||
func (prc *BaseParserRuleContext) GetTypedRuleContext(ctxType reflect.Type, i int) RuleContext {
|
||||
return prc.getChild(ctxType, i)
|
||||
}
|
||||
|
||||
func (prc *BaseParserRuleContext) GetTypedRuleContexts(ctxType reflect.Type) []interface{} {
|
||||
panic("GetTypedRuleContexts not implemented")
|
||||
// if (prc.children== nil) {
|
||||
// return []
|
||||
// } else {
|
||||
// var contexts = []
|
||||
// for(var j=0 j<len(prc.children) j++) {
|
||||
// var child = prc.children[j]
|
||||
// if _, ok := child.(ctxType); ok {
|
||||
// contexts.push(child)
|
||||
// }
|
||||
// }
|
||||
// return contexts
|
||||
// }
|
||||
func (prc *BaseParserRuleContext) GetTypedRuleContexts(ctxType reflect.Type) []RuleContext {
|
||||
if prc.children == nil {
|
||||
return make([]RuleContext, 0)
|
||||
}
|
||||
|
||||
var contexts = make([]RuleContext, 0)
|
||||
|
||||
for _,child := range prc.children {
|
||||
childType := reflect.TypeOf(child)
|
||||
|
||||
if childType.ConvertibleTo(ctxType) {
|
||||
contexts = append(contexts, child.(RuleContext))
|
||||
}
|
||||
}
|
||||
return contexts
|
||||
}
|
||||
|
||||
func (prc *BaseParserRuleContext) GetChildCount() int {
|
||||
|
|
|
@ -114,7 +114,7 @@ func (v *Base<file.grammarName>Visitor) Visit<lname; format="cap">(ctx *<lname;
|
|||
Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
|
||||
|
||||
<if(superClass)>
|
||||
var <superClass> = require('./<superClass>').<superClass> // TODO
|
||||
// TODO var <superClass> = require('./<superClass>').<superClass>
|
||||
<endif>
|
||||
|
||||
var parserATN = <atn>
|
||||
|
@ -138,17 +138,17 @@ func New<parser.name>(input antlr4.TokenStream) *<parser.name> {
|
|||
decisionToDFA[index] = antlr4.NewDFA(ds, index)
|
||||
}
|
||||
|
||||
parser := new(<parser.name>)
|
||||
this := new(<parser.name>)
|
||||
|
||||
parser.BaseParser = antlr4.NewBaseParser(input)
|
||||
this.BaseParser = antlr4.NewBaseParser(input)
|
||||
|
||||
parser.Interpreter = antlr4.NewParserATNSimulator(parser, deserializedATN, decisionToDFA, sharedContextCache)
|
||||
parser.RuleNames = ruleNames
|
||||
parser.LiteralNames = literalNames
|
||||
parser.SymbolicNames = symbolicNames
|
||||
parser.GrammarFileName = "<parser.grammarFileName; format="java-escape">"
|
||||
this.Interpreter = antlr4.NewParserATNSimulator(this, deserializedATN, decisionToDFA, sharedContextCache)
|
||||
this.RuleNames = ruleNames
|
||||
this.LiteralNames = literalNames
|
||||
this.SymbolicNames = symbolicNames
|
||||
this.GrammarFileName = "<parser.grammarFileName; format="java-escape">"
|
||||
|
||||
return parser
|
||||
return this
|
||||
}
|
||||
|
||||
<namedActions.members>
|
||||
|
@ -187,13 +187,13 @@ dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
|
|||
<if(actionFuncs)>
|
||||
func (l *<lexer.name>) Action(localctx antlr4.RuleContext, ruleIndex, actionIndex int) {
|
||||
switch ruleIndex {
|
||||
<recog.actionFuncs.values:{f| case <f.ruleIndex>:
|
||||
<recog.actionFuncs.values:{f|case <f.ruleIndex>:
|
||||
<if(!f.isRuleContext)>
|
||||
var t *<f.name; format="cap">Context = nil
|
||||
if localctx != nil { t = localctx.(*<f.ctxType>) \}
|
||||
return l.<f.name>_Action(t, actionIndex)
|
||||
l.<f.name>_Action(t, actionIndex)
|
||||
<else>
|
||||
return l.<f.name>_Action(t, actionIndex)
|
||||
l.<f.name>_Action(localctx, actionIndex)
|
||||
<endif>}; separator="\n">
|
||||
default:
|
||||
panic("No registered action for:" + fmt.Sprint(ruleIndex))
|
||||
|
@ -211,7 +211,7 @@ func (l *<lexer.name>) Sempred(localctx antlr4.RuleContext, ruleIndex, predIndex
|
|||
if localctx != nil { t = localctx.(*<f.ctxType>) \}
|
||||
return l.<f.name>_Sempred(t, predIndex);
|
||||
<else>
|
||||
return l.<f.name>_Sempred(t, predIndex);
|
||||
return l.<f.name>_Sempred(localctx, predIndex);
|
||||
<endif>}; separator="\n">
|
||||
default:
|
||||
panic("No registered predicate for:" + fmt.Sprint(ruleIndex))
|
||||
|
@ -244,7 +244,7 @@ case <index>:
|
|||
* overriding implementation impossible to maintain.
|
||||
*/
|
||||
RuleSempredFunction(r, actions) ::= <<
|
||||
func (p *<if(parser)><parser.name><else><lexer.name><endif>) <r.name; format="cap">_Sempred(localctx <if(r.isRuleContext)>antlr4.RuleContext<else>*<r.ctxType><endif>, predIndex int) bool {
|
||||
func (p *<if(parser)><parser.name><else><lexer.name><endif>) <r.name; format="cap">_Sempred(localctx antlr4.RuleContext, predIndex int) bool {
|
||||
switch predIndex {
|
||||
<actions:{index| case <index>:
|
||||
return <actions.(index)>;}; separator="\n">
|
||||
|
@ -252,11 +252,8 @@ func (p *<if(parser)><parser.name><else><lexer.name><endif>) <r.name; format="ca
|
|||
panic("No predicate with index:" + fmt.Sprint(predIndex))
|
||||
}
|
||||
}
|
||||
|
||||
>>
|
||||
|
||||
|
||||
|
||||
RuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,namedActions,finallyAction,postamble,exceptions) ::= <<
|
||||
|
||||
<ruleCtx>
|
||||
|
@ -610,7 +607,7 @@ RulePropertyRef_parser(r) ::= "p"
|
|||
ThisRulePropertyRef_start(r) ::= "localctx.GetStart()"
|
||||
ThisRulePropertyRef_stop(r) ::= "localctx.GetStop()"
|
||||
ThisRulePropertyRef_text(r) ::= "p.GetTokenStream().GetTextFromInterval(antlr4.NewInterval(localctx.GetStart().GetTokenIndex(), p.GetTokenStream().LT(-1).GetTokenIndex()))"
|
||||
ThisRulePropertyRef_ctx(r) ::= "localctx"
|
||||
ThisRulePropertyRef_ctx(r) ::= "<ctx(r)>"
|
||||
ThisRulePropertyRef_parser(r) ::= "p"
|
||||
|
||||
NonLocalAttrRef(s) ::= "GetInvokingContext(<s.ruleIndex>).<s.name>"
|
||||
|
@ -620,7 +617,7 @@ AddToLabelList(a) ::= "<ctx(a.label)>.<a.listName> = append(<ctx(a.label)>.<a.li
|
|||
|
||||
TokenDecl(t) ::= "<t.name> <TokenLabelType()>"
|
||||
TokenTypeDecl(t) ::= "<t.name> int"
|
||||
TokenListDecl(t) ::= "<t.name> antlr4.Token[]"
|
||||
TokenListDecl(t) ::= "<t.name> []antlr4.Token"
|
||||
|
||||
RuleContextDecl(r) ::= "<r.name> I<r.ctxName>"
|
||||
RuleContextListDecl(rdecl) ::= "<rdecl.name> []I<rdecl.ctxName>"
|
||||
|
@ -628,47 +625,53 @@ RuleContextListDecl(rdecl) ::= "<rdecl.name> []I<rdecl.ctxName>"
|
|||
AttributeDecl(d) ::= "<d.name> <d.type;format={lower}><if(d.initValue)>// TODO = <d.initValue><endif>"
|
||||
|
||||
ContextTokenGetterDecl(t) ::= <<
|
||||
<t.name; format="cap">() interface{} {
|
||||
<t.name; format="cap">() antlr4.TerminalNode {
|
||||
return s.GetToken(<parser.name><t.name>, 0)
|
||||
}
|
||||
>>
|
||||
|
||||
// should never be called
|
||||
ContextTokenListGetterDecl(t) ::= <<
|
||||
def <t.name>_list(self):
|
||||
return self.GetTokens(<parser.name><t.name>)
|
||||
fail: ContextTokenListGetterDecl should never be called!
|
||||
>>
|
||||
|
||||
ContextTokenListIndexedGetterDecl(t) ::= <<
|
||||
<t.name; format="cap">(i int) interface{} {
|
||||
<t.name; format="cap">(i int) []antlr4.TerminalNode {
|
||||
if i \< 0 {
|
||||
return s.GetTokens(<parser.name><t.name>)
|
||||
} else {
|
||||
return s.GetToken(<parser.name><t.name>, i)
|
||||
return []antlr4.TerminalNode{ s.GetToken(<parser.name><t.name>, i) }
|
||||
}
|
||||
}
|
||||
>>
|
||||
|
||||
ContextRuleGetterDecl(r) ::= <<
|
||||
<r.name; format="cap">() interface{} {
|
||||
return s.GetTypedRuleContext(reflect.TypeOf((*<r.ctxName>)(nil)).Elem(),0)
|
||||
<r.name; format="cap">() *<r.ctxName> {
|
||||
return s.GetTypedRuleContext(reflect.TypeOf((*<r.ctxName>)(nil)).Elem(),0).(*<r.ctxName>)
|
||||
}
|
||||
>>
|
||||
|
||||
// should never be called
|
||||
ContextRuleListGetterDecl(r) ::= <<
|
||||
func <r.name; format="cap">_list(self):
|
||||
return s.GetTypedRuleContexts(reflect.TypeOf((*<r.ctxName>)(nil)).Elem())
|
||||
|
||||
fail: ContextRuleListGetterDecl should never be called!
|
||||
>>
|
||||
|
||||
ContextRuleListIndexedGetterDecl(r) ::= <<
|
||||
<r.name; format="cap">(i int) interface{} {
|
||||
<r.name; format="cap">(i int) []*<r.ctxName> {
|
||||
var ts []antlr4.RuleContext;
|
||||
|
||||
if i \< 0 {
|
||||
return s.GetTypedRuleContexts(reflect.TypeOf((*<r.ctxName>)(nil)).Elem())
|
||||
ts = s.GetTypedRuleContexts( reflect.PtrTo( reflect.TypeOf((*<r.ctxName>)(nil)).Elem() ))
|
||||
} else {
|
||||
return s.GetTypedRuleContext(reflect.TypeOf((*<r.ctxName>)(nil)).Elem(),i)
|
||||
ts = []antlr4.RuleContext { s.GetTypedRuleContext( reflect.PtrTo( reflect.TypeOf((*<r.ctxName>)(nil)).Elem() ),i) }
|
||||
}
|
||||
|
||||
var tst []*<r.ctxName> = make([]*<r.ctxName>, len(ts))
|
||||
for i, t := range ts {
|
||||
tst[i] = t.(*<r.ctxName>)
|
||||
}
|
||||
|
||||
return tst
|
||||
}
|
||||
>>
|
||||
|
||||
|
@ -918,20 +921,20 @@ func New<lexer.name>(input antlr4.CharStream) *<lexer.name> {
|
|||
lexerDecisionToDFA[index] = antlr4.NewDFA(ds, index)
|
||||
}
|
||||
|
||||
lex := new(<lexer.name>)
|
||||
this := new(<lexer.name>)
|
||||
|
||||
lex.BaseLexer = antlr4.NewBaseLexer(input)
|
||||
this.BaseLexer = antlr4.NewBaseLexer(input)
|
||||
|
||||
lex.Interpreter = antlr4.NewLexerATNSimulator(lex, lexerAtn, lexerDecisionToDFA, antlr4.NewPredictionContextCache())
|
||||
this.Interpreter = antlr4.NewLexerATNSimulator(this, lexerAtn, lexerDecisionToDFA, antlr4.NewPredictionContextCache())
|
||||
|
||||
lex.modeNames = lexerModeNames
|
||||
lex.RuleNames = lexerRuleNames
|
||||
lex.LiteralNames = lexerLiteralNames
|
||||
lex.SymbolicNames = lexerSymbolicNames
|
||||
lex.GrammarFileName = "<lexer.grammarFileName>"
|
||||
this.modeNames = lexerModeNames
|
||||
this.RuleNames = lexerRuleNames
|
||||
this.LiteralNames = lexerLiteralNames
|
||||
this.SymbolicNames = lexerSymbolicNames
|
||||
this.GrammarFileName = "<lexer.grammarFileName>"
|
||||
//lex.EOF = antlr4.TokenEOF
|
||||
|
||||
return lex
|
||||
return this
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -942,7 +945,6 @@ const (
|
|||
<rest(lexer.modes):{m| <lexer.name><m> = <i>}; separator="\n">
|
||||
)
|
||||
|
||||
<namedActions.members>
|
||||
|
||||
<dumpActions(lexer, "", actionFuncs, sempredFuncs)>
|
||||
|
||||
|
|
Loading…
Reference in New Issue