[antlr-interest] Follow up to hoisted predicates and local variables

Jim Idle jimi at temporal-wave.com
Sat Sep 15 09:10:54 PDT 2012


OK - So:

Create a rule that lexes /*
Create an input->mark at the start of this rule
Using hand crafted code, walk through the input stream
If a normal comment, then you are just finding the matching */ (handle
embedded)
If a !12345 comment, then
   directly change the /*!12345 to spaces in the input stream,
   find the matching */ and change those to spaces
   input->rewind to the mark you created
   exit the rule

Easy :) - sometimes the best solution is not to try and force the lexer to
deal with this. V4 lexers will be able to deal with state and so on, and
should handle this type of thing better.

Jim





> -----Original Message-----
> From: Mike Lischke [mailto:mike at lischke-online.de]
> Sent: Saturday, September 15, 2012 2:53 AM
> To: Jim Idle
> Cc: ANTLR Mailing List
> Subject: Re: [antlr-interest] Follow up to hoisted predicates and local
> variables
>
>
> Hi Jim,
>
> > I think that you may need to step back on your approach here. You may
> > have showed this before, but what (clearly horrible) language are you
> > trying to parse, and what is the context? We seem to be solving small
> > issues for you, when perhaps your bigger question can be addressed in
> > a more correct fashion.
>
>
> If that were possible I'd be very happy. I have asked the bigger
> question just a few days ago:
> http://antlr.markmail.org/message/reuws4bz3mi6hb24, but got no reply.
>
> In the meantime I came very close to a solution, but am stuck now
> because of the predicates problem I mentioned.
>
> Mike
> --
> www.soft-gems.net
>


More information about the antlr-interest mailing list