diff options
| author | John Turner <jturner.usa@gmail.com> | 2025-11-13 19:49:22 +0000 |
|---|---|---|
| committer | John Turner <jturner.usa@gmail.com> | 2025-11-13 19:49:22 +0000 |
| commit | 0448a529264d1a27d741bc817de468f8d359072d (patch) | |
| tree | 0c0f5bbe7afb1240f44d3c6f221d50799c956257 | |
| parent | 874be77aa404167270e94afcc7722078bb499b51 (diff) | |
| download | gentoo-utils-0448a529264d1a27d741bc817de468f8d359072d.tar.gz | |
impl Cp type
| -rw-r--r-- | src/atom/mod.rs | 12 | ||||
| -rw-r--r-- | src/atom/parsers.rs | 16 |
2 files changed, 25 insertions, 3 deletions
diff --git a/src/atom/mod.rs b/src/atom/mod.rs index 0d1d3a9..6688665 100644 --- a/src/atom/mod.rs +++ b/src/atom/mod.rs @@ -109,6 +109,12 @@ pub struct UseDep { } #[derive(Clone, Debug, PartialEq, Eq, Get)] +pub struct Cp { + category: Category, + name: Name, +} + +#[derive(Clone, Debug, PartialEq, Eq, Get)] pub struct Cpv { category: Category, name: Name, @@ -558,6 +564,12 @@ impl fmt::Display for UseDep { } } +impl fmt::Display for Cp { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}/{}", &self.category, &self.name) + } +} + impl fmt::Display for Cpv { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}/{}-{}", &self.category, &self.name, &self.version) diff --git a/src/atom/parsers.rs b/src/atom/parsers.rs index 9d3cb15..4806857 100644 --- a/src/atom/parsers.rs +++ b/src/atom/parsers.rs @@ -5,9 +5,9 @@ use mon::{Parser, ParserIter, r#if, numeric1, one_of, tag}; use crate::{ Parseable, atom::{ - Atom, Blocker, Category, Cpv, Name, Slot, SlotName, SlotOperator, UseDep, UseDepCondition, - UseDepNegate, UseDepSign, Version, VersionNumber, VersionNumbers, VersionOperator, - VersionSuffix, VersionSuffixKind, VersionSuffixes, + Atom, Blocker, Category, Cp, Cpv, Name, Slot, SlotName, SlotOperator, UseDep, + UseDepCondition, UseDepNegate, UseDepSign, Version, VersionNumber, VersionNumbers, + VersionOperator, VersionSuffix, VersionSuffixKind, VersionSuffixes, }, useflag::UseFlag, }; @@ -334,6 +334,16 @@ impl<'a> Parseable<'a, &'a str> for Atom { } } +impl<'a> Parseable<'a, &'a str> for Cp { + type Parser = impl Parser<&'a str, Output = Self>; + + fn parser() -> Self::Parser { + Category::parser() + .and(Name::parser().preceded_by(tag("/"))) + .map(|(category, name)| Cp { category, name }) + } +} + impl<'a> Parseable<'a, &'a str> for Cpv { type Parser = impl Parser<&'a str, Output = Self>; |
