Force whitespaces between tokens Follow
Answered
Hi. What is the right way to force whitespaces between tokens for a custom language? For example the rule below must contain `TokenType.WHITE_SPACE` between tokens but by default the parser accepts strings like `key1ESCAPE`.
key_expr ::= KEY_KEYWORD NUMBER LABEL
I don't want to put `WHITE_SPACE` in my the grammar.
Additionally I need to check that every expression is placed on a single line.
I've found `ParserDefinition.SpaceRequirements` but it seems like it only works for some refactoring. Do I have to implement a custom Annotator to solve the issue?
Please sign in to leave a comment.
Hi Ilya,
It sounds like whitespaces are part of your grammar, so I don't understand why you don't want to include them.
I would try to create the required custom "whitespace" tokens (not using the existing one) in your lexer and in BNF where it is needed. It may be tricky to create a lexer that correctly recognizes required whitespace, when there are optional whitespaces as well.
Another solution, if you don't want to include it in your grammar for some reason, is to use Annotator.