Skip to content
Discussion options

You must be logged in to vote

You can in theory use \n in a terminal and use it in the AST:

entry Test: return=RETURN;

terminal RETURN: /\r?\n/;

However, you must adjust the hidden terminal WS in order for this to work:

hidden terminal WS: /[ \t\r]+/;

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.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ShirlyWang666
Comment options

@msujew
Comment options

@ShirlyWang666
Comment options

Answer selected by msujew
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants