forked from gentoo-utils/gentoo-utils
verify usedeps
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
use core::option::Option::None;
|
||||||
|
|
||||||
use mon::{Parser, r#if, not, numeric1, one_of, opt, tag, take_while};
|
use mon::{Parser, r#if, not, numeric1, one_of, opt, tag, take_while};
|
||||||
|
|
||||||
use crate::{
|
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> {
|
pub fn usedep_sign<'a>() -> impl Parser<&'a str, Output = UseDepSign> {
|
||||||
tag("(-)")
|
tag("(-)")
|
||||||
.map(|_| UseDepSign::Disabled)
|
.map(|_| UseDepSign::Disabled)
|
||||||
.or(tag("(+)").map(|_| UseDepSign::Enabled))
|
.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> {
|
pub fn usedep<'a>() -> impl Parser<&'a str, Output = UseDep> {
|
||||||
opt(usedep_negate())
|
let a = useflag()
|
||||||
.and(useflag())
|
|
||||||
.and(opt(usedep_sign()))
|
.and(opt(usedep_sign()))
|
||||||
.and(opt(usedep_condition()))
|
.preceded_by(tag("-"))
|
||||||
.map(|(((negate, flag), sign), condition)| UseDep {
|
.map(|(flag, sign)| UseDep {
|
||||||
negate,
|
negate: Some(UseDepNegate::Minus),
|
||||||
flag,
|
flag,
|
||||||
sign,
|
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> {
|
pub fn atom<'a>() -> impl Parser<&'a str, Output = Atom> {
|
||||||
@@ -203,7 +245,7 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_atom() {
|
fn test_atom() {
|
||||||
let it = InputIter::new(
|
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();
|
atom().check_finished(it).unwrap();
|
||||||
@@ -224,4 +266,11 @@ mod test {
|
|||||||
|
|
||||||
assert!(atom().check_finished(it).is_err());
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user