Vipul Delwadia wrote:
> Hi,
>
> Suppose I have a very simple grammar:
>
> line: x;
>
> x     :       STRING+;
>
> fragment BACKSLASH
>       :       '\\';
>
> NOTA: BACKSLASH A;
>
> A     :       'a';
>
> STRING
>       :       (~(A)|NOTA)+;
>
> Now I want x to be able to match any sequence which doesn't have "a"
> in it, including sequences which have "\a".

A and NOTA should be fragment rules, but there are other problems,
for example (~(A)|NOTA) is ambiguous because ~(A) includes '\\'.
This should work (untested):

STRING : (~('a'|'\\') | ('\\' .))+ '\\'?;

Note that this will not allow a double-backslash followed by 'a'.
(In most languages, that would be an escaped backslash, so it
shouldn't be allowed.) You may or may not want to allow the
optional unterminated backslash ('\\'?) at the end.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com


Attachment: signature.asc
Description: OpenPGP digital signature

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

Reply via email to