From dad8ebd45a7c104069d243a6ac01d16074a196fa Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 06 Jan 2021 04:20:41 +0000 Subject: [PATCH] fix(types): use absolute paths in macro --- --- a/crates/jrsonnet-evaluator/src/builtin/mod.rs +++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs @@ -7,8 +7,8 @@ }; use format::{format_arr, format_obj}; use jrsonnet_parser::{ArgsDesc, BinaryOpType, ExprLocation}; -use jrsonnet_types::{ty, ComplexValType, ValType}; -use std::{collections::HashMap, path::PathBuf, rc::Rc}; +use jrsonnet_types::ty; +use std::{path::PathBuf, rc::Rc}; pub mod stdlib; pub use stdlib::*; @@ -31,32 +31,6 @@ }) }, ) -} - -thread_local! { - pub static INTRINSICS: HashMap<&'static str, fn(Context, &Option, &ArgsDesc) -> Result> = { - let mut out: HashMap<&'static str, _> = HashMap::new(); - out.insert("length", intrinsic_length); - out - }; -} - -fn intrinsic_length(context: Context, _loc: &Option, args: &ArgsDesc) -> Result { - Ok(parse_args!(context, "length", args, 1, [ - 0, x: ty!((str | obj | [any])); - ], { - Ok(match x { - Val::Str(n) => Val::Num(n.chars().count() as f64), - Val::Arr(a) => Val::Num(a.len() as f64), - Val::Obj(o) => Val::Num( - o.fields_visibility() - .into_iter() - .filter(|(_k, v)| *v) - .count() as f64, - ), - _ => unreachable!(), - }) - })?) } #[allow(clippy::cognitive_complexity)] --- a/crates/jrsonnet-types/src/lib.rs +++ b/crates/jrsonnet-types/src/lib.rs @@ -3,6 +3,7 @@ #[macro_export] macro_rules! ty { ([$inner:tt]) => {{ + use $crate::{ComplexValType, ValType, ty}; static VAL: &'static ComplexValType = &ty!($inner); match VAL { ComplexValType::Any => ComplexValType::Simple(ValType::Arr), @@ -10,43 +11,43 @@ } }}; (bool) => { - ComplexValType::Simple(ValType::Bool) + $crate::ComplexValType::Simple($crate::ValType::Bool) }; (null) => { - ComplexValType::Simple(ValType::Null) + $crate::ComplexValType::Simple($crate::ValType::Null) }; (str) => { - ComplexValType::Simple(ValType::Str) + $crate::ComplexValType::Simple($crate::ValType::Str) }; (char) => { - ComplexValType::Char + $crate::ComplexValType::Char }; (num) => { - ComplexValType::Simple(ValType::Num) + $crate::ComplexValType::Simple($crate::ValType::Num) }; (number(($min:expr)..($max:expr))) => {{ - ComplexValType::BoundedNumber($min, $max) + $crate::ComplexValType::BoundedNumber($min, $max) }}; (obj) => { - ComplexValType::Simple(ValType::Obj) + $crate::ComplexValType::Simple($crate::ValType::Obj) }; (any) => { - ComplexValType::Any + $crate::ComplexValType::Any }; (fn.any) => { - ComplexValType::Simple(ValType::Func) + $crate::ComplexValType::Simple($crate::ValType::Func) }; (($($a:tt) |+)) => {{ - static CONTENTS: &'static [ComplexValType] = &[ + static CONTENTS: &'static [$crate::ComplexValType] = &[ $(ty!($a)),+ ]; - ComplexValType::UnionRef(CONTENTS) + $crate::ComplexValType::UnionRef(CONTENTS) }}; (($($a:tt) &+)) => {{ - static CONTENTS: &'static [ComplexValType] = &[ + static CONTENTS: &'static [$crate::ComplexValType] = &[ $(ty!($a)),+ ]; - ComplexValType::SumRef(CONTENTS) + $crate::ComplexValType::SumRef(CONTENTS) }}; } -- gitstuff