summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/atom/parsers.rs89
1 files changed, 69 insertions, 20 deletions
diff --git a/src/atom/parsers.rs b/src/atom/parsers.rs
index 7b2b096..4bc27ce 100644
--- a/src/atom/parsers.rs
+++ b/src/atom/parsers.rs
@@ -1,3 +1,5 @@
+use core::option::Option::None;
+
use mon::{Parser, r#if, not, numeric1, one_of, opt, tag, take_while};
use crate::{
@@ -120,35 +122,75 @@ pub fn slot<'a>() -> impl Parser<&'a str, Output = Slot> {
})
}
-pub fn usedep_negate<'a>() -> impl Parser<&'a str, Output = UseDepNegate> {
- tag("-")
- .map(|_| UseDepNegate::Minus)
- .or(tag("!").map(|_| UseDepNegate::Exclamation))
-}
-
pub fn usedep_sign<'a>() -> impl Parser<&'a str, Output = UseDepSign> {
tag("(-)")
.map(|_| UseDepSign::Disabled)
.or(tag("(+)").map(|_| UseDepSign::Enabled))
}
-pub fn usedep_condition<'a>() -> impl Parser<&'a str, Output = UseDepCondition> {
- tag("=")
- .map(|_| UseDepCondition::Eq)
- .or(tag("?").map(|_| UseDepCondition::Question))
-}
-
pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
- opt(usedep_negate())
- .and(useflag())
+ let a = useflag()
.and(opt(usedep_sign()))
- .and(opt(usedep_condition()))
- .map(|(((negate, flag), sign), condition)| UseDep {
- negate,
+ .preceded_by(tag("-"))
+ .map(|(flag, sign)| UseDep {
+ negate: Some(UseDepNegate::Minus),
flag,
sign,
- condition,
- })
+ condition: None,
+ });
+
+ let b = useflag()
+ .and(opt(usedep_sign()))
+ .preceded_by(tag("!"))
+ .followed_by(tag("?"))
+ .map(|(flag, sign)| UseDep {
+ negate: Some(UseDepNegate::Exclamation),
+ flag,
+ sign,
+ condition: Some(UseDepCondition::Question),
+ });
+
+ let c = useflag()
+ .and(opt(usedep_sign()))
+ .followed_by(tag("?"))
+ .map(|(flag, sign)| UseDep {
+ negate: None,
+ flag,
+ sign,
+ condition: Some(UseDepCondition::Question),
+ });
+
+ let d = useflag()
+ .and(opt(usedep_sign()))
+ .preceded_by(tag("!"))
+ .followed_by(tag("="))
+ .map(|(flag, sign)| UseDep {
+ negate: Some(UseDepNegate::Exclamation),
+ flag,
+ sign,
+ condition: Some(UseDepCondition::Eq),
+ });
+
+ let e = useflag()
+ .and(opt(usedep_sign()))
+ .followed_by(tag("="))
+ .map(|(flag, sign)| UseDep {
+ negate: None,
+ flag,
+ sign,
+ condition: Some(UseDepCondition::Eq),
+ });
+
+ let f = useflag()
+ .and(opt(usedep_sign()))
+ .map(|(flag, sign)| UseDep {
+ negate: None,
+ flag,
+ sign,
+ condition: None,
+ });
+
+ a.or(b).or(c).or(d).or(e).or(f)
}
pub fn atom<'a>() -> impl Parser<&'a str, Output = Atom> {
@@ -203,7 +245,7 @@ mod test {
#[test]
fn test_atom() {
let it = InputIter::new(
- "!!>=cat/pkg-1-foo-1.0.0v_alpha1_p20250326-r1:primary/sub=[!a(+),-b(-)=,c?]",
+ "!!>=cat/pkg-1-foo-1.0.0v_alpha1_p20250326-r1:primary/sub=[use,use=,!use=,use?,!use?,-use,use(+),use(-)]",
);
atom().check_finished(it).unwrap();
@@ -224,4 +266,11 @@ mod test {
assert!(atom().check_finished(it).is_err());
}
+
+ #[test]
+ fn test_invalid_usedep() {
+ let it = InputIter::new("foo-bar-1.0.0:slot/sub=[!use]");
+
+ assert!(atom().check_finished(it).is_err())
+ }
}