-
-
Save faiface/1cefa2e1e1732089cea35759425b5861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I have to create a custom type because the undesired behavior | |
// only occurs if I use a custom type for the parsing result. If | |
// I tried with something like bool, I get my custom error returned | |
// back just as I want it. Very strange. | |
pub enum MyUnit { Only } | |
// Now this parser returns "found end of input" if the input is not | |
// equal to "only". But a custom error is generated and wanted to be | |
// returned instead. | |
pub fn example() -> impl Parser<char, MyUnit, Error = Simple<char>> { | |
text::ident().padded() | |
.try_map(|s: String, span| { | |
match s.as_str() { | |
"only" => Ok(MyUnit::Only), | |
_ => Err(Simple::custom(span, format!("invalid bool value {:?}", s))), | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment