[antlr-interest] Newbie trying to tame lexer

forumer at smartmobili.com forumer at smartmobili.com
Sat Aug 18 09:19:41 PDT 2012


I have declared a new rule

JAVADOC_COMMENT
  : '/**' ({input.LA(1) != '*' && input.LA(2) != '/'}?=> . )*
  ;


I suppose it will fix my problem.

Thanks

Le 18.08.2012 15:08, forumer... a écrit :
> Thanks a lot, I just see your answer now and I am trying it.
> It seems to work except for javadoc comment :
>
> /**
> public class FooBar extends Bar {
>
> }
> */
>
> I get a new FailedPredicateException(input, "BLOCK_COMMENT",
> "input.LA(1) != '*' && input.LA(2) != '/'");
>
>
>
>
>
>
>
> Le 05.08.2012 19:53, Bart Kiers a écrit :
>> 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,  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
>>> dont want that.
>>> So is it possible ?
>>
>>
>>
>> Links:
>> ------
>> [1] mailto:forumer at smartmobili.com
>
> 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