My grammar must ignore whitespaces for the most part, except in certain contexts. Answers to this question advises to define specific lexer rules to handle the exceptions I want.
The problem is that (I think) I cannot handle such cases at the lexer level, since they seem to be triggered high at the parser level.
To be more specific: I want to recognize something like
MyRule:
MyParseTree1 Operator MyParseTree2 // WS is skipped
| MyParseTree1 WS SensitiveOperator WS MyParse // WS carries meaning
keeping in mind that I have a WS -> skip rule because in most of my grammar whitespaces should be skipped.
In Xtext, rules can specify on a rule-scoped basis what hidden tokens apply within the rule's scope:
MyRule (hidden COMMENTS):
... // WS reaches the parser, comments don't
MyRule2 (hidden WS, COMMENTS):
... // WS is skipped, comments too
But I am clueless with antlr4.