robrix / Madness

Recursive Descent Into Madness
MIT License
291 stars 17 forks source link

EOF parser #28

Closed robrix closed 9 years ago

robrix commented 9 years ago

Only matches the empty string.

robrix commented 9 years ago

This can be a bit dangerous if it gets repeated, for example.

neilpa commented 9 years ago

Now that parsers take input and index this should be less dangerous.

robrix commented 9 years ago

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.

neilpa commented 9 years ago

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.

robrix commented 9 years ago

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).