<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.6000.16788" name=GENERATOR></HEAD>
<BODY>
<DIV><EM><SPAN class=853354317-01012009>On </SPAN>Tue Dec 30<SPAN
class=853354317-01012009>, 2008, at 10:56 PST, Terrence Parr
wrote</SPAN></EM></DIV>
<DIV><FONT face="Lucida Console"><FONT size=2><FONT face=Arial><SPAN
class=853354317-01012009>> </SPAN>Hi. you'll have to call the lexer methods
directly on the generated <BR><SPAN class=853354317-01012009>>
</SPAN>lexer not using delegates I think</FONT></FONT></FONT></DIV>
<DIV><FONT face="Lucida Console"><FONT size=2><FONT
face=Arial></FONT></FONT></FONT> </DIV>
<DIV><FONT face="Lucida Console"><SPAN class=853354317-01012009><FONT face=Arial
size=2>As it turns out, I can insert the delegates myself as a
workaround</FONT></SPAN></FONT><FONT face="Lucida Console"><SPAN
class=853354317-01012009><FONT face=Arial size=2>.</FONT></SPAN></FONT></DIV>
<DIV><FONT face="Lucida Console"><SPAN
class=853354317-01012009></SPAN> </DIV>
<DIV><FONT size=2><FONT face=Arial><I>--------- begin C.g
---------<BR></I></FONT><FONT face=Arial><I>grammar C ;<BR></I></FONT><FONT
face=Arial><I>import L, P2 ;</I></FONT></FONT></DIV>
<DIV><BR><EM><FONT face=Arial size=2>@lexer::members {<BR> public final
void mLETTER() throws RecognitionException { gL.mLETTER();
}<BR>}</FONT></EM></DIV>
<DIV><BR><FONT face=Arial><FONT size=2><I>stuff : ( letters spaces )+
;<BR></I></FONT></FONT><FONT size=2><I><FONT face=Arial>--------- end <SPAN
class=853354317-01012009>C.g </SPAN>------------</FONT></I></FONT></DIV>
<DIV><FONT size=2><FONT face=Arial></FONT></FONT> </DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial size=2>This is a pain for a
large grammar, but it will only have to be done once (assuming all my
new development is happening at the top level, and there are no lexicon updates
coming in at the bottom levels). I can find the name of the delegates, e.g.,
"gL", in my CLexer.java file. I can find the method signature lines, e.g.
"<EM>public final void mLETTER() throws RecognitionException</EM>", in my
C_L.java file. Of course, if I override a lexer rule, I have to remove the
delegator, but if I forget, I get a reminder from the Java
compiler:</FONT></SPAN></DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial size=2>------------- begin
Java compile error message ----------</FONT></SPAN></DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial size=2>CLexer.java:52:
mLETTER() is already defined in CLexer<BR> public final void
mLETTER() throws RecognitionException
{<BR>
^<BR>CLexer.java:14: cannot find symbol<BR>symbol : method
mLETTER()<BR>location: class C_L<BR> public final
void mLETTER() throws RecognitionException { gL.mLETTER(); }</FONT></SPAN></DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial size=2>------------ end
Java compile error message ----------</FONT></SPAN></DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial size=2>This should work.
But I hope the next release automates the delegation for the
lexer.</FONT></SPAN></DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial
size=2>George</FONT></SPAN></DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=853354317-01012009><FONT face=Arial
size=2>--------------------------- begin original message
----------------------------------------</FONT></SPAN></DIV>
<DIV></FONT><FONT face=Arial size=2>Hi. you'll have to call the lexer methods
directly on the generated <BR>lexer not using delegates I
think<BR>Ter<BR>On Dec 30, 2008, at 7:16 AM, George S. Cowan
wrote:<BR><BR>><I> The generated lexer for composite grammars does not
generate the <BR></I>><I> delegation methods for lexer rules in the
topmost grammar. This is <BR></I>><I> only a problem if one is directly
calling the lexer methods, for <BR></I>><I> instance, in unit testing
and, in particular, testing lexer rules in <BR></I>><I>
gUnit.<BR></I>><I><BR></I>><I> Here is the example grammar from the
Composite Grammar page (<A
href="http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars">http://www.antlr.org/wiki/display/ANTLR3/Composite+Grammars</A>
<BR></I>><I> ) with slight modifications so it will
work:<BR></I>><I><BR></I>><I> -------------------- begin L.g
--------------<BR></I>><I> lexer grammar L ;<BR></I>><I> LETTER : 'a'..'z'
;<BR></I>><I> ---- begin P1.g ---<BR></I>><I> parser grammar P1
;<BR></I>><I> letter : LETTER ;<BR></I>><I> spaces : ' '+ ;<BR></I>><I>
--- begin P2.g ---<BR></I>><I> parser grammar P2 ;<BR></I>><I> import P1
;<BR></I>><I> letters : letter+ ;<BR></I>><I> --------- begin C.g
---------<BR></I>><I> grammar C ;<BR></I>><I> import L, P2
;<BR></I>><I> stuff : ( letters spaces )+ ;<BR></I>><I> --------- end
grammar files ------------<BR></I>><I><BR></I>><I> Here is the gUnit test
file and the exception:<BR></I>><I> ------ CTest.testsuite
-----<BR></I>><I> gunit C;<BR></I>><I> LETTER<BR></I>><I> :
"a" OK<BR></I>><I> "A"
FAIL<BR></I>><I> ------------------------ runtime exception
<BR></I>><I> -------------------------------<BR></I>><I>
java.lang.NoSuchMethodException:
CLexer.mLETTER()<BR></I>><I>
at java.lang.Class.getMethod(Unknown
Source)<BR></I>><I> at
org.antlr.gunit.gUnitExecuter.runLexer(gUnitExecuter.java: <BR></I>><I>
211)<BR></I>><I> at
<BR></I>><I>
org.antlr.gunit.gUnitExecuter.runCorrectParser(gUnitExecuter.java:131)<BR></I>><I>
at <BR></I>><I>
org.antlr.gunit.gUnitExecuter.executeTests(gUnitExecuter.java:149)<BR></I>><I>
at org.antlr.gunit.gUnitExecuter.execTest(gUnitExecuter.java: <BR></I>><I>
97)<BR></I>><I> at
org.antlr.gunit.Interp.main(Interp.java:62)<BR></I>><I>
------------------------ END <BR></I>><I>
--------------------------------------------------<BR></I>><I><BR></DIV></I></FONT></BODY></HTML>