Skip to content

Using delimited_by on whitespace doesn't seem to work #88

Answered by zesterer
Isaac-Leonard asked this question in Q&A
Discussion options

You must be logged in to vote

Hello!

The answer to this is subtle and non-obvious, and goes away entirely if you use .at_least(1) after .repeated() (although, this is probably not the best solution).

Why this happens

This happens because repeated is permitted to accept no occurrences of the pattern at all, so there is no possible input for which repeated can fail, because any failure counts as 'the end of the repeating section'.

When parsing your input, { }, the exp.padded().repeated() parser succeeds because no occurrences of exp.padded() were found. It then falls back to the latter part of delimited_by, immediately expecting a } following it (because or is lazy and only tries the second parser if the first failed). …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by Isaac-Leonard
Comment options

You must be logged in to vote
1 reply
@zesterer
Comment options

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