[antlr-interest] Bug Report: Composite Grammar does not delegate Lexer methods (like mLETTER)
George S. Cowan
cowang at comcast.net
Tue Dec 30 07:16:32 PST 2008
The generated lexer for composite grammars does not generate the delegation
methods for lexer rules in the topmost grammar. This is only a problem if
one is directly calling the lexer methods, for instance, in unit testing
and, in particular, testing lexer rules in gUnit.
Here is the example grammar from the Composite Grammar page (
<http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars>
http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars) with slight
modifications so it will work:
-------------------- begin L.g --------------
lexer grammar L ;
LETTER : 'a'..'z' ;
---- begin P1.g ---
parser grammar P1 ;
letter : LETTER ;
spaces : ' '+ ;
--- begin P2.g ---
parser grammar P2 ;
import P1 ;
letters : letter+ ;
--------- begin C.g ---------
grammar C ;
import L, P2 ;
stuff : ( letters spaces )+ ;
--------- end grammar files ------------
Here is the gUnit test file and the exception:
------ CTest.testsuite -----
gunit C;
LETTER
: "a" OK
"A" FAIL
------------------------ runtime exception -------------------------------
java.lang.NoSuchMethodException: CLexer.mLETTER()
at java.lang.Class.getMethod(Unknown Source)
at org.antlr.gunit.gUnitExecuter.runLexer(gUnitExecuter.java:211)
at
org.antlr.gunit.gUnitExecuter.runCorrectParser(gUnitExecuter.java:131)
at
org.antlr.gunit.gUnitExecuter.executeTests(gUnitExecuter.java:149)
at org.antlr.gunit.gUnitExecuter.execTest(gUnitExecuter.java:97)
at org.antlr.gunit.Interp.main(Interp.java:62)
------------------------ END
--------------------------------------------------
I ran my tests on Windows XP SP3 using the following command lines:
del /Q work\*
java -cp C:\Java\ANTLR\antlr-3.1.1.jar org.antlr.Tool -o work C.g.
cd work
javac -cp C:\Java\ANTLR\antlr-3.1.1.jar;. *.java
java -cp C:\Java\ANTLR\gunit-1.0.4.jar;C:\Java\ANTLR\antlr-3.1.1.jar;.
org.antlr.gunit.Interp ..\CTest.testsuite
Thanks for ANTLR. I'm looking forward to making some real progress in my
language work.
Regards,
George
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081230/c3b515f0/attachment.html
More information about the antlr-interest
mailing list