On Feb 16, 2010, at 12:27 PM, Gavin Lambert wrote:
> At 08:13 17/02/2010, Terence Parr wrote:
> >} and what I need is loop escaping dependent on previous match, so
> >some constrained context passing would be nice.
> >
> >try predicates. :)
>
> While it's usually possible to frame the contents of a looping construct in a
> positive sense (which is what ANTLR currently requires), it'd be nice if
> there were a language construct that would let you do specific negative
> matches too (maybe a feature request for v4?).
Been thinking about that.
> For (a completely made up) example, consider a case where you might want to
> match any identifier except one starting with "foo". In current ANTLR, you'd
> have to do one of these:
> FOOLIST: 'foo[' NON_FOO_ID+ ']';
> FOOLIST: 'foo[' ({!next_id_starts_with_foo()}? => ID)+ ']';
> FOOLIST: 'foo[' ((~'f' | 'f' ~'o' | 'fo' ~'o') => ID)+ ']';
>
> It'd be nice if there was some way to express a negative match via a
> syntactic predicate, eg:
> FOOLIST: 'foo[' (('foo') => ~ | ID)+ ']';
> (where '~' in an alt basically means "break", ie. match nothing and terminate
> the innermost loop.)
> Or, perhaps better:
> FOOLIST: 'foo[' (('foo') ~=> ID)+ ']';
> (where '~=>' means "only take this path if the predicate *fails*")
>
> Granted, this sort of requirement doesn't come up often, but when it does
> it'd be nice to have a tidier way of expressing it; and it'd be fairly simple
> to implement... :)
happens only in lexer as far as i can tell but would be nice to have.
updated
http://www.antlr.org/wiki/display/~admin/2010/01/19/ANTLR+v4+lexers
Ter
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en.