I have a grammar that works with v3, and I am now trying to migrate to v4. I have taken some hints from questions 18431158 and 14778570, but I have one more question:
In my v3 code, I was counting line numbers like this (newLine() just keeps a count of lines parsed and saves it, so that later, when I try to report some semantic errors, I could also report the corresponding line number):
COMMENT : '/*' ( options {greedy=false;} :
(
'\n' {newLine();}
| ~ '\n'
) )* '*/' {$channel=HIDDEN;}
;
LINE_COMMENT : '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN; newLine();} ;
WS: (
' '
|'\r'
|'\t'
|'\n' {newLine();}
)+ {$channel=HIDDEN;};
In v4, the lexer actions are not permitted inside. How do I migrate this code to v4?