mirror of
https://github.com/Zenithsiz/zbuild.git
synced 2026-02-03 14:10:02 +00:00
Removed pattern operations.
This commit is contained in:
parent
37b74daae6
commit
910dbedb59
46
src/ast.rs
46
src/ast.rs
@ -166,19 +166,8 @@ pub struct Pattern<'a> {
|
||||
/// Pattern name
|
||||
pub name: &'a str,
|
||||
|
||||
/// Pattern operators
|
||||
pub ops: Vec<PatternOp>,
|
||||
}
|
||||
|
||||
/// Pattern operator
|
||||
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
|
||||
#[expect(
|
||||
missing_copy_implementations,
|
||||
reason = "We might add non-`Copy` fields in the future"
|
||||
)]
|
||||
pub enum PatternOp {
|
||||
/// Non-empty
|
||||
NonEmpty,
|
||||
pub non_empty: bool,
|
||||
}
|
||||
|
||||
/// Alias
|
||||
@ -212,14 +201,10 @@ impl serde::Serialize for Expr<'_> {
|
||||
.iter()
|
||||
.map(|cmpt| match *cmpt {
|
||||
ExprCmpt::String(s) => s.to_owned(),
|
||||
ExprCmpt::Pattern(Pattern { name, ref ops }) => format!(
|
||||
"^({name}{})",
|
||||
ops.iter()
|
||||
.map(|op| format!("::{}", match op {
|
||||
PatternOp::NonEmpty => "non_empty",
|
||||
}))
|
||||
.join("")
|
||||
),
|
||||
ExprCmpt::Pattern(Pattern { name, non_empty }) => match non_empty {
|
||||
true => format!("^({name}::non_empty)"),
|
||||
false => format!("^({name})"),
|
||||
},
|
||||
ExprCmpt::Alias(Alias { name, ref ops }) => format!(
|
||||
"$({name}{})",
|
||||
ops.iter()
|
||||
@ -300,16 +285,17 @@ impl<'a, 'de: 'a> serde::Deserialize<'de> for Expr<'a> {
|
||||
})
|
||||
.collect::<Result<_, _>>()?,
|
||||
}),
|
||||
Kind::Pattern => ExprCmpt::Pattern(Pattern {
|
||||
name,
|
||||
ops: ops
|
||||
.into_iter()
|
||||
.map(|op| match op.trim() {
|
||||
"non_empty" => Ok(PatternOp::NonEmpty),
|
||||
op => Err(D::Error::custom(format!("Unknown pattern operator {op:?}"))),
|
||||
})
|
||||
.collect::<Result<_, _>>()?,
|
||||
}),
|
||||
Kind::Pattern => {
|
||||
let mut non_empty = false;
|
||||
for op in ops {
|
||||
match op.trim() {
|
||||
"non_empty" => non_empty = true,
|
||||
op => return Err(D::Error::custom(format!("Unknown pattern operator {op:?}"))),
|
||||
}
|
||||
}
|
||||
|
||||
ExprCmpt::Pattern(Pattern { name, non_empty })
|
||||
},
|
||||
};
|
||||
cmpts.push(cmpt);
|
||||
},
|
||||
|
||||
@ -13,7 +13,6 @@ pub use {
|
||||
alias::AliasOp,
|
||||
expr::{Expr, ExprCmpt, ExprTree},
|
||||
item::{DepItem, OutItem},
|
||||
pattern::PatternOp,
|
||||
rule::{Command, Exec, Rule},
|
||||
target::Target,
|
||||
};
|
||||
|
||||
@ -10,7 +10,7 @@ pub use self::expr_tree::ExprTree;
|
||||
use {
|
||||
super::{
|
||||
alias::{Alias, AliasOp},
|
||||
pattern::{Pattern, PatternOp},
|
||||
pattern::Pattern,
|
||||
},
|
||||
crate::{ast, util::ArcStr},
|
||||
std::fmt,
|
||||
@ -148,14 +148,9 @@ impl Expr {
|
||||
.into_iter()
|
||||
.map(|cmpt| match cmpt {
|
||||
ast::ExprCmpt::String(s) => ExprCmpt::String(zbuild_file.slice_from_str(s)),
|
||||
ast::ExprCmpt::Pattern(ast::Pattern { name, ops }) => ExprCmpt::Pattern(Pattern {
|
||||
ast::ExprCmpt::Pattern(ast::Pattern { name, non_empty }) => ExprCmpt::Pattern(Pattern {
|
||||
name: zbuild_file.slice_from_str(name),
|
||||
ops: ops
|
||||
.into_iter()
|
||||
.map(|op| match op {
|
||||
ast::PatternOp::NonEmpty => PatternOp::NonEmpty,
|
||||
})
|
||||
.collect(),
|
||||
non_empty,
|
||||
}),
|
||||
ast::ExprCmpt::Alias(ast::Alias { name, ops }) => ExprCmpt::Alias(Alias {
|
||||
name: zbuild_file.slice_from_str(name),
|
||||
|
||||
@ -2,11 +2,7 @@
|
||||
|
||||
use {
|
||||
super::Expr,
|
||||
crate::{
|
||||
error::AppError,
|
||||
rules::{pattern::Pattern, PatternOp},
|
||||
util::ArcStr,
|
||||
},
|
||||
crate::{error::AppError, rules::pattern::Pattern, util::ArcStr},
|
||||
itertools::{Itertools, PeekingNext},
|
||||
std::collections::BTreeMap,
|
||||
};
|
||||
@ -138,14 +134,8 @@ impl<K> ExprTree<K> {
|
||||
let pats = match pat {
|
||||
// If there is any pattern, try to match it
|
||||
Some(pat) => {
|
||||
for op in &pat.ops {
|
||||
match op {
|
||||
// If it needs to be non-empty, check
|
||||
PatternOp::NonEmpty =>
|
||||
if value.is_empty() {
|
||||
return None;
|
||||
},
|
||||
}
|
||||
if pat.non_empty && value.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
BTreeMap::from([(pat.name.clone(), value.into())])
|
||||
|
||||
@ -9,23 +9,16 @@ pub struct Pattern {
|
||||
/// Pattern name
|
||||
pub name: ArcStr,
|
||||
|
||||
/// Operators
|
||||
pub ops: Vec<PatternOp>,
|
||||
}
|
||||
|
||||
/// Pattern operator
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash, Debug)]
|
||||
pub enum PatternOp {
|
||||
/// Non-empty
|
||||
NonEmpty,
|
||||
pub non_empty: bool,
|
||||
}
|
||||
|
||||
impl fmt::Display for Pattern {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "^({}", self.name)?;
|
||||
|
||||
for op in &self.ops {
|
||||
write!(f, "::{op}")?;
|
||||
if self.non_empty {
|
||||
write!(f, "::non_empty")?;
|
||||
}
|
||||
|
||||
write!(f, ")")?;
|
||||
@ -34,11 +27,3 @@ impl fmt::Display for Pattern {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for PatternOp {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::NonEmpty => write!(f, "non_empty"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user