git.delta.rocks / jrsonnet / refs/commits / 80f37a416bf7

difftreelog

style enforce import style

Yaroslav Bolyukin2022-04-20parent: #4c00868.patch.diff
in: master

38 files changed

modified.rustfmt.tomldiffbeforeafterboth
--- a/.rustfmt.toml
+++ b/.rustfmt.toml
@@ -1 +1,3 @@
 hard_tabs = true
+imports_granularity = "crate"
+group_imports = "stdexternalcrate"
modifiedbindings/jsonnet/src/import.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/import.rs
+++ b/bindings/jsonnet/src/import.rs
@@ -1,9 +1,5 @@
 //! Import resolution manipulation utilities
 
-use jrsonnet_evaluator::{
-	error::{Error::*, Result},
-	throw, EvaluationState, ImportResolver,
-};
 use std::{
 	any::Any,
 	cell::RefCell,
@@ -17,6 +13,11 @@
 	rc::Rc,
 };
 
+use jrsonnet_evaluator::{
+	error::{Error::*, Result},
+	throw, EvaluationState, ImportResolver,
+};
+
 pub type JsonnetImportCallback = unsafe extern "C" fn(
 	ctx: *mut c_void,
 	base: *const c_char,
modifiedbindings/jsonnet/src/interop.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/interop.rs
+++ b/bindings/jsonnet/src/interop.rs
@@ -1,12 +1,14 @@
 //! Jrsonnet specific additional binding helpers
 
-use crate::{import::jsonnet_import_callback, native::jsonnet_native_callback};
-use jrsonnet_evaluator::{EvaluationState, Val};
 use std::{
 	ffi::c_void,
 	os::raw::{c_char, c_int},
 };
 
+use jrsonnet_evaluator::{EvaluationState, Val};
+
+use crate::{import::jsonnet_import_callback, native::jsonnet_native_callback};
+
 extern "C" {
 	pub fn _jrsonnet_static_import_callback(
 		ctx: *mut c_void,
modifiedbindings/jsonnet/src/lib.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/lib.rs
+++ b/bindings/jsonnet/src/lib.rs
@@ -8,8 +8,6 @@
 pub mod val_modify;
 pub mod vars_tlas;
 
-use import::NativeImportResolver;
-use jrsonnet_evaluator::{EvaluationState, IStr, ManifestFormat, Val};
 use std::{
 	alloc::Layout,
 	ffi::{CStr, CString},
@@ -17,6 +15,9 @@
 	path::PathBuf,
 };
 
+use import::NativeImportResolver;
+use jrsonnet_evaluator::{EvaluationState, IStr, ManifestFormat, Val};
+
 /// WASM stub
 #[cfg(target_arch = "wasm32")]
 #[no_mangle]
modifiedbindings/jsonnet/src/native.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/native.rs
+++ b/bindings/jsonnet/src/native.rs
@@ -1,3 +1,11 @@
+use std::{
+	convert::TryFrom,
+	ffi::{c_void, CStr},
+	os::raw::{c_char, c_int},
+	path::Path,
+	rc::Rc,
+};
+
 use gcmodule::Cc;
 use jrsonnet_evaluator::{
 	error::{Error, LocError},
@@ -5,13 +13,6 @@
 	gc::TraceBox,
 	native::{NativeCallback, NativeCallbackHandler},
 	EvaluationState, IStr, Val,
-};
-use std::{
-	convert::TryFrom,
-	ffi::{c_void, CStr},
-	os::raw::{c_char, c_int},
-	path::Path,
-	rc::Rc,
 };
 
 type JsonnetNativeCallback = unsafe extern "C" fn(
modifiedbindings/jsonnet/src/val_extract.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_extract.rs
+++ b/bindings/jsonnet/src/val_extract.rs
@@ -1,12 +1,12 @@
 //! Extract values from VM
 
-use jrsonnet_evaluator::{EvaluationState, Val};
-
 use std::{
 	ffi::CString,
 	os::raw::{c_char, c_double, c_int},
 };
 
+use jrsonnet_evaluator::{EvaluationState, Val};
+
 #[no_mangle]
 pub extern "C" fn jsonnet_json_extract_string(_vm: &EvaluationState, v: &Val) -> *mut c_char {
 	match v {
modifiedbindings/jsonnet/src/val_make.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_make.rs
+++ b/bindings/jsonnet/src/val_make.rs
@@ -1,12 +1,13 @@
 //! Create values in VM
 
-use gcmodule::Cc;
-use jrsonnet_evaluator::{ArrValue, EvaluationState, ObjValue, Val};
 use std::{
 	ffi::CStr,
 	os::raw::{c_char, c_double, c_int},
 };
 
+use gcmodule::Cc;
+use jrsonnet_evaluator::{val::ArrValue, EvaluationState, ObjValue, Val};
+
 /// # Safety
 ///
 /// This function is safe, if received v is a pointer to normal C string
modifiedbindings/jsonnet/src/val_modify.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/val_modify.rs
+++ b/bindings/jsonnet/src/val_modify.rs
@@ -2,10 +2,11 @@
 //! Only tested with variables, which haven't altered by code before appearing here
 //! In jrsonnet every value is immutable, and this code is probally broken
 
+use std::{ffi::CStr, os::raw::c_char};
+
 use gcmodule::Cc;
-use jrsonnet_evaluator::{ArrValue, EvaluationState, LazyBinding, LazyVal, ObjMember, Val};
+use jrsonnet_evaluator::{val::ArrValue, EvaluationState, LazyBinding, LazyVal, ObjMember, Val};
 use jrsonnet_parser::Visibility;
-use std::{ffi::CStr, os::raw::c_char};
 
 /// # Safety
 ///
modifiedbindings/jsonnet/src/vars_tlas.rsdiffbeforeafterboth
--- a/bindings/jsonnet/src/vars_tlas.rs
+++ b/bindings/jsonnet/src/vars_tlas.rs
@@ -1,8 +1,9 @@
 //! Manipulate external variables and top level arguments
 
-use jrsonnet_evaluator::EvaluationState;
 use std::{ffi::CStr, os::raw::c_char};
 
+use jrsonnet_evaluator::EvaluationState;
+
 /// # Safety
 #[no_mangle]
 pub unsafe extern "C" fn jsonnet_ext_var(
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
--- a/cmds/jrsonnet/src/main.rs
+++ b/cmds/jrsonnet/src/main.rs
@@ -1,13 +1,13 @@
+use std::{
+	fs::{create_dir_all, File},
+	io::{Read, Write},
+	path::PathBuf,
+};
+
 use clap::{AppSettings, IntoApp, Parser};
 use clap_complete::Shell;
 use jrsonnet_cli::{ConfigureState, GcOpts, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};
 use jrsonnet_evaluator::{error::LocError, EvaluationState};
-use std::{
-	fs::{create_dir_all, File},
-	io::Read,
-	io::Write,
-	path::PathBuf,
-};
 
 #[cfg(feature = "mimalloc")]
 #[global_allocator]
modifiedcrates/jrsonnet-cli/src/ext.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/ext.rs
+++ b/crates/jrsonnet-cli/src/ext.rs
@@ -1,8 +1,10 @@
-use crate::ConfigureState;
+use std::{fs::read_to_string, str::FromStr};
+
 use clap::Parser;
 use jrsonnet_evaluator::{error::Result, EvaluationState};
-use std::{fs::read_to_string, str::FromStr};
 
+use crate::ConfigureState;
+
 #[derive(Clone)]
 pub struct ExtStr {
 	pub name: String,
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/lib.rs
+++ b/crates/jrsonnet-cli/src/lib.rs
@@ -3,14 +3,14 @@
 mod tla;
 mod trace;
 
+use std::{env, path::PathBuf};
+
+use clap::Parser;
 pub use ext::*;
+use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};
 pub use manifest::*;
 pub use tla::*;
 pub use trace::*;
-
-use clap::Parser;
-use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};
-use std::{env, path::PathBuf};
 
 pub trait ConfigureState {
 	fn configure(&self, state: &EvaluationState) -> Result<()>;
modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -1,8 +1,10 @@
-use crate::ConfigureState;
+use std::{path::PathBuf, str::FromStr};
+
 use clap::Parser;
 use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};
-use std::{path::PathBuf, str::FromStr};
 
+use crate::ConfigureState;
+
 pub enum ManifestFormatName {
 	/// Expect string as output, and write them directly
 	String,
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/tla.rs
+++ b/crates/jrsonnet-cli/src/tla.rs
@@ -1,7 +1,8 @@
-use crate::{ConfigureState, ExtFile, ExtStr};
 use clap::Parser;
 use jrsonnet_evaluator::{error::Result, EvaluationState};
 
+use crate::{ConfigureState, ExtFile, ExtStr};
+
 #[derive(Parser)]
 #[clap(next_help_heading = "TOP LEVEL ARGUMENTS")]
 pub struct TLAOpts {
modifiedcrates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/trace.rs
+++ b/crates/jrsonnet-cli/src/trace.rs
@@ -1,12 +1,14 @@
-use crate::ConfigureState;
+use std::str::FromStr;
+
 use clap::Parser;
 use jrsonnet_evaluator::{
 	error::Result,
 	trace::{CompactFormat, ExplainingFormat, PathResolver},
 	EvaluationState,
 };
-use std::str::FromStr;
 
+use crate::ConfigureState;
+
 #[derive(PartialEq)]
 pub enum TraceFormatName {
 	Compact,
modifiedcrates/jrsonnet-evaluator/build.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/build.rs
+++ b/crates/jrsonnet-evaluator/build.rs
@@ -1,6 +1,3 @@
-use bincode::serialize;
-use jrsonnet_parser::{parse, ParserSettings};
-use jrsonnet_stdlib::STDLIB_STR;
 use std::{
 	env,
 	fs::File,
@@ -8,6 +5,10 @@
 	path::{Path, PathBuf},
 };
 
+use bincode::serialize;
+use jrsonnet_parser::{parse, ParserSettings};
+use jrsonnet_stdlib::STDLIB_STR;
+
 fn main() {
 	let parsed = parse(
 		STDLIB_STR,
modifiedcrates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/format.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/format.rs
@@ -1,13 +1,15 @@
 //! faster std.format impl
 #![allow(clippy::too_many_arguments)]
 
-use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};
+use std::convert::TryFrom;
+
 use gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_types::ValType;
-use std::convert::TryFrom;
 use thiserror::Error;
 
+use crate::{error::Error::*, throw, LocError, ObjValue, Result, Val};
+
 #[derive(Debug, Clone, Error, Trace)]
 pub enum FormatError {
 	#[error("truncated format code")]
modifiedcrates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/manifest.rs
@@ -1,7 +1,7 @@
-use crate::error::Error::*;
-use crate::error::Result;
-use crate::push_description_frame;
-use crate::{throw, Val};
+use crate::{
+	error::{Error::*, Result},
+	push_description_frame, throw, Val,
+};
 
 #[derive(PartialEq, Clone, Copy)]
 pub enum ManifestType {
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/mod.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/mod.rs
@@ -1,23 +1,25 @@
-use crate::function::{CallLocation, StaticBuiltin};
-use crate::typed::{Any, Bytes, PositiveF64, VecVal, M1};
-use crate::{
-	builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},
-	equals,
-	error::{Error::*, Result},
-	operator::evaluate_mod_op,
-	primitive_equals, push_frame, throw,
-	typed::{Either2, Either4},
-	with_state, ArrValue, FuncVal, IndexableVal, Val,
+use std::{
+	collections::HashMap,
+	convert::{TryFrom, TryInto},
 };
-use crate::{Either, ObjValue};
+
 use format::{format_arr, format_obj};
 use gcmodule::Cc;
 use jrsonnet_interner::IStr;
 use serde::Deserialize;
 use serde_yaml::DeserializingQuirks;
-use std::collections::HashMap;
-use std::convert::{TryFrom, TryInto};
 
+use crate::{
+	builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},
+	error::{Error::*, Result},
+	function::{CallLocation, StaticBuiltin},
+	operator::evaluate_mod_op,
+	push_frame, throw,
+	typed::{Any, BoundedUsize, Bytes, Either2, Either4, PositiveF64, VecVal, M1},
+	val::{equals, primitive_equals, ArrValue, FuncVal, IndexableVal, Slice},
+	with_state, Either, ObjValue, Val,
+};
+
 pub mod stdlib;
 pub use stdlib::*;
 
@@ -58,12 +60,12 @@
 			}
 
 			Ok(Val::Str(
-			(s.chars()
-				.skip(index)
-				.take(end - index)
-				.step_by(step)
-				.collect::<String>())
-			.into(),
+				(s.chars()
+					.skip(index)
+					.take(end - index)
+					.step_by(step)
+					.collect::<String>())
+				.into(),
 			))
 		}
 		IndexableVal::Arr(arr) => {
modifiedcrates/jrsonnet-evaluator/src/builtin/sort.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/sort.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/sort.rs
@@ -1,10 +1,12 @@
+use gcmodule::{Cc, Trace};
+
 use crate::{
 	error::{Error, LocError, Result},
 	throw,
 	typed::Any,
-	FuncVal, Val,
+	val::FuncVal,
+	Val,
 };
-use gcmodule::{Cc, Trace};
 
 #[derive(Debug, Clone, thiserror::Error, Trace)]
 pub enum SortError {
modifiedcrates/jrsonnet-evaluator/src/builtin/stdlib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/stdlib.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/stdlib.rs
@@ -1,6 +1,7 @@
-use jrsonnet_parser::{LocExpr, ParserSettings};
 use std::path::PathBuf;
 
+use jrsonnet_parser::{LocExpr, ParserSettings};
+
 thread_local! {
 	/// To avoid parsing again when issued from the same thread
 	#[allow(unreachable_code)]
modifiedcrates/jrsonnet-evaluator/src/ctx.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/ctx.rs
+++ b/crates/jrsonnet-evaluator/src/ctx.rs
@@ -1,12 +1,12 @@
-use crate::cc_ptr_eq;
-use crate::gc::GcHashMap;
+use std::fmt::Debug;
+
+use gcmodule::{Cc, Trace};
+use jrsonnet_interner::IStr;
+
 use crate::{
-	error::Error::*, map::LayeredHashMap, FutureWrapper, LazyBinding, LazyVal, ObjValue, Result,
-	Val,
+	cc_ptr_eq, error::Error::*, gc::GcHashMap, map::LayeredHashMap, FutureWrapper, LazyBinding,
+	LazyVal, ObjValue, Result, Val,
 };
-use gcmodule::{Cc, Trace};
-use jrsonnet_interner::IStr;
-use std::fmt::Debug;
 
 #[derive(Clone, Trace)]
 pub struct ContextCreator(pub Context, pub FutureWrapper<GcHashMap<IStr, LazyBinding>>);
modifiedcrates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/error.rs
+++ b/crates/jrsonnet-evaluator/src/error.rs
@@ -1,16 +1,18 @@
-use crate::{
-	builtin::{format::FormatError, sort::SortError},
-	typed::TypeLocError,
+use std::{
+	path::{Path, PathBuf},
+	rc::Rc,
 };
+
 use gcmodule::Trace;
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};
 use jrsonnet_types::ValType;
-use std::{
-	path::{Path, PathBuf},
-	rc::Rc,
+use thiserror::Error;
+
+use crate::{
+	builtin::{format::FormatError, sort::SortError},
+	typed::TypeLocError,
 };
-use thiserror::Error;
 
 #[derive(Error, Debug, Clone, Trace)]
 pub enum Error {
modifiedcrates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs
@@ -1,15 +1,5 @@
 use std::convert::TryFrom;
 
-use crate::{
-	builtin::{std_slice, BUILTINS},
-	error::Error::*,
-	evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},
-	function::CallLocation,
-	gc::TraceBox,
-	push_frame, throw, with_state, ArrValue, Bindable, Context, ContextCreator, FuncDesc, FuncVal,
-	FutureWrapper, GcHashMap, LazyBinding, LazyVal, LazyValValue, ObjValue, ObjValueBuilder,
-	ObjectAssertion, Result, Val,
-};
 use gcmodule::{Cc, Trace};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{
@@ -17,6 +7,19 @@
 	LiteralType, LocExpr, Member, ObjBody, ParamsDesc,
 };
 use jrsonnet_types::ValType;
+
+use crate::{
+	builtin::{std_slice, BUILTINS},
+	error::Error::*,
+	evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},
+	function::CallLocation,
+	gc::TraceBox,
+	push_frame, throw,
+	typed::BoundedUsize,
+	val::{ArrValue, FuncDesc, FuncVal, LazyValValue},
+	with_state, Bindable, Context, ContextCreator, FutureWrapper, GcHashMap, LazyBinding, LazyVal,
+	ObjValue, ObjValueBuilder, ObjectAssertion, Result, Val,
+};
 pub mod operator;
 
 pub fn evaluate_binding_in_future(
modifiedcrates/jrsonnet-evaluator/src/evaluate/operator.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/evaluate/operator.rs
+++ b/crates/jrsonnet-evaluator/src/evaluate/operator.rs
@@ -1,10 +1,11 @@
 use std::convert::TryInto;
 
-use crate::builtin::std_format;
-use crate::{equals, evaluate, Context, Val};
-use crate::{error::Error::*, throw, Result};
 use jrsonnet_parser::{BinaryOpType, LocExpr, UnaryOpType};
 
+use crate::{
+	builtin::std_format, error::Error::*, evaluate, throw, val::equals, Context, Result, Val,
+};
+
 pub fn evaluate_unary_op(op: UnaryOpType, b: &Val) -> Result<Val> {
 	use UnaryOpType::*;
 	use Val::*;
modifiedcrates/jrsonnet-evaluator/src/function.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/function.rs
+++ b/crates/jrsonnet-evaluator/src/function.rs
@@ -1,16 +1,19 @@
+use std::{borrow::Cow, collections::HashMap, convert::TryFrom};
+
+use gcmodule::Trace;
+use jrsonnet_interner::IStr;
+pub use jrsonnet_macros::builtin;
+use jrsonnet_parser::{ArgsDesc, ExprLocation, LocExpr, ParamsDesc};
+
 use crate::{
 	error::{Error::*, LocError},
 	evaluate, evaluate_named,
 	gc::TraceBox,
 	throw,
 	typed::Typed,
-	Context, FutureWrapper, GcHashMap, LazyVal, LazyValValue, Result, Val,
+	val::LazyValValue,
+	Context, FutureWrapper, GcHashMap, LazyVal, Result, Val,
 };
-use gcmodule::Trace;
-use jrsonnet_interner::IStr;
-pub use jrsonnet_macros::builtin;
-use jrsonnet_parser::{ArgsDesc, ExprLocation, LocExpr, ParamsDesc};
-use std::{borrow::Cow, collections::HashMap, convert::TryFrom};
 
 #[derive(Clone, Copy)]
 pub struct CallLocation<'l>(pub Option<&'l ExprLocation>);
modifiedcrates/jrsonnet-evaluator/src/import.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/import.rs
+++ b/crates/jrsonnet-evaluator/src/import.rs
@@ -1,17 +1,20 @@
-use crate::{
-	error::{Error::*, Result},
-	throw,
-};
-use fs::File;
-use jrsonnet_interner::IStr;
-use std::fs;
 use std::{
 	any::Any,
+	convert::TryFrom,
+	fs,
+	io::Read,
 	path::{Path, PathBuf},
 	rc::Rc,
 };
-use std::{convert::TryFrom, io::Read};
 
+use fs::File;
+use jrsonnet_interner::IStr;
+
+use crate::{
+	error::{Error::*, Result},
+	throw,
+};
+
 /// Implements file resolution logic for `import` and `importStr`
 pub trait ImportResolver {
 	/// Resolves real file path, e.g. `(/home/user/manifests, b.libjsonnet)` can correspond
modifiedcrates/jrsonnet-evaluator/src/integrations/serde.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/integrations/serde.rs
+++ b/crates/jrsonnet-evaluator/src/integrations/serde.rs
@@ -1,9 +1,11 @@
+use std::convert::{TryFrom, TryInto};
+
+use serde_json::{Map, Number, Value};
+
 use crate::{
 	error::{Error::*, LocError, Result},
 	throw, ObjValueBuilder, Val,
 };
-use serde_json::{Map, Number, Value};
-use std::convert::{TryFrom, TryInto};
 
 impl TryFrom<&Val> for Value {
 	type Error = LocError;
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -13,6 +13,7 @@
 pub mod error;
 mod evaluate;
 pub mod function;
+pub mod gc;
 mod import;
 mod integrations;
 mod map;
@@ -20,9 +21,15 @@
 mod obj;
 pub mod trace;
 pub mod typed;
-mod val;
+pub mod val;
 
-pub use jrsonnet_parser as parser;
+use std::{
+	cell::{Ref, RefCell, RefMut},
+	collections::HashMap,
+	fmt::Debug,
+	path::{Path, PathBuf},
+	rc::Rc,
+};
 
 pub use ctx::*;
 pub use dynamic::*;
@@ -33,18 +40,11 @@
 use gcmodule::{Cc, Trace, Weak};
 pub use import::*;
 pub use jrsonnet_interner::IStr;
+pub use jrsonnet_parser as parser;
 use jrsonnet_parser::*;
 pub use obj::*;
-use std::{
-	cell::{Ref, RefCell, RefMut},
-	collections::HashMap,
-	fmt::Debug,
-	path::{Path, PathBuf},
-	rc::Rc,
-};
 use trace::{location_to_offset, offset_to_location, CodeLocation, CompactFormat, TraceFormat};
-pub use val::*;
-pub mod gc;
+pub use val::{LazyVal, ManifestFormat, Val};
 
 pub trait Bindable: Trace + 'static {
 	fn bind(&self, this: Option<ObjValue>, super_obj: Option<ObjValue>) -> Result<LazyVal>;
@@ -693,18 +693,24 @@
 
 #[cfg(test)]
 pub mod tests {
-	use super::Val;
-	use crate::{
-		error::Error::*, function::BuiltinParam, gc::TraceBox, native::NativeCallbackHandler,
-		primitive_equals, EvaluationState,
-	};
-	use gcmodule::{Cc, Trace};
-	use jrsonnet_parser::*;
 	use std::{
 		path::{Path, PathBuf},
 		rc::Rc,
 	};
 
+	use gcmodule::{Cc, Trace};
+	use jrsonnet_parser::*;
+
+	use super::Val;
+	use crate::{
+		error::Error::*,
+		function::{BuiltinParam, CallLocation},
+		gc::TraceBox,
+		native::NativeCallbackHandler,
+		val::primitive_equals,
+		EvaluationState,
+	};
+
 	#[test]
 	#[should_panic]
 	fn eval_state_stacktrace() {
@@ -712,11 +718,15 @@
 		state.run_in_state(|| {
 			state
 				.push(
-					Some(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
+					CallLocation::new(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
 					|| "outer".to_owned(),
 					|| {
 						state.push(
-							Some(&ExprLocation(PathBuf::from("test2.jsonnet").into(), 30, 40)),
+							CallLocation::new(&ExprLocation(
+								PathBuf::from("test2.jsonnet").into(),
+								30,
+								40,
+							)),
 							|| "inner".to_owned(),
 							|| Err(RuntimeError("".into()).into()),
 						)?;
@@ -1290,10 +1300,11 @@
 	}
 
 	mod derive_typed {
+		use std::path::PathBuf;
+
 		use crate::{typed::Typed, EvaluationState};
-		use std::path::PathBuf;
 
-		#[derive(Typed, PartialEq, Debug)]
+		#[derive(PartialEq, Debug, Typed)]
 		struct MyTyped {
 			a: u32,
 			#[typed(rename = "b")]
modifiedcrates/jrsonnet-evaluator/src/native.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/native.rs
+++ b/crates/jrsonnet-evaluator/src/native.rs
@@ -1,13 +1,16 @@
 #![allow(clippy::type_complexity)]
 
-use crate::function::{parse_builtin_call, ArgsLike, Builtin, BuiltinParam, CallLocation};
-use crate::gc::TraceBox;
-use crate::Context;
-use crate::{error::Result, Val};
+use std::{path::Path, rc::Rc};
+
 use gcmodule::Trace;
-use std::path::Path;
-use std::rc::Rc;
 
+use crate::{
+	error::Result,
+	function::{parse_builtin_call, ArgsLike, Builtin, BuiltinParam, CallLocation},
+	gc::TraceBox,
+	Context, Val,
+};
+
 #[derive(Trace)]
 pub struct NativeCallback {
 	pub(crate) params: Vec<BuiltinParam>,
modifiedcrates/jrsonnet-evaluator/src/obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/obj.rs
+++ b/crates/jrsonnet-evaluator/src/obj.rs
@@ -1,20 +1,23 @@
-use crate::error::LocError;
-use crate::function::CallLocation;
-use crate::gc::{GcHashMap, GcHashSet, TraceBox};
-use crate::operator::evaluate_add_op;
-use crate::push_frame;
-use crate::{
-	cc_ptr_eq, error::Error::*, throw, weak_ptr_eq, weak_raw, Bindable, LazyBinding, LazyVal,
-	Result, Val,
+use std::{
+	cell::RefCell,
+	fmt::Debug,
+	hash::{Hash, Hasher},
 };
+
 use gcmodule::{Cc, Trace, Weak};
 use jrsonnet_interner::IStr;
 use jrsonnet_parser::{ExprLocation, Visibility};
 use rustc_hash::FxHashMap;
-use std::cell::RefCell;
-use std::fmt::Debug;
-use std::hash::{Hash, Hasher};
 
+use crate::{
+	cc_ptr_eq,
+	error::{Error::*, LocError},
+	function::CallLocation,
+	gc::{GcHashMap, GcHashSet, TraceBox},
+	operator::evaluate_add_op,
+	push_frame, throw, weak_ptr_eq, weak_raw, Bindable, LazyBinding, LazyVal, Result, Val,
+};
+
 #[derive(Debug, Trace)]
 pub struct ObjMember {
 	pub add: bool,
modifiedcrates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -1,8 +1,10 @@
 mod location;
 
+use std::path::{Path, PathBuf};
+
+pub use location::*;
+
 use crate::{error::Error, EvaluationState, LocError};
-pub use location::*;
-use std::path::{Path, PathBuf};
 
 /// The way paths should be displayed
 pub enum PathResolver {
modifiedcrates/jrsonnet-evaluator/src/typed/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/typed/mod.rs
+++ b/crates/jrsonnet-evaluator/src/typed/mod.rs
@@ -2,14 +2,14 @@
 
 mod conversions;
 pub use conversions::*;
+use gcmodule::Trace;
+pub use jrsonnet_types::{ComplexValType, ValType};
+use thiserror::Error;
 
 use crate::{
 	error::{Error, LocError, Result},
 	push_description_frame, Val,
 };
-use gcmodule::Trace;
-pub use jrsonnet_types::{ComplexValType, ValType};
-use thiserror::Error;
 
 #[derive(Debug, Error, Clone, Trace)]
 pub enum TypeError {
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/val.rs
+++ b/crates/jrsonnet-evaluator/src/val.rs
@@ -1,3 +1,10 @@
+use std::{cell::RefCell, fmt::Debug, rc::Rc};
+
+use gcmodule::{Cc, Trace};
+use jrsonnet_interner::IStr;
+use jrsonnet_parser::{LocExpr, ParamsDesc};
+use jrsonnet_types::ValType;
+
 use crate::{
 	builtin::manifest::{
 		manifest_json_ex, manifest_yaml_ex, ManifestJsonOptions, ManifestType, ManifestYamlOptions,
@@ -12,11 +19,6 @@
 	gc::TraceBox,
 	throw, Context, ObjValue, Result,
 };
-use gcmodule::{Cc, Trace};
-use jrsonnet_interner::IStr;
-use jrsonnet_parser::{LocExpr, ParamsDesc};
-use jrsonnet_types::ValType;
-use std::{cell::RefCell, fmt::Debug, rc::Rc};
 
 pub trait LazyValValue: Trace {
 	fn get(self: Box<Self>) -> Result<Val>;
modifiedcrates/jrsonnet-interner/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-interner/src/lib.rs
+++ b/crates/jrsonnet-interner/src/lib.rs
@@ -1,6 +1,3 @@
-use gcmodule::Trace;
-use rustc_hash::FxHashMap;
-use serde::{Deserialize, Serialize};
 use std::{
 	borrow::Cow,
 	cell::RefCell,
@@ -12,6 +9,10 @@
 	str::Utf8Error,
 };
 
+use gcmodule::Trace;
+use rustc_hash::FxHashMap;
+use serde::{Deserialize, Serialize};
+
 #[derive(Clone, PartialOrd, Ord, Eq)]
 pub struct IStr(Rc<str>);
 impl Trace for IStr {
modifiedcrates/jrsonnet-parser/src/expr.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/expr.rs
+++ b/crates/jrsonnet-parser/src/expr.rs
@@ -1,7 +1,3 @@
-use gcmodule::Trace;
-use jrsonnet_interner::IStr;
-#[cfg(feature = "serde")]
-use serde::{Deserialize, Serialize};
 use std::{
 	fmt::{Debug, Display},
 	ops::Deref,
@@ -9,6 +5,11 @@
 	rc::Rc,
 };
 
+use gcmodule::Trace;
+use jrsonnet_interner::IStr;
+#[cfg(feature = "serde")]
+use serde::{Deserialize, Serialize};
+
 #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
 #[derive(Debug, PartialEq, Trace)]
 pub enum FieldName {
modifiedcrates/jrsonnet-parser/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-parser/src/lib.rs
+++ b/crates/jrsonnet-parser/src/lib.rs
@@ -1,10 +1,11 @@
 #![allow(clippy::redundant_closure_call)]
 
-use peg::parser;
 use std::{
 	path::{Path, PathBuf},
 	rc::Rc,
 };
+
+use peg::parser;
 mod expr;
 pub use expr::*;
 pub use jrsonnet_interner::IStr;
@@ -317,11 +318,13 @@
 
 #[cfg(test)]
 pub mod tests {
-	use super::{expr::*, parse};
-	use crate::ParserSettings;
 	use std::path::PathBuf;
+
 	use BinaryOpType::*;
 
+	use super::{expr::*, parse};
+	use crate::ParserSettings;
+
 	macro_rules! parse {
 		($s:expr) => {
 			parse(
modifiedcrates/jrsonnet-types/src/lib.rsdiffbeforeafterboth
before · crates/jrsonnet-types/src/lib.rs
1#![allow(clippy::redundant_closure_call)]23use gcmodule::Trace;4use std::fmt::Display;56#[macro_export]7macro_rules! ty {8	((Array<number>)) => {{9		$crate::ComplexValType::ArrayRef(&$crate::ComplexValType::Simple($crate::ValType::Num))10	}};11	((Array<ubyte>)) => {{12		$crate::ComplexValType::ArrayRef(&$crate::ComplexValType::BoundedNumber(Some(0.0), Some(255.0)))13	}};14	(array) => {15		$crate::ComplexValType::Simple($crate::ValType::Arr)16	};17	(boolean) => {18		$crate::ComplexValType::Simple($crate::ValType::Bool)19	};20	(null) => {21		$crate::ComplexValType::Simple($crate::ValType::Null)22	};23	(string) => {24		$crate::ComplexValType::Simple($crate::ValType::Str)25	};26	(char) => {27		$crate::ComplexValType::Char28	};29	(number) => {30		$crate::ComplexValType::Simple($crate::ValType::Num)31	};32	(BoundedNumber<($min:expr), ($max:expr)>) => {{33		$crate::ComplexValType::BoundedNumber($min, $max)34	}};35	(object) => {36		$crate::ComplexValType::Simple($crate::ValType::Obj)37	};38	(any) => {39		$crate::ComplexValType::Any40	};41	(function) => {42		$crate::ComplexValType::Simple($crate::ValType::Func)43	};44	(($($a:tt) |+)) => {{45		static CONTENTS: &'static [&'static $crate::ComplexValType] = &[46			$(&ty!($a)),+47		];48		$crate::ComplexValType::UnionRef(CONTENTS)49	}};50	(($($a:tt) &+)) => {{51		static CONTENTS: &'static [&'static $crate::ComplexValType] = &[52			$(&ty!($a)),+53		];54		$crate::ComplexValType::SumRef(CONTENTS)55	}};56}5758#[test]59fn test() {60	assert_eq!(61		ty!((Array<number>)),62		ComplexValType::ArrayRef(&ComplexValType::Simple(ValType::Num))63	);64	assert_eq!(ty!(array), ComplexValType::Simple(ValType::Arr));65	assert_eq!(ty!(any), ComplexValType::Any);66	assert_eq!(67		ty!((string | number)),68		ComplexValType::UnionRef(&[69			&ComplexValType::Simple(ValType::Str),70			&ComplexValType::Simple(ValType::Num)71		])72	);73	assert_eq!(74		format!("{}", ty!(((string & number) | (object & null)))),75		"string & number | object & null"76	);77	assert_eq!(format!("{}", ty!((string | array))), "string | array");78	assert_eq!(79		format!("{}", ty!(((string & number) | array))),80		"string & number | array"81	);82}8384#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]85pub enum ValType {86	Bool,87	Null,88	Str,89	Num,90	Arr,91	Obj,92	Func,93}9495impl ValType {96	pub const fn name(&self) -> &'static str {97		use ValType::*;98		match self {99			Bool => "boolean",100			Null => "null",101			Str => "string",102			Num => "number",103			Arr => "array",104			Obj => "object",105			Func => "function",106		}107	}108}109110impl Display for ValType {111	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {112		write!(f, "{}", self.name())113	}114}115116#[derive(Debug, Clone, PartialEq, Trace)]117#[skip_trace]118pub enum ComplexValType {119	Any,120	Char,121	Simple(ValType),122	BoundedNumber(Option<f64>, Option<f64>),123	Array(Box<ComplexValType>),124	ArrayRef(&'static ComplexValType),125	ObjectRef(&'static [(&'static str, &'static ComplexValType)]),126	Union(Vec<ComplexValType>),127	UnionRef(&'static [&'static ComplexValType]),128	Sum(Vec<ComplexValType>),129	SumRef(&'static [&'static ComplexValType]),130}131132impl From<ValType> for ComplexValType {133	fn from(s: ValType) -> Self {134		Self::Simple(s)135	}136}137138fn write_union<'i>(139	f: &mut std::fmt::Formatter<'_>,140	is_union: bool,141	union: impl Iterator<Item = &'i ComplexValType>,142) -> std::fmt::Result {143	for (i, v) in union.enumerate() {144		let should_add_braces =145			matches!(v, ComplexValType::UnionRef(_) | ComplexValType::Union(_) if !is_union);146		if i != 0 {147			write!(f, " {} ", if is_union { '|' } else { '&' })?;148		}149		if should_add_braces {150			write!(f, "(")?;151		}152		write!(f, "{}", v)?;153		if should_add_braces {154			write!(f, ")")?;155		}156	}157	Ok(())158}159160fn print_array(a: &ComplexValType, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {161	if *a == ComplexValType::Any {162		write!(f, "array")?163	} else {164		write!(f, "Array<{}>", a)?165	}166	Ok(())167}168169impl Display for ComplexValType {170	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {171		match self {172			ComplexValType::Any => write!(f, "any")?,173			ComplexValType::Simple(s) => write!(f, "{}", s)?,174			ComplexValType::Char => write!(f, "char")?,175			ComplexValType::BoundedNumber(a, b) => write!(176				f,177				"BoundedNumber<{}, {}>",178				a.map(|e| e.to_string()).unwrap_or_else(|| "".into()),179				b.map(|e| e.to_string()).unwrap_or_else(|| "".into())180			)?,181			ComplexValType::ArrayRef(a) => print_array(a, f)?,182			ComplexValType::Array(a) => print_array(a, f)?,183			ComplexValType::ObjectRef(fields) => {184				write!(f, "{{")?;185				for (i, (k, v)) in fields.iter().enumerate() {186					if i != 0 {187						write!(f, ", ")?;188					}189					write!(f, "{}: {}", k, v)?;190				}191				write!(f, "}}")?;192			}193			ComplexValType::Union(v) => write_union(f, true, v.iter())?,194			ComplexValType::UnionRef(v) => write_union(f, true, v.iter().copied())?,195			ComplexValType::Sum(v) => write_union(f, false, v.iter())?,196			ComplexValType::SumRef(v) => write_union(f, false, v.iter().copied())?,197		};198		Ok(())199	}200}201202peg::parser! {203pub grammar parser() for str {204	rule number() -> f64205		= n:$(['0'..='9']+) { n.parse().unwrap() }206207	rule any_ty() -> ComplexValType = "any" { ComplexValType::Any }208	rule char_ty() -> ComplexValType = "character" { ComplexValType::Char }209	rule bool_ty() -> ComplexValType = "boolean" { ComplexValType::Simple(ValType::Bool) }210	rule null_ty() -> ComplexValType = "null" { ComplexValType::Simple(ValType::Null) }211	rule str_ty() -> ComplexValType = "string" { ComplexValType::Simple(ValType::Str) }212	rule num_ty() -> ComplexValType = "number" { ComplexValType::Simple(ValType::Num) }213	rule simple_array_ty() -> ComplexValType = "array" { ComplexValType::Simple(ValType::Arr) }214	rule simple_object_ty() -> ComplexValType = "object" { ComplexValType::Simple(ValType::Obj) }215	rule simple_function_ty() -> ComplexValType = "function" { ComplexValType::Simple(ValType::Func) }216217	rule array_ty() -> ComplexValType218		= "Array<" t:ty() ">" { ComplexValType::Array(Box::new(t)) }219220	rule bounded_number_ty() -> ComplexValType221		= "BoundedNumber<" a:number() ", " b:number() ">" { ComplexValType::BoundedNumber(Some(a), Some(b)) }222223	rule ty_basic() -> ComplexValType224		= any_ty()225		/ char_ty()226		/ bool_ty()227		/ null_ty()228		/ str_ty()229		/ num_ty()230		/ simple_array_ty()231		/ simple_object_ty()232		/ simple_function_ty()233		/ array_ty()234		/ bounded_number_ty()235236	pub rule ty() -> ComplexValType237		= precedence! {238			a:(@) " | " b:@ {239				match a {240					ComplexValType::Union(mut a) => {241						a.push(b);242						ComplexValType::Union(a)243					}244					_ => ComplexValType::Union(vec![a, b]),245				}246			}247			--248			a:(@) " & " b:@ {249				match a {250					ComplexValType::Sum(mut a) => {251						a.push(b);252						ComplexValType::Sum(a)253					}254					_ => ComplexValType::Sum(vec![a, b]),255				}256			}257			--258			"(" t:ty() ")" { t }259			t:ty_basic() { t }260		}261}262}263264#[cfg(test)]265pub mod tests {266	use super::parser;267268	#[test]269	fn precedence() {270		assert_eq!(271			parser::ty("(any & any) | (any | any) & any")272				.unwrap()273				.to_string(),274			"any & any | (any | any) & any"275		);276	}277278	#[test]279	fn array() {280		assert_eq!(parser::ty("Array<any>").unwrap().to_string(), "array");281		assert_eq!(282			parser::ty("Array<number>").unwrap().to_string(),283			"Array<number>"284		);285	}286	#[test]287	fn bounded_number() {288		assert_eq!(289			parser::ty("BoundedNumber<1, 2>").unwrap().to_string(),290			"BoundedNumber<1, 2>"291		);292	}293}
after · crates/jrsonnet-types/src/lib.rs
1#![allow(clippy::redundant_closure_call)]23use std::fmt::Display;45use gcmodule::Trace;67#[macro_export]8macro_rules! ty {9	((Array<number>)) => {{10		$crate::ComplexValType::ArrayRef(&$crate::ComplexValType::Simple($crate::ValType::Num))11	}};12	((Array<ubyte>)) => {{13		$crate::ComplexValType::ArrayRef(&$crate::ComplexValType::BoundedNumber(Some(0.0), Some(255.0)))14	}};15	(array) => {16		$crate::ComplexValType::Simple($crate::ValType::Arr)17	};18	(boolean) => {19		$crate::ComplexValType::Simple($crate::ValType::Bool)20	};21	(null) => {22		$crate::ComplexValType::Simple($crate::ValType::Null)23	};24	(string) => {25		$crate::ComplexValType::Simple($crate::ValType::Str)26	};27	(char) => {28		$crate::ComplexValType::Char29	};30	(number) => {31		$crate::ComplexValType::Simple($crate::ValType::Num)32	};33	(BoundedNumber<($min:expr), ($max:expr)>) => {{34		$crate::ComplexValType::BoundedNumber($min, $max)35	}};36	(object) => {37		$crate::ComplexValType::Simple($crate::ValType::Obj)38	};39	(any) => {40		$crate::ComplexValType::Any41	};42	(function) => {43		$crate::ComplexValType::Simple($crate::ValType::Func)44	};45	(($($a:tt) |+)) => {{46		static CONTENTS: &'static [&'static $crate::ComplexValType] = &[47			$(&ty!($a)),+48		];49		$crate::ComplexValType::UnionRef(CONTENTS)50	}};51	(($($a:tt) &+)) => {{52		static CONTENTS: &'static [&'static $crate::ComplexValType] = &[53			$(&ty!($a)),+54		];55		$crate::ComplexValType::SumRef(CONTENTS)56	}};57}5859#[test]60fn test() {61	assert_eq!(62		ty!((Array<number>)),63		ComplexValType::ArrayRef(&ComplexValType::Simple(ValType::Num))64	);65	assert_eq!(ty!(array), ComplexValType::Simple(ValType::Arr));66	assert_eq!(ty!(any), ComplexValType::Any);67	assert_eq!(68		ty!((string | number)),69		ComplexValType::UnionRef(&[70			&ComplexValType::Simple(ValType::Str),71			&ComplexValType::Simple(ValType::Num)72		])73	);74	assert_eq!(75		format!("{}", ty!(((string & number) | (object & null)))),76		"string & number | object & null"77	);78	assert_eq!(format!("{}", ty!((string | array))), "string | array");79	assert_eq!(80		format!("{}", ty!(((string & number) | array))),81		"string & number | array"82	);83}8485#[derive(Debug, Clone, Copy, PartialEq, Eq, Trace)]86pub enum ValType {87	Bool,88	Null,89	Str,90	Num,91	Arr,92	Obj,93	Func,94}9596impl ValType {97	pub const fn name(&self) -> &'static str {98		use ValType::*;99		match self {100			Bool => "boolean",101			Null => "null",102			Str => "string",103			Num => "number",104			Arr => "array",105			Obj => "object",106			Func => "function",107		}108	}109}110111impl Display for ValType {112	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {113		write!(f, "{}", self.name())114	}115}116117#[derive(Debug, Clone, PartialEq, Trace)]118#[skip_trace]119pub enum ComplexValType {120	Any,121	Char,122	Simple(ValType),123	BoundedNumber(Option<f64>, Option<f64>),124	Array(Box<ComplexValType>),125	ArrayRef(&'static ComplexValType),126	ObjectRef(&'static [(&'static str, &'static ComplexValType)]),127	Union(Vec<ComplexValType>),128	UnionRef(&'static [&'static ComplexValType]),129	Sum(Vec<ComplexValType>),130	SumRef(&'static [&'static ComplexValType]),131}132133impl From<ValType> for ComplexValType {134	fn from(s: ValType) -> Self {135		Self::Simple(s)136	}137}138139fn write_union<'i>(140	f: &mut std::fmt::Formatter<'_>,141	is_union: bool,142	union: impl Iterator<Item = &'i ComplexValType>,143) -> std::fmt::Result {144	for (i, v) in union.enumerate() {145		let should_add_braces =146			matches!(v, ComplexValType::UnionRef(_) | ComplexValType::Union(_) if !is_union);147		if i != 0 {148			write!(f, " {} ", if is_union { '|' } else { '&' })?;149		}150		if should_add_braces {151			write!(f, "(")?;152		}153		write!(f, "{}", v)?;154		if should_add_braces {155			write!(f, ")")?;156		}157	}158	Ok(())159}160161fn print_array(a: &ComplexValType, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {162	if *a == ComplexValType::Any {163		write!(f, "array")?164	} else {165		write!(f, "Array<{}>", a)?166	}167	Ok(())168}169170impl Display for ComplexValType {171	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {172		match self {173			ComplexValType::Any => write!(f, "any")?,174			ComplexValType::Simple(s) => write!(f, "{}", s)?,175			ComplexValType::Char => write!(f, "char")?,176			ComplexValType::BoundedNumber(a, b) => write!(177				f,178				"BoundedNumber<{}, {}>",179				a.map(|e| e.to_string()).unwrap_or_else(|| "".into()),180				b.map(|e| e.to_string()).unwrap_or_else(|| "".into())181			)?,182			ComplexValType::ArrayRef(a) => print_array(a, f)?,183			ComplexValType::Array(a) => print_array(a, f)?,184			ComplexValType::ObjectRef(fields) => {185				write!(f, "{{")?;186				for (i, (k, v)) in fields.iter().enumerate() {187					if i != 0 {188						write!(f, ", ")?;189					}190					write!(f, "{}: {}", k, v)?;191				}192				write!(f, "}}")?;193			}194			ComplexValType::Union(v) => write_union(f, true, v.iter())?,195			ComplexValType::UnionRef(v) => write_union(f, true, v.iter().copied())?,196			ComplexValType::Sum(v) => write_union(f, false, v.iter())?,197			ComplexValType::SumRef(v) => write_union(f, false, v.iter().copied())?,198		};199		Ok(())200	}201}202203peg::parser! {204pub grammar parser() for str {205	rule number() -> f64206		= n:$(['0'..='9']+) { n.parse().unwrap() }207208	rule any_ty() -> ComplexValType = "any" { ComplexValType::Any }209	rule char_ty() -> ComplexValType = "character" { ComplexValType::Char }210	rule bool_ty() -> ComplexValType = "boolean" { ComplexValType::Simple(ValType::Bool) }211	rule null_ty() -> ComplexValType = "null" { ComplexValType::Simple(ValType::Null) }212	rule str_ty() -> ComplexValType = "string" { ComplexValType::Simple(ValType::Str) }213	rule num_ty() -> ComplexValType = "number" { ComplexValType::Simple(ValType::Num) }214	rule simple_array_ty() -> ComplexValType = "array" { ComplexValType::Simple(ValType::Arr) }215	rule simple_object_ty() -> ComplexValType = "object" { ComplexValType::Simple(ValType::Obj) }216	rule simple_function_ty() -> ComplexValType = "function" { ComplexValType::Simple(ValType::Func) }217218	rule array_ty() -> ComplexValType219		= "Array<" t:ty() ">" { ComplexValType::Array(Box::new(t)) }220221	rule bounded_number_ty() -> ComplexValType222		= "BoundedNumber<" a:number() ", " b:number() ">" { ComplexValType::BoundedNumber(Some(a), Some(b)) }223224	rule ty_basic() -> ComplexValType225		= any_ty()226		/ char_ty()227		/ bool_ty()228		/ null_ty()229		/ str_ty()230		/ num_ty()231		/ simple_array_ty()232		/ simple_object_ty()233		/ simple_function_ty()234		/ array_ty()235		/ bounded_number_ty()236237	pub rule ty() -> ComplexValType238		= precedence! {239			a:(@) " | " b:@ {240				match a {241					ComplexValType::Union(mut a) => {242						a.push(b);243						ComplexValType::Union(a)244					}245					_ => ComplexValType::Union(vec![a, b]),246				}247			}248			--249			a:(@) " & " b:@ {250				match a {251					ComplexValType::Sum(mut a) => {252						a.push(b);253						ComplexValType::Sum(a)254					}255					_ => ComplexValType::Sum(vec![a, b]),256				}257			}258			--259			"(" t:ty() ")" { t }260			t:ty_basic() { t }261		}262}263}264265#[cfg(test)]266pub mod tests {267	use super::parser;268269	#[test]270	fn precedence() {271		assert_eq!(272			parser::ty("(any & any) | (any | any) & any")273				.unwrap()274				.to_string(),275			"any & any | (any | any) & any"276		);277	}278279	#[test]280	fn array() {281		assert_eq!(parser::ty("Array<any>").unwrap().to_string(), "array");282		assert_eq!(283			parser::ty("Array<number>").unwrap().to_string(),284			"Array<number>"285		);286	}287	#[test]288	fn bounded_number() {289		assert_eq!(290			parser::ty("BoundedNumber<1, 2>").unwrap().to_string(),291			"BoundedNumber<1, 2>"292		);293	}294}