Skip to content

How to avoid trailing whitespace getting consumed #916

Answered by notpeter
nnmm asked this question in Q&A
Discussion options

You must be logged in to vote

It's as if the ~ after "b" eats the whitespace following it, even though the "a" is not matched. Is that a bug? If no, how can I stop rules with a repetition at the end from consuming whitespace?

PEST parsers are greedy, so when they match they consume the input and there's going back. So with implicit whitespace
the ~ in baa ~ "\n"becomesbaa ~ WHITESPACE* ~ "\n". WHITESPACE gobbles the newline(s) and so it doesn't find "\n"` and fails.

You should take the newlines out of WHITESPACE and manually account for them. You should only put newlines in WHITESPACE if you are working in a language where newlines, " " and "\t" are all optional/trivial -- this happens in a language with explicit st…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tomtau
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