[antlr-interest] Bug Report: Composite Grammar does not delegate Lexer methods (like mLETTER)

Terence Parr parrt at cs.usfca.edu
Tue Dec 30 10:56:43 PST 2008


Hi. you'll have to call the lexer methods directly on the generated  
lexer not using delegates I think
Ter
On Dec 30, 2008, at 7:16 AM, George S. Cowan wrote:

> 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 
> ) 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
>
>
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list