0

I have the following code (or similar, anyway):

fragment COMMA : ',' ;
fragment OP : '(' ;
fragment CP : ')' ;

expression
    : ID
    | call
    ;

call
    : ID OP expression (COMMA expression)* CP
    ;

But when I try an example expression, like: foo(bar, baz), I get an error, more specifically, token recognition error at: '('. And when I make them normal rules, and not fragments, commas and parenthesis are added to the parse tree. I want to use COMMAs and parenthesis to match rules, but I don't want them in the parse tree. Anyway, why aren't the fragments working?

Alexis Dumas
  • 1,299
  • 11
  • 30
  • So, in short: `COMMA`, `OP` and `CP` should not be `fragment` rules since you're using them inside parser rules. And if you're trying to do this because you want these tokens to be omitted from the resulting parse tree, then you're out of luck: you can't. – Bart Kiers Jun 04 '15 at 20:44
  • Darn. I guess I can just ignore the characters I don't want. Thanks for the answer, Bart. – Alexis Dumas Jun 04 '15 at 23:03
  • No problem Christopher. – Bart Kiers Jun 05 '15 at 04:47

0 Answers0