From 4545a8f5d079ecf4691df8c9a9b0b6b5fb02f7c1 Mon Sep 17 00:00:00 2001 From: ericvergnaud Date: Fri, 6 Jun 2014 23:41:18 +0800 Subject: [PATCH] resolved the Lexer listener/visitor issue by changing the tests grammar using @members to @parser::members --- tool/src/org/antlr/v4/codegen/model/LexerFile.java | 7 ------- .../org/antlr/v4/test/TestCompositeGrammars.java | 2 +- tool/test/org/antlr/v4/test/TestListeners.java | 10 +++++----- .../org/antlr/v4/test/TestSemPredEvalParser.java | 14 +++++++------- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/tool/src/org/antlr/v4/codegen/model/LexerFile.java b/tool/src/org/antlr/v4/codegen/model/LexerFile.java index 815b6ec01..8bec073f4 100644 --- a/tool/src/org/antlr/v4/codegen/model/LexerFile.java +++ b/tool/src/org/antlr/v4/codegen/model/LexerFile.java @@ -41,9 +41,6 @@ public class LexerFile extends OutputFile { public String genPackage; // from -package cmd-line @ModelElement public Lexer lexer; @ModelElement public Map 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; } } diff --git a/tool/test/org/antlr/v4/test/TestCompositeGrammars.java b/tool/test/org/antlr/v4/test/TestCompositeGrammars.java index 803ce0d33..63174b438 100644 --- a/tool/test/org/antlr/v4/test/TestCompositeGrammars.java +++ b/tool/test/org/antlr/v4/test/TestCompositeGrammars.java @@ -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"; diff --git a/tool/test/org/antlr/v4/test/TestListeners.java b/tool/test/org/antlr/v4/test/TestListeners.java index 710cd4c65..887e3ca66 100644 --- a/tool/test/org/antlr/v4/test/TestListeners.java +++ b/tool/test/org/antlr/v4/test/TestListeners.java @@ -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" + diff --git a/tool/test/org/antlr/v4/test/TestSemPredEvalParser.java b/tool/test/org/antlr/v4/test/TestSemPredEvalParser.java index 7c3be0d9b..c3e11688e 100644 --- a/tool/test/org/antlr/v4/test/TestSemPredEvalParser.java +++ b/tool/test/org/antlr/v4/test/TestSemPredEvalParser.java @@ -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" +