From a766abda3ec92e07912e8ac6813b0a9f4dc51827 Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Tue, 26 Apr 2022 10:31:39 +0200 Subject: [PATCH] Rename module from action to attr_value --- crates/eww/src/widgets/def_widget_macro.rs | 14 +++++++------- .../yuck/src/config/{action.rs => attr_value.rs} | 0 crates/yuck/src/config/mod.rs | 2 +- crates/yuck/src/format_diagnostic.rs | 2 +- crates/yuck/src/parser/from_ast.rs | 7 +++++-- 5 files changed, 14 insertions(+), 11 deletions(-) rename crates/yuck/src/config/{action.rs => attr_value.rs} (100%) diff --git a/crates/eww/src/widgets/def_widget_macro.rs b/crates/eww/src/widgets/def_widget_macro.rs index 785cc2869..813f641c8 100644 --- a/crates/eww/src/widgets/def_widget_macro.rs +++ b/crates/eww/src/widgets/def_widget_macro.rs @@ -16,7 +16,7 @@ macro_rules! def_widget { // If an attribute is explicitly marked as optional (? appended to type) // the attribute will still show up here, as a `None` value. Otherwise, all values in this map // will be `Some`. - let attr_map: Result>> = try { + let attr_map: Result>> = try { ::maplit::hashmap! { $( eww_shared_util::AttrName(::std::stringify!($attr_name).to_owned()) => @@ -79,14 +79,14 @@ macro_rules! def_widget { (@value_depending_on_type $values:expr, $attr_name:ident : as_action $(? $(@ $optional:tt @)?)? $(= $default:expr)?) => { match $attr_name { - Some(yuck::config::action::AttrValue::Action(action)) => Some(action.eval_exprs(&$values)?), + Some(yuck::config::attr_value::AttrValue::Action(action)) => Some(action.eval_exprs(&$values)?), _ => None, } }; (@value_depending_on_type $values:expr, $attr_name:ident : $typecast_func:ident $(? $(@ $optional:tt @)?)? $(= $default:expr)?) => { match $attr_name { - Some(yuck::config::action::AttrValue::SimplExpr(expr)) => Some(expr.eval(&$values)?.$typecast_func()?), + Some(yuck::config::attr_value::AttrValue::SimplExpr(expr)) => Some(expr.eval(&$values)?.$typecast_func()?), _ => None, } }; @@ -98,18 +98,18 @@ macro_rules! def_widget { // The attribute is explicitly marked as optional - the value should be provided to the prop function body as Option (@get_value $args:ident, $name:expr, ?) => { - $args.widget_use.attrs.ast_optional::($name)?.clone() + $args.widget_use.attrs.ast_optional::($name)?.clone() }; // The attribute has a default value (@get_value $args:ident, $name:expr, = $default:expr) => { - Some($args.widget_use.attrs.ast_optional::($name)? + Some($args.widget_use.attrs.ast_optional::($name)? .clone() - .unwrap_or_else(|| yuck::config::action::AttrValue::SimplExpr(simplexpr::SimplExpr::synth_literal($default)))) + .unwrap_or_else(|| yuck::config::attr_value::AttrValue::SimplExpr(simplexpr::SimplExpr::synth_literal($default)))) }; // The attribute is required - the prop will only be ran if this attribute is actually provided. (@get_value $args:ident, $name:expr,) => { - Some($args.widget_use.attrs.ast_required::($name)?.clone()) + Some($args.widget_use.attrs.ast_required::($name)?.clone()) } } diff --git a/crates/yuck/src/config/action.rs b/crates/yuck/src/config/attr_value.rs similarity index 100% rename from crates/yuck/src/config/action.rs rename to crates/yuck/src/config/attr_value.rs diff --git a/crates/yuck/src/config/mod.rs b/crates/yuck/src/config/mod.rs index 7e4638727..e91ca3b06 100644 --- a/crates/yuck/src/config/mod.rs +++ b/crates/yuck/src/config/mod.rs @@ -1,4 +1,4 @@ -pub mod action; +pub mod attr_value; pub mod attributes; pub mod backend_window_options; pub mod config; diff --git a/crates/yuck/src/format_diagnostic.rs b/crates/yuck/src/format_diagnostic.rs index 3730e14d1..cfd076a6f 100644 --- a/crates/yuck/src/format_diagnostic.rs +++ b/crates/yuck/src/format_diagnostic.rs @@ -99,7 +99,7 @@ impl ToDiagnostic for AstError { AstError::UnknownAction(span, actual) => gen_diagnostic! { msg = format!("Unknown action `{}`", actual), label = span, - note = format!("Must be one of: {}", crate::config::action::ACTION_NAMES.iter().join(", ")), + note = format!("Must be one of: {}", crate::config::attr_value::ACTION_NAMES.iter().join(", ")), }, AstError::ParseError { file_id, source } => lalrpop_error_to_diagnostic(source, *file_id), diff --git a/crates/yuck/src/parser/from_ast.rs b/crates/yuck/src/parser/from_ast.rs index 2138d3cec..65c999ce4 100644 --- a/crates/yuck/src/parser/from_ast.rs +++ b/crates/yuck/src/parser/from_ast.rs @@ -2,7 +2,11 @@ use super::{ ast::{Ast, AstType}, ast_iterator::AstIterator, }; -use crate::{config::action::AttrValue, error::*, parser}; +use crate::{ + config::attr_value::{Action, AttrValue}, + error::*, + parser, +}; use eww_shared_util::{AttrName, Span, VarName}; use itertools::Itertools; use simplexpr::{ast::SimplExpr, dynval::DynVal}; @@ -57,7 +61,6 @@ impl FromAst for SimplExpr { } } -use crate::config::action::Action; impl FromAst for Action { fn from_ast(e: Ast) -> AstResult { let mut iter = e.try_ast_iter()?;