Skip to content

Commit

Permalink
Rename module from action to attr_value
Browse files Browse the repository at this point in the history
  • Loading branch information
elkowar committed Apr 26, 2022
1 parent 4f7a756 commit cda2378
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
14 changes: 7 additions & 7 deletions crates/eww/src/widgets/def_widget_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HashMap<eww_shared_util::AttrName, Option<yuck::config::action::AttrValue>>> = try {
let attr_map: Result<HashMap<eww_shared_util::AttrName, Option<yuck::config::attr_value::AttrValue>>> = try {
::maplit::hashmap! {
$(
eww_shared_util::AttrName(::std::stringify!($attr_name).to_owned()) =>
Expand Down Expand Up @@ -78,14 +78,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,
}
};
Expand All @@ -97,18 +97,18 @@ macro_rules! def_widget {

// The attribute is explicitly marked as optional - the value should be provided to the prop function body as Option<T>
(@get_value $args:ident, $name:expr, ?) => {
$args.widget_use.attrs.ast_optional::<yuck::config::action::AttrValue>($name)?.clone()
$args.widget_use.attrs.ast_optional::<yuck::config::attr_value::AttrValue>($name)?.clone()
};

// The attribute has a default value
(@get_value $args:ident, $name:expr, = $default:expr) => {
Some($args.widget_use.attrs.ast_optional::<yuck::config::action::AttrValue>($name)?
Some($args.widget_use.attrs.ast_optional::<yuck::config::attr_value::AttrValue>($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::<yuck::config::action::AttrValue>($name)?.clone())
Some($args.widget_use.attrs.ast_required::<yuck::config::attr_value::AttrValue>($name)?.clone())
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion crates/yuck/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod action;
pub mod attr_value;
pub mod attributes;
pub mod backend_window_options;
pub mod config;
Expand Down
2 changes: 1 addition & 1 deletion crates/yuck/src/format_diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 5 additions & 2 deletions crates/yuck/src/parser/from_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -57,7 +61,6 @@ impl FromAst for SimplExpr {
}
}

use crate::config::action::Action;
impl FromAst for Action {
fn from_ast(e: Ast) -> AstResult<Self> {
let mut iter = e.try_ast_iter()?;
Expand Down

0 comments on commit cda2378

Please sign in to comment.