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

Jesse McGrew jmcgrew at gmail.com
Sat Sep 15 04:53:41 PDT 2012


I think my approach would be for the multiline comment lexer rule to
look ahead after it sees '/*' to determine if it's a matching version
comment. If it is, then only consume the '/*' and set a flag; if not,
consume the whole comment as usual. Then in the lexer rule for the '*'
operator, if the flag is set, allow it to match '*/', mark it hidden,
and clear the flag. So more or less:

MULTILINE_COMMENT
: '/*'
  ( {matchingVersionFollows() == false}?=> .* '*/'     /* regular comment */
  | /* version comment matched, don't consume any more */
    { $type = VERSION_COMMENT_BEGIN; inVersionComment = true; }
  )
  { $channel = HIDDEN; }
;

STAR
: '*'
  ( {inVersionComment}?=> '/' { $type = VERSION_COMMENT_END; $channel
= HIDDEN; inVersionComment = false; }
  | /* just the star */
  )
;

On Sat, Sep 15, 2012 at 2:53 AM, Mike Lischke <mike at lischke-online.de> wrote:
>
> 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
>
>
>
> 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