summaryrefslogtreecommitdiff
path: root/src/atom
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-11-18 04:15:53 +0000
committerJohn Turner <jturner.usa@gmail.com>2025-11-18 04:15:53 +0000
commitc75a38f6152fffcdb7b044231f7c65da957ece25 (patch)
tree32e46cfcbcfb3effc5ca5a3531764e4dc30dc42e /src/atom
parent2dc5df611258104ec56dbf6cea0089c28766e270 (diff)
downloadgentoo-utils-c75a38f6152fffcdb7b044231f7c65da957ece25.tar.gz
allow slot to be only :* := :slot/sub= or :slot
Diffstat (limited to 'src/atom')
-rw-r--r--src/atom/mod.rs46
-rw-r--r--src/atom/parsers.rs23
2 files changed, 41 insertions, 28 deletions
diff --git a/src/atom/mod.rs b/src/atom/mod.rs
index 0378a8d..6251e35 100644
--- a/src/atom/mod.rs
+++ b/src/atom/mod.rs
@@ -79,11 +79,17 @@ pub enum SlotOperator {
#[derive(Clone, Debug, PartialEq, Eq, Get)]
pub struct SlotName(#[get(method = "name", kind = "deref")] String);
-#[derive(Clone, Debug, PartialEq, Eq, Get)]
-pub struct Slot {
- primary: Option<SlotName>,
- sub: Option<SlotName>,
- operator: Option<SlotOperator>,
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub enum Slot {
+ Wildcard,
+ Equal {
+ primary: Option<SlotName>,
+ sub: Option<SlotName>,
+ },
+ Name {
+ primary: SlotName,
+ sub: Option<SlotName>,
+ },
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -575,19 +581,29 @@ impl fmt::Display for SlotName {
impl fmt::Display for Slot {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- if let Some(slot) = self.primary.as_ref() {
- write!(f, "{slot}")?;
- }
+ match self {
+ Self::Wildcard => write!(f, "*"),
+ Self::Equal { primary, sub } => {
+ if let Some(primary) = primary {
+ write!(f, "{primary}")?;
+ }
- if let Some(sub) = self.sub.as_ref() {
- write!(f, "/{sub}")?;
- }
+ if let Some(sub) = sub {
+ write!(f, "/{sub}")?;
+ }
- if let Some(operator) = self.operator.as_ref() {
- write!(f, "{operator}")?;
- }
+ write!(f, "=")
+ }
+ Self::Name { primary, sub } => {
+ write!(f, "{primary}")?;
- Ok(())
+ if let Some(sub) = sub {
+ write!(f, "/{sub}")?;
+ }
+
+ Ok(())
+ }
+ }
}
}
diff --git a/src/atom/parsers.rs b/src/atom/parsers.rs
index 75eca51..47c8c1e 100644
--- a/src/atom/parsers.rs
+++ b/src/atom/parsers.rs
@@ -186,21 +186,17 @@ impl<'a> Parseable<'a, &'a str> for Slot {
type Parser = impl Parser<&'a str, Output = Self>;
fn parser() -> Self::Parser {
- SlotName::parser()
+ let wildcard = tag("*").map(|_| Slot::Wildcard);
+ let equals = SlotName::parser()
.opt()
.and(SlotName::parser().preceded_by(tag("/")).opt())
- .and(SlotOperator::parser().opt())
- .map(|((primary, sub), operator)| Slot {
- primary,
- sub,
- operator,
- })
- .verify_output(|slot| {
- matches!(
- (&slot.primary(), &slot.operator()),
- (Some(_) | None, Some(_)) | (Some(_), None)
- )
- })
+ .followed_by(tag("="))
+ .map(|(primary, sub)| Slot::Equal { primary, sub });
+ let name = SlotName::parser()
+ .and(SlotName::parser().preceded_by(tag("/")).opt())
+ .map(|(primary, sub)| Slot::Name { primary, sub });
+
+ wildcard.or(equals).or(name)
}
}
@@ -556,6 +552,7 @@ mod test {
"=dev-ml/stdio-0.17*t:=[ocamlopt?]",
">=dev-libs/libgee-0-8.5:0..8=",
"<dev-haskell/wai-3.3:=[]",
+ ">=kde-frameworks/kcrash-2.16.0:6*",
];
for atom in atoms {