represent 4th variant of slots, and disallow empty primary slot names

This commit is contained in:
John Turner
2025-11-22 01:03:14 +00:00
parent bd0fec80f9
commit e9603ce62f
2 changed files with 14 additions and 11 deletions

View File

@@ -85,8 +85,9 @@ pub struct SlotName(#[get(method = "name", kind = "deref")] String);
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Slot {
Wildcard,
Equal {
primary: Option<SlotName>,
Equal,
NameEqual {
primary: SlotName,
sub: Option<SlotName>,
},
Name {
@@ -592,10 +593,11 @@ impl fmt::Display for Slot {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Wildcard => write!(f, "*"),
Self::Equal { primary, sub } => {
if let Some(primary) = primary {
write!(f, "{primary}")?;
}
Self::Equal => {
write!(f, "=")
}
Self::NameEqual { primary, sub } => {
write!(f, "{primary}")?;
if let Some(sub) = sub {
write!(f, "/{sub}")?;

View File

@@ -210,16 +210,16 @@ impl<'a> Parseable<'a, &'a str> for Slot {
fn parser() -> Self::Parser {
let wildcard = tag("*").map(|_| Slot::Wildcard);
let equals = SlotName::parser()
.opt()
let equal = tag("=").map(|_| Slot::Equal);
let name_equal = SlotName::parser()
.and(SlotName::parser().preceded_by(tag("/")).opt())
.followed_by(tag("="))
.map(|(primary, sub)| Slot::Equal { primary, sub });
.map(|(primary, sub)| Slot::NameEqual { primary, sub });
let name = SlotName::parser()
.and(SlotName::parser().preceded_by(tag("/")).opt())
.map(|(primary, sub)| Slot::Name { primary, sub });
.map(|(primary, sub)| Self::Name { primary, sub });
wildcard.or(equals).or(name)
wildcard.or(equal).or(name_equal).or(name)
}
}
@@ -585,6 +585,7 @@ mod test {
"<dev-haskell/wai-3.3:=[]",
">=kde-frameworks/kcrash-2.16.0:6*",
"0-f/merreka+m::k+",
"iev-a/h:/n=",
];
for atom in atoms {