[antlr-interest] * (zero or more) not matching greedily
Petteri Räty
betelgeuse at gentoo.org
Fri Apr 10 12:16:47 PDT 2009
Petteri Räty wrote:
> The relevant stuff from a grammar:
>
> category: (alphanum|'+'|'_'|DOT) ( alphanum|'+'|'_'|DOT|'-')* {
> System.out.println($category.text); };
>
> alphanum: LOWER|UPPER|DIGIT;
>
> DOT : '.';
>
> DIGIT : '0'..'9';
> LOWER : 'a'..'z';
> UPPER : 'A'..'Z';
>
> Why does it only take the first character for category? Isn't * supposed
> to be greedy? I also tried adding options {greedy=true;} to the subrule
> but it doesn't make a difference.
>
> betelgeuse at pena ~/python/depend $ ATOM="app-foo" make
> java -cp <snip long cp> Main app-foo
> a
>
> Regards,
> Petteri
>
>
Ok by attaching a Netbeans debugger I figured out what's going on. I have:
state_suffix
: '_' ('alpha'|'beta'|'pre'|'rc'|'p') integer?;
From here antlr creates a token that matches 'p' when parsing alphanum.
Is there a better way than changing this to a validating semantic
predicated?
Regards,
Petteri
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 261 bytes
Desc: OpenPGP digital signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090410/7b706af4/attachment.bin
More information about the antlr-interest
mailing list