<span class="Apple-style-span" style="border-collapse: collapse; ">Hi <span style="border-collapse: collapse; white-space: pre-wrap; ">Gavin Lamber:</span><div><span style="border-collapse: collapse; white-space: pre-wrap; "> Thanks for your reply.</span></div>
<div><span style="border-collapse: collapse; white-space: pre-wrap; "> I tried the lexer rule you gave me. But following error comes out:</span></div><div><span style="border-collapse: collapse; white-space: pre-wrap; "><br>
</span></div><div><span style="border-collapse: collapse; white-space: pre-wrap; "> Alternative 155: after matching input such as 'F''U''N''C''T''I''O''N''F''U''N''C''T''I''O''N''F''U''N''C''T''I''O''N''E''N''D''_''F''U''N''C''T''I''O''N'{'0'..'9', 'A'..'Z', '_', 'a'..'z'}'F''U''N''C''T''I''O''N''E''N''D''_''F''U''N''C''T''I''O''N'{'0'..'9', 'A'..'Z', '_', 'a'..'z'}'F''U''N''C''T''I''O'{'\u0000'..'/', ':'..'@', 'N', '['..'^', '`', '{'..'\uFFFF'} decision cannot predict what comes next due to recursion overflow to FUNCTION_DECL from FUNCTION_DECL</span></div>
</span><br><div class="gmail_quote">On Tue, Jan 13, 2009 at 7:11 PM, Gavin Lambert <span dir="ltr"><<a href="mailto:antlr@mirality.co.nz">antlr@mirality.co.nz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="Ih2E3d">At 22:10 13/01/2009, chain one wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I want to recognize a function definition and skip it before passing tokens to the parser.<br>
The function definition starts with "FUNCTION" ,ends with "END_FUNCTION".<br>
</blockquote></div>
[...]<div class="Ih2E3d"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
FUNCTION_DECL<br>
: 'FUNCTION'<br>
{<br>
$channel=HIDDEN;<br>
}<br>
( options {greedy=false;} : . )* FUNCTION_DECL ( options {greedy=false;} : . )* 'END_FUNCTION' SEMI<br>
;<br>
</blockquote>
<br></div>
You might need to be more explicit about it:<div class="Ih2E3d"><br>
<br>
FUNCTION_DECL<br>
: 'FUNCTION' { $channel = HIDDEN; }<br></div>
(FUNCTION_DECL | ~'E' | 'E' ~'N' | 'EN' ~'D' | 'END' ~'_' |<br>
'END_' ~'F' | 'END_F' ~'U' | 'END_FU' ~'N' | 'END_FUN' ~'C' |<br>
'END_FUNC' ~'T' | 'END_FUNCT' ~'I' | 'END_FUNCTI' ~'O' |<br>
'END_FUNCTIO' ~'N' | 'END_FUNCTION' ~SEMI)*<br>
'END_FUNCTION' SEMI<br>
;<br>
<br>
(This assumes that whitespace isn't permitted between END_FUNCTION and the semicolon.)<br>
<br>
Also, if you're wanting to skip over large chunks of your input, then you might want to investigate filtering lexers.<div class="Ih2E3d"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This also could not work : ( :<br>
<br>
fragment<br>
FUNCTION:<br>
'FUNCTION'<br>
;<br>
</blockquote></div>
[...]<div class="Ih2E3d"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
FUNCTION_DECL<br>
:FUNCTION<br>
{<br>
SKIP();<br>
}<br>
( ~(FUNCTION|END_FUNCTION)<br>
|<br>
FUNCTION_DECL<br>
)* END_FUNCTION SEMI<br>
;<br>
</blockquote>
<br></div>
The reason why that doesn't work is that ~ can only take the inverse of sets, and sets in a lexer rule are alternatives of individual characters. FUNCTION and END_FUNCTION are not sets, they're sequences, so it's illegal to use ~ on them.<br>
<br>
</blockquote></div><br>