-
Beginner question here: if I'm to use white space as the the separator in certain rules, do I have to remove it from the Lexer.SKIPPED group and handle it everywhere else? For example, a syntax like this:
There are two kinds of statements: inline and multi-line. The statements are separated by line breaks, The whitespace is the separator for inline statements arguments like "Identifier1 arg0 arg1", but it should be skipped elsewhere such as in the indents. What's the best way to achieve this effect? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
With whitespace skipped, you will get the following tokens: IDENT LBRACE IDENT IDENT IDENT IDENT LBRACE. One thing that would probably work is a gate which checks if the token is on the same line.
Another approach, if most of the newlines are relevant, but spaces and tabs are not, would be to have your WHITESPACE token NOT match "\n" and be skipped. "\n" would be a separate token which you don't skip. You might need to handle in a couple of cases where it could be ignored but it should be fewer. |
Beta Was this translation helpful? Give feedback.
-
It is best to avoid handling whitespace everywhere if possible as that ends up being very verbose.
Does the existence or lack thereof of the whitespace cause different meaning during parsing? Can you identify the situation where the whitespace is meaningful during (or after) lexing and inject |
Beta Was this translation helpful? Give feedback.
With whitespace skipped, you will get the following tokens: IDENT LBRACE IDENT IDENT IDENT IDENT LBRACE.
One thing that would probably work is a gate which checks if the token is on the same line.
You will probably need to ignore ambiguities somewhere.
Another approach, if most of the newlines are relevant, but spaces and tabs are not, would be to have your WHITESPACE token NOT match "\n" and be skipped. "\n" would be a separate token which you don't skip. You m…