Skip to content

Conversation

cenodis
Copy link
Contributor

@cenodis cenodis commented Aug 15, 2021

This PR introduces a fail parser that works as the inverse of the success parser. It always fails regardless of what input was passed to it. This complements the success parser and allows specifying default cases to return an error instead.

I have come across one use case as part of my precedence parser #1362. It requires three parser for prefix, postfix and binary operators respectively. But some languages might not have any prefix or postfix operators so the respective parser should just fail.

Compared to a workaround like verify(tag(""), |_: &str| false), fail is easier to read and makes the intent more clear when a parser is required (e.g. as part of a parameter) but should just fail because its not needed in the context.

@cenodis
Copy link
Contributor Author

cenodis commented Aug 15, 2021

Its not unrecoverable. Its the normal nom::Err::Error. Though I guess the name fail could be confused with the unrecoverable Failure variant. But I dont want yet another thing called "error" in nom considering that there are already 4 or 5 things with the name "error". Any other suggestions?

@Stargateur
Copy link
Contributor

Stargateur commented Aug 15, 2021

Well, failure should be ok when we will rename the error type in nom, for now it's probably confusing. Maybe for now forward ? Cause I still wonder how to rename Err::Error to either Failure or Forward;

Or maybe recoverable ? (meh)

@Geal
Copy link
Collaborator

Geal commented Aug 17, 2021

naming it fail will be fine for now

@Geal Geal merged commit 808a85b into rust-bakery:master Aug 17, 2021
@Geal
Copy link
Collaborator

Geal commented Aug 17, 2021

thanks!

@cenodis cenodis deleted the feature_fail branch August 17, 2021 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants