resolved the Lexer listener/visitor issue by changing the tests grammar

using @members to @parser::members
This commit is contained in:
ericvergnaud 2014-06-06 23:41:18 +08:00
parent c46acf0031
commit 4545a8f5d0
4 changed files with 13 additions and 20 deletions

View File

@ -41,9 +41,6 @@ public class LexerFile extends OutputFile {
public String genPackage; // from -package cmd-line
@ModelElement public Lexer lexer;
@ModelElement public Map<String, Action> namedActions;
public Boolean genListener = false;
public Boolean genVisitor = false;
public String grammarName;
public LexerFile(OutputModelFactory factory, String fileName) {
super(factory, fileName);
@ -54,9 +51,5 @@ public class LexerFile extends OutputFile {
namedActions.put(name, new Action(factory, ast));
}
genPackage = factory.getGrammar().tool.genPackage;
// need the below members in the ST for Python
genListener = g.tool.gen_listener;
genVisitor = g.tool.gen_visitor;
grammarName = g.originalGrammar==null ? g.name : g.originalGrammar.name;
}
}

View File

@ -116,7 +116,7 @@ public class TestCompositeGrammars extends BaseTest {
@Test public void testDelegatorAccessesDelegateMembers() throws Exception {
String slave =
"parser grammar S;\n" +
"@members {\n" +
"@parser::members {\n" +
" public void foo() {System.out.println(\"foo\");}\n" +
"}\n" +
"a : B ;\n";

View File

@ -39,7 +39,7 @@ public class TestListeners extends BaseTest {
String grammar =
"grammar T;\n" +
"@header {import org.antlr.v4.runtime.tree.*;}\n"+
"@members {\n" +
"@parser::members {\n" +
"public static class LeafListener extends TBaseListener {\n" +
" public void visitTerminal(TerminalNode node) {\n" +
" System.out.println(node.getSymbol().getText());\n" +
@ -70,7 +70,7 @@ public class TestListeners extends BaseTest {
@Test public void testTokenGetters() throws Exception {
String grammar =
"grammar T;\n" +
"@members {\n" +
"@parser::members {\n" +
"public static class LeafListener extends TBaseListener {\n" +
" public void exitA(TParser.AContext ctx) {\n" +
" if (ctx.getChildCount()==2) System.out.printf(\"%s %s %s\",ctx.INT(0).getSymbol().getText(),ctx.INT(1).getSymbol().getText(),ctx.INT());\n" +
@ -107,7 +107,7 @@ public class TestListeners extends BaseTest {
@Test public void testRuleGetters() throws Exception {
String grammar =
"grammar T;\n" +
"@members {\n" +
"@parser::members {\n" +
"public static class LeafListener extends TBaseListener {\n" +
" public void exitA(TParser.AContext ctx) {\n" +
" if (ctx.getChildCount()==2) {\n" +
@ -147,7 +147,7 @@ public class TestListeners extends BaseTest {
@Test public void testLR() throws Exception {
String grammar =
"grammar T;\n" +
"@members {\n" +
"@parser::members {\n" +
"public static class LeafListener extends TBaseListener {\n" +
" public void exitE(TParser.EContext ctx) {\n" +
" if (ctx.getChildCount()==3) {\n" +
@ -188,7 +188,7 @@ public class TestListeners extends BaseTest {
@Test public void testLRWithLabels() throws Exception {
String grammar =
"grammar T;\n" +
"@members {\n" +
"@parser::members {\n" +
" public static class LeafListener extends TBaseListener {\n" +
" public void exitCall(TParser.CallContext ctx) {\n" +
" System.out.printf(\"%s %s\",ctx.e().start.getText(),\n" +

View File

@ -327,7 +327,7 @@ public class TestSemPredEvalParser extends BaseTest {
// can't see preds, resolves to first alt found (1 in this case)
String grammar =
"grammar T;\n" +
"@members {int i;}\n" +
"@parser::members {int i;}\n" +
"s : a+ ;\n" +
"a : {i=1;} ID {i==1}? {System.out.println(\"alt 1\");}\n" +
" | {i=2;} ID {i==2}? {System.out.println(\"alt 2\");}\n" +
@ -353,7 +353,7 @@ public class TestSemPredEvalParser extends BaseTest {
@Test public void testToLeftWithVaryingPredicate() throws Exception {
String grammar =
"grammar T;\n" +
"@members {int i=0;}\n" +
"@parser::members {int i=0;}\n" +
"s : ({i++; System.out.println(\"i=\"+i);} a)+ ;\n" +
"a : {i % 2 == 0}? ID {System.out.println(\"alt 1\");}\n" +
" | {i % 2 != 0}? ID {System.out.println(\"alt 2\");}\n" +
@ -383,7 +383,7 @@ public class TestSemPredEvalParser extends BaseTest {
@Test public void testPredicateDependentOnArg() throws Exception {
String grammar =
"grammar T;\n" +
"@members {int i=0;}\n" +
"@parser::members {int i=0;}\n" +
"s : a[2] a[1];\n" +
"a[int i]" +
" : {$i==1}? ID {System.out.println(\"alt 1\");}\n" +
@ -477,7 +477,7 @@ public class TestSemPredEvalParser extends BaseTest {
@Test public void testPredsInGlobalFOLLOW() throws Exception {
String grammar =
"grammar T;\n" +
"@members {" +
"@parser::members {" +
"void f(Object s) {System.out.println(s);}\n" +
"boolean p(boolean v) {System.out.println(\"eval=\"+v); return v;}\n" +
"}\n" +
@ -502,7 +502,7 @@ public class TestSemPredEvalParser extends BaseTest {
@Test public void testDepedentPredsInGlobalFOLLOW() throws Exception {
String grammar =
"grammar T;\n" +
"@members {" +
"@parser::members {" +
"void f(Object s) {System.out.println(s);}\n" +
"boolean p(boolean v) {System.out.println(\"eval=\"+v); return v;}\n" +
"}\n" +
@ -530,7 +530,7 @@ public class TestSemPredEvalParser extends BaseTest {
@Test public void testActionsHidePredsInGlobalFOLLOW() throws Exception {
String grammar =
"grammar T;\n" +
"@members {" +
"@parser::members {" +
"void f(Object s) {System.out.println(s);}\n" +
"boolean p(boolean v) {System.out.println(\"eval=\"+v); return v;}\n" +
"}\n" +
@ -553,7 +553,7 @@ public class TestSemPredEvalParser extends BaseTest {
String grammar =
"grammar T;\n" +
"\n" +
"@members {boolean enumKeyword = true;}\n" +
"@parser::members {boolean enumKeyword = true;}\n" +
"\n" +
"primary\n" +
" : ID {System.out.println(\"ID \"+$ID.text);}\n" +