1

I am working on a grammar that allows for keywords as identifiers, and the current suggestion seems to be to do something like:

id : 'if'|'call'|'then'|ID;

My language has a lot of keywords, so I've been doing:

id: ~(PLUS | MINUS);

Basically any token that's NOT a non-keyword token.

Is there a way to have all of my keyword tokens be prepended with some string and wildcard match that? e.g.

K_PLUS: '+';
K_MINUS: '-';
ID: <everything else>;

id : ID | ~(K_*);

1 Answers1

0

No, that is not possible unfortunately.

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
  • Thanks. Do you know if there's a technical/scientific reason why something like that isn't allowed? – Arun Ramani May 08 '18 at 20:36
  • @ArunRamani ah, missed your question. Well, I think it's not supported because it is not very often needed. Also, it's rather error prone: when adding rules, you'd accidentally match it by some wild card matching. Even if it was supported, I'd still use `id : 'if'|'call'|'then'|ID;` instead of `id : ID | ~(K_*);` – Bart Kiers May 15 '18 at 19:15