Skip to content

Instantly share code, notes, and snippets.

@antifuchs
Created April 10, 2019 10:54
Show Gist options
  • Save antifuchs/00401104d37e4b5b407c2606cdddd243 to your computer and use it in GitHub Desktop.
Save antifuchs/00401104d37e4b5b407c2606cdddd243 to your computer and use it in GitHub Desktop.
An example of a failing parse error kind implementation
[package]
edition = '2018'
name = "wtf_nom"
version = "0.0.1-dev"
authors = ["Andreas Fuchs <[email protected]>"]
license = "MIT"
[dependencies]
nom = "4.2.3"
use nom::*;
#[derive(Debug, PartialEq, Clone)]
pub enum ParseErrorKind {
Bcrypt,
/// An unexpected parse error, indicates a bug in the htpasswd crate
Unknown,
}
impl From<u32> for ParseErrorKind {
fn from(f: u32) -> Self {
ParseErrorKind::Unknown
}
}
named!(bcrypt_pw<&str, String, ParseErrorKind>,
return_error!(ErrorKind::Custom(ParseErrorKind::Bcrypt),
do_parse!(
peek!(alt_complete!(tag!("$2a$") | tag!("$2y$") | tag!("$2b$"))) >>
pw: not_line_ending >>
(pw.to_string())
))
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment