Reputation: 39437
I wrote a stub for a grammar (only matches comments so far), and it's giving me the error:
syntax error: invalid char literal: <INVALID>
Moreover, I've tracked down the error to being in the following command:
... ~LINE_ENDING* ...
LINE_ENDING : ( '\n' | '\r' | '\r\n');
Can someone help me fix this?
Upvotes: 0
Views: 766
Reputation: 99869
The ~
operator can only be applied to a set. In a lexer, the elements of a set are characters of an input stream. In other words, you can have this:
~( 'a'..'z'
| 'C'
| '\r'
| '\n'
)
But you can't have this because it's a sequence (of two characters) instead of a set.
~('\r\n')
The problem you encountered is an extension of this second case.
Upvotes: 2
Reputation: 170158
Not sure why you get that error (I have no means of testing it myself at the moment). Perhaps the fact you're negating either a single char (\r
or \n
) or a double char (\r\n
) is an issue?
What happens if you try:
SingleLineComment
: '//' (~LineBreakChar)* (NewLine | EOF)
;
LineBreakChar
: '\r' | '\n'
;
NewLine
: '\r'? '\n' | '\r'
;
?
Upvotes: 1