[antlr-interest] Parsing quoted phrases and non-quoted keywords
Scott Van Wart
scott at indosoft.com
Fri Jul 31 18:57:24 PDT 2009
Fantastic, thanks very much for your help! My quoted string rule used
to be a parser rule but I thought I could separate out the quotes in the
parser rather than in my own Java code. Yay for laziness. (more inline
comments below)
Gavin Lambert wrote:
> Another alternative here is to just use this instead:
>
> OTHER: . ;
Now just to check my understanding, I thought I'd try a non-greedy loop
to see what error it would give me (I assumed it would give an error
since you didn't mention it as a viable solution :):
OTHER: ( options { greedy = false; } : . )+;
Which gave me "The following alternatives can never be matched: 1".
Since the rule doesn't have some kind of terminating token (like '/*' (
options { greedy = false; } : . )* '*/') and it won't look at other
rules to find out when to stop, the greedy match won't match anything at
all. Is that the right understanding? Why then wouldn't it always
match a single character due to the '+' being 1 or more matches?
Thanks again! Got it working perfectly.
- Scott
More information about the antlr-interest
mailing list