git.delta.rocks / jrsonnet / refs/commits / dad8ebd45a7c

difftreelog

fix(types) use absolute paths in macro

Yaroslav Bolyukin2021-01-06parent: #6c57514.patch.diff
in: master

2 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
7};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};
1212
13pub mod stdlib;13pub mod stdlib;
14pub use stdlib::*;14pub use stdlib::*;
33 )33 )
34}34}
35
36thread_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 out
41 };
42}
43
44fn 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}
6135
62#[allow(clippy::cognitive_complexity)]36#[allow(clippy::cognitive_complexity)]
63pub fn call_builtin(37pub fn call_builtin(
modifiedcrates/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)
 	}};
 }