Closed robrix closed 9 years ago
This can be a bit dangerous if it gets repeated, for example.
Now that parsers take input and index this should be less dangerous.
No, it’s just as dangerous—the danger was never e.g. unwrapping nil, but rather infinite loops: unbounded repetition of any successful empty parser will infinite loop. For example:
eof*
will infinite loop if it is successful (i.e. at the end of the input).
This makes this sort of combinator extremely difficult to use safely because anything using the parser it’s part of could repeat it unboundedly without that being at all obvious; worse still, the symptoms might only appear for degenerate inputs :grimacing:
With that in mind, I’m going to close this out. The only truly safe way to use eof
is as a direct child of the combinator passed to parse
, and parse
itself already handles the parse-til-end-of-input case.
Isn't this a danger for any zero-width matching parser? I can see eof
being useful for matching on common errors like mismatched brackets/parens or unterminated strings.
Yes, that is a danger for any zero-width matching parser. I’m :-1: on including any of them without some sort of guard (like e.g. only functioning within lookahead).
Only matches the empty string.