[antlr-interest] Newbie trying to tame lexer
Bart Kiers
bkiers at gmail.com
Sun Aug 5 10:53:55 PDT 2012
Try something like this:
BLOCK_COMMENT
: '/*' ({input.LA(1) != '*' && input.LA(2) != '/'}?=> . )*
( '*/'
| EOF {System.err.println("Oi, wrong BLOCK_COMMENT!");}
)
;
Note that the predicate, `{input.LA(1) != '*' && input.LA(2) != '/'}?=>`,
contains target-specific code (Java, in my example).
Regards,
Bart.
On Sat, Aug 4, 2012 at 10:34 PM, <forumer at smartmobili.com> wrote:
> Le 04.08.2012 20:20, Bart Kiers a écrit :
>
>> Hi forumer,
>>
>> Youd normally create a single rule for a block comment, like this:
>>
>> BLOCK_COMMENT
>> : /* .* */
>> ;
>>
>> Yes I know but I need a parser that can accept invalid multiline
> comments, ex
>
> /*
> * I am an invalid multiline comment
>
> With the traditional approach I will get a match exception and I don't
> want that.
> So is it possible ?
>
>
>
>
More information about the antlr-interest
mailing list