Skip to content

Commit

Permalink
Initialize locals with init value - fixes #22
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Mar 18, 2015
1 parent e4c7bd4 commit 13e0fdc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def accept(self, visitor:ParseTreeVisitor):

>>

AttributeDecl(d) ::= "self.<d.name> = None"
AttributeDecl(d) ::= "self.<d.name> = <if(d.initValue)><d.initValue><else>None<endif>"

/** If we don't know location of label def x, use this template */
labelref(x) ::= "<if(!x.isLocal)>localctx.<endif><x.name>"
Expand Down
10 changes: 10 additions & 0 deletions tool/test/org/antlr/v4/test/rt/py3/TestParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,15 @@ public void testParamList() throws Exception {
assertEquals("a\n", found);
assertNull(this.stderrDuringParse);
}

@Test
public void testParamInit() throws Exception {
String grammar = "grammar T;\n" +
"a locals[i=23]: 'a' {print(str($i))} ;";
String found = execParser("T.g4", grammar, "TParser", "TLexer", "TListener", "TVisitor", "a", "a", false);
assertEquals("23\n", found);
assertNull(this.stderrDuringParse);
}


}

0 comments on commit 13e0fdc

Please sign in to comment.