difftreelog
fix(types) use absolute paths in macro
in: master
2 files changed
crates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth--- 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<ExprLocation>, &ArgsDesc) -> Result<Val>> = {
- let mut out: HashMap<&'static str, _> = HashMap::new();
- out.insert("length", intrinsic_length);
- out
- };
-}
-
-fn intrinsic_length(context: Context, _loc: &Option<ExprLocation>, args: &ArgsDesc) -> Result<Val> {
- 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)]
crates/jrsonnet-types/src/lib.rsdiffbeforeafterboth3#[macro_export]3#[macro_export]4macro_rules! ty {4macro_rules! ty {5 ([$inner:tt]) => {{5 ([$inner:tt]) => {{6 use $crate::{ComplexValType, ValType, ty};6 static VAL: &'static ComplexValType = &ty!($inner);7 static VAL: &'static ComplexValType = &ty!($inner);7 match VAL {8 match VAL {8 ComplexValType::Any => ComplexValType::Simple(ValType::Arr),9 ComplexValType::Any => ComplexValType::Simple(ValType::Arr),9 _ => ComplexValType::ArrayRef(&VAL),10 _ => ComplexValType::ArrayRef(&VAL),10 }11 }11 }};12 }};12 (bool) => {13 (bool) => {13 ComplexValType::Simple(ValType::Bool)14 $crate::ComplexValType::Simple($crate::ValType::Bool)14 };15 };15 (null) => {16 (null) => {16 ComplexValType::Simple(ValType::Null)17 $crate::ComplexValType::Simple($crate::ValType::Null)17 };18 };18 (str) => {19 (str) => {19 ComplexValType::Simple(ValType::Str)20 $crate::ComplexValType::Simple($crate::ValType::Str)20 };21 };21 (char) => {22 (char) => {22 ComplexValType::Char23 $crate::ComplexValType::Char23 };24 };24 (num) => {25 (num) => {25 ComplexValType::Simple(ValType::Num)26 $crate::ComplexValType::Simple($crate::ValType::Num)26 };27 };27 (number(($min:expr)..($max:expr))) => {{28 (number(($min:expr)..($max:expr))) => {{28 ComplexValType::BoundedNumber($min, $max)29 $crate::ComplexValType::BoundedNumber($min, $max)29 }};30 }};30 (obj) => {31 (obj) => {31 ComplexValType::Simple(ValType::Obj)32 $crate::ComplexValType::Simple($crate::ValType::Obj)32 };33 };33 (any) => {34 (any) => {34 ComplexValType::Any35 $crate::ComplexValType::Any35 };36 };36 (fn.any) => {37 (fn.any) => {37 ComplexValType::Simple(ValType::Func)38 $crate::ComplexValType::Simple($crate::ValType::Func)38 };39 };39 (($($a:tt) |+)) => {{40 (($($a:tt) |+)) => {{40 static CONTENTS: &'static [ComplexValType] = &[41 static CONTENTS: &'static [$crate::ComplexValType] = &[41 $(ty!($a)),+42 $(ty!($a)),+42 ];43 ];43 ComplexValType::UnionRef(CONTENTS)44 $crate::ComplexValType::UnionRef(CONTENTS)44 }};45 }};45 (($($a:tt) &+)) => {{46 (($($a:tt) &+)) => {{46 static CONTENTS: &'static [ComplexValType] = &[47 static CONTENTS: &'static [$crate::ComplexValType] = &[47 $(ty!($a)),+48 $(ty!($a)),+48 ];49 ];49 ComplexValType::SumRef(CONTENTS)50 $crate::ComplexValType::SumRef(CONTENTS)50 }};51 }};51}52}5253