diff --git a/src/atom/parsers.rs b/src/atom/parsers.rs index 65cce04..f4686f2 100644 --- a/src/atom/parsers.rs +++ b/src/atom/parsers.rs @@ -280,4 +280,11 @@ mod test { atom().check_finished(it).unwrap(); } + + #[test] + fn test_usedep_with_underscore() { + let it = InputIter::new("foo/bar-1.0.0[use_dep]"); + + atom().check_finished(it).unwrap(); + } } diff --git a/src/useflag/parsers.rs b/src/useflag/parsers.rs index e6e228b..a430b3d 100644 --- a/src/useflag/parsers.rs +++ b/src/useflag/parsers.rs @@ -1,10 +1,15 @@ -use mon::{Parser, alpha1, alphanumeric, one_of, take_while}; +use mon::{Parser, r#if, take_while}; use crate::useflag::UseFlag; pub fn useflag<'a>() -> impl Parser<&'a str, Output = UseFlag> { - alpha1() - .and(alphanumeric().or(take_while(one_of("+_@-".chars())))) + let start = r#if(|c: &char| c.is_ascii_alphanumeric()); + let rest = take_while(r#if(|c: &char| { + c.is_ascii_alphanumeric() || "+_@-".contains(*c) + })); + + start + .and(rest) .recognize() .map(|output: &str| UseFlag(output.to_string())) }