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.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