How to handle line returns in grammar? #971
-
Is it possible to parse line return to a specific AstNode? Let's say, when user hits enter and creates a new line, I want to do something specific, like generate another object according to the AstNode. In current version, If I use '\n' as the keyword, there is an error message popped up 'Keywords cannot only consist of whitespace characters.'. So, is there a way to handle this case? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You can in theory use
However, you must adjust the
At this point, you will need to track every |
Beta Was this translation helpful? Give feedback.
You can in theory use
\n
in a terminal and use it in the AST:However, you must adjust the
hidden terminal WS
in order for this to work:At this point, you will need to track every
\n
character manually in your grammar, which is very annoying, so I wouldn't recommend it. Why is it that you need a special AST node? This would make the grammar insanely complicated, since most languages allow newlines basically anywhere.