mirror of
https://github.com/Zenithsiz/zbuild.git
synced 2026-02-05 07:05:53 +00:00
Addressed some TODOs in ast::Expr deserialization.
This commit is contained in:
parent
c41f53a7f5
commit
ef2cf4a70c
21
src/ast.rs
21
src/ast.rs
@ -1,9 +1,12 @@
|
||||
//! Ast
|
||||
|
||||
// Imports
|
||||
use {serde::de::Error, std::collections::HashMap};
|
||||
use {
|
||||
serde::de::Error,
|
||||
std::{borrow::Cow, collections::HashMap},
|
||||
};
|
||||
|
||||
/// Ast
|
||||
/// Zbuild ast
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct Ast {
|
||||
@ -82,13 +85,11 @@ impl<'de> serde::Deserialize<'de> for Expr {
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
// Parse the string
|
||||
// TODO: Allow arrays and concat them?
|
||||
// TODO: Deserialize a `Cow<str>`?
|
||||
let inner = String::deserialize(deserializer)?;
|
||||
let inner = Cow::<str>::deserialize(deserializer)?;
|
||||
|
||||
// Then parse all components
|
||||
let mut cmpts = vec![];
|
||||
let mut rest = inner.as_str();
|
||||
let mut rest = &*inner;
|
||||
loop {
|
||||
// Try to find the next pattern / alias
|
||||
match rest.find(['$', '^']) {
|
||||
@ -131,7 +132,7 @@ impl<'de> serde::Deserialize<'de> for Expr {
|
||||
None => (inner, vec![]),
|
||||
};
|
||||
|
||||
|
||||
// Finally check what it was originally and parse all operations
|
||||
let cmpt = match kind {
|
||||
Kind::Alias => ExprCmpt::Alias {
|
||||
name: name.to_owned(),
|
||||
@ -177,14 +178,12 @@ impl<'de> serde::Deserialize<'de> for Expr {
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct Rule {
|
||||
/// Aliases
|
||||
#[serde(rename = "alias")]
|
||||
#[serde(default)]
|
||||
pub aliases: HashMap<String, Expr>,
|
||||
pub alias: HashMap<String, Expr>,
|
||||
|
||||
/// Output items
|
||||
#[serde(rename = "out")]
|
||||
#[serde(default)]
|
||||
pub output: Vec<Item>,
|
||||
pub out: Vec<Item>,
|
||||
|
||||
/// Dependencies
|
||||
#[serde(default)]
|
||||
|
||||
@ -37,11 +37,11 @@ impl Rule<Expr> {
|
||||
/// Creates a new rule from it's ast
|
||||
pub fn new(name: String, rule: ast::Rule) -> Self {
|
||||
let aliases = rule
|
||||
.aliases
|
||||
.alias
|
||||
.into_iter()
|
||||
.map(|(name, expr)| (name, Expr::new(expr)))
|
||||
.collect();
|
||||
let output = rule.output.into_iter().map(Item::new).collect();
|
||||
let output = rule.out.into_iter().map(Item::new).collect();
|
||||
let deps = rule.deps.into_iter().map(Item::new).collect();
|
||||
let static_deps = rule.static_deps.into_iter().map(Item::new).collect();
|
||||
let exec_cwd = rule.exec_cwd.map(Expr::new);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user