Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rule reference is not currently supported in a set in ANTLR4 Grammar

I am trying to port Chris Lambro's ANTLR3 Javascript Grammar to ANTLR4

I am getting the following error,

Rule reference 'LT' is not currently supported in a set

in the following code ~(LT)*

LineComment
    : '//'  ~(LT)* -> skip
    ;

LT  : '\n'      // Line feed.
    | '\r'      // Carriage return.
    | '\u2028'  // Line separator.
    | '\u2029'  // Paragraph separator.
    ;

I need help understanding why I am getting this error, and how I can solve it .

like image 392
Gautam Avatar asked May 28 '13 11:05

Gautam


1 Answers

The ~ operator in ANTLR inverts a set of symbols (characters in the lexer, or tokens in the parser). Inside the set, you have a reference to the LT lexer rule, which is not currently supported in ANTLR 4. To resolve the problem, you need to inline the rule reference:

LineComment
    :   '//' ~([\n\r\u2028\u2029])* -> skip
    ;
like image 144
Sam Harwell Avatar answered Nov 20 '22 10:11

Sam Harwell