Using delimited_by on whitespace doesn't seem to work #88
-
Theres a very good chance I'm just making a mistake here and I've not done extensive testing on it yet but it seems like the only cause is a bug in Chomsky.
The parser code is:
The full code is on my GitHub however its not yet commented at all pretty much. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hello! The answer to this is subtle and non-obvious, and goes away entirely if you use Why this happensThis happens because When parsing your input, Solving thisIn general, something like exp
.clone()
.padded()
.repeated()
.padded()
.delimited_by('{', '}') I hope this helps! |
Beta Was this translation helpful? Give feedback.
-
Hey, that works perfectly thank you and makes complete sense, feel like I should've realised that from the start lol. |
Beta Was this translation helpful? Give feedback.
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 whichrepeated
can fail, because any failure counts as 'the end of the repeating section'.When parsing your input,
{ }
, theexp.padded().repeated()
parser succeeds because no occurrences ofexp.padded()
were found. It then falls back to the latter part ofdelimited_by
, immediately expecting a}
following it (becauseor
is lazy and only tries the second parser if the first failed). …