difftreelog
fix(types) use absolute paths in macro
in: master
2 files changed
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth7};7};8use format::{format_arr, format_obj};8use format::{format_arr, format_obj};9use jrsonnet_parser::{ArgsDesc, BinaryOpType, ExprLocation};9use jrsonnet_parser::{ArgsDesc, BinaryOpType, ExprLocation};10use jrsonnet_types::{ty, ComplexValType, ValType};10use jrsonnet_types::ty;11use std::{collections::HashMap, path::PathBuf, rc::Rc};11use std::{path::PathBuf, rc::Rc};121213pub mod stdlib;13pub mod stdlib;14pub use stdlib::*;14pub use stdlib::*;33 )33 )34}34}3536thread_local! {37 pub static INTRINSICS: HashMap<&'static str, fn(Context, &Option<ExprLocation>, &ArgsDesc) -> Result<Val>> = {38 let mut out: HashMap<&'static str, _> = HashMap::new();39 out.insert("length", intrinsic_length);40 out41 };42}4344fn intrinsic_length(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {45 Ok(parse_args!(context, "length", args, 1, [46 0, x: ty!((str | obj | [any]));47 ], {48 Ok(match x {49 Val::Str(n) => Val::Num(n.chars().count() as f64),50 Val::Arr(a) => Val::Num(a.len() as f64),51 Val::Obj(o) => Val::Num(52 o.fields_visibility()53 .into_iter()54 .filter(|(_k, v)| *v)55 .count() as f64,56 ),57 _ => unreachable!(),58 })59 })?)60}613562#[allow(clippy::cognitive_complexity)]36#[allow(clippy::cognitive_complexity)]63pub fn call_builtin(37pub fn call_builtin(crates/jrsonnet-types/src/lib.rsdiffbeforeafterboth--- 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)
}};
}