git.delta.rocks / jrsonnet / refs/commits / 2d3e9127fca2

difftreelog

Merge remote-tracking branch 'origin/master' into gcmodule

Yaroslav Bolyukin2022-01-04parents: #fa16ccf #e1fb5e1.patch.diff
in: master

7 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/manifest.rsdiffbeforeafterboth
19pub struct ManifestJsonOptions<'s> {19pub struct ManifestJsonOptions<'s> {
20 pub padding: &'s str,20 pub padding: &'s str,
21 pub mtype: ManifestType,21 pub mtype: ManifestType,
22 pub newline: &'s str,
23 pub key_val_sep: &'s str,
22}24}
2325
24pub fn manifest_json_ex(val: &Val, options: &ManifestJsonOptions<'_>) -> Result<String> {26pub fn manifest_json_ex(val: &Val, options: &ManifestJsonOptions<'_>) -> Result<String> {
49 buf.push('[');51 buf.push('[');
50 if !items.is_empty() {52 if !items.is_empty() {
51 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {53 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
52 buf.push('\n');54 buf.push_str(options.newline);
53 }55 }
5456
55 let old_len = cur_padding.len();57 let old_len = cur_padding.len();
60 if mtype == ManifestType::ToString {62 if mtype == ManifestType::ToString {
61 buf.push(' ');63 buf.push(' ');
62 } else if mtype != ManifestType::Minify {64 } else if mtype != ManifestType::Minify {
63 buf.push('\n');65 buf.push_str(options.newline);
64 }66 }
65 }67 }
66 buf.push_str(cur_padding);68 buf.push_str(cur_padding);
69 cur_padding.truncate(old_len);71 cur_padding.truncate(old_len);
7072
71 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {73 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
72 buf.push('\n');74 buf.push_str(options.newline);
73 buf.push_str(cur_padding);75 buf.push_str(cur_padding);
74 }76 }
75 } else if mtype == ManifestType::Std {77 } else if mtype == ManifestType::Std {
86 let fields = obj.fields();88 let fields = obj.fields();
87 if !fields.is_empty() {89 if !fields.is_empty() {
88 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {90 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
89 buf.push('\n');91 buf.push_str(options.newline);
90 }92 }
9193
92 let old_len = cur_padding.len();94 let old_len = cur_padding.len();
97 if mtype == ManifestType::ToString {99 if mtype == ManifestType::ToString {
98 buf.push(' ');100 buf.push(' ');
99 } else if mtype != ManifestType::Minify {101 } else if mtype != ManifestType::Minify {
100 buf.push('\n');102 buf.push_str(options.newline);
101 }103 }
102 }104 }
103 buf.push_str(cur_padding);105 buf.push_str(cur_padding);
104 escape_string_json_buf(&field, buf);106 escape_string_json_buf(&field, buf);
105 buf.push_str(": ");107 buf.push_str(options.key_val_sep);
106 push_description_frame(108 push_description_frame(
107 || format!("field <{}> manifestification", field.clone()),109 || format!("field <{}> manifestification", field.clone()),
108 || {110 || {
115 cur_padding.truncate(old_len);117 cur_padding.truncate(old_len);
116118
117 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {119 if mtype != ManifestType::ToString && mtype != ManifestType::Minify {
118 buf.push('\n');120 buf.push_str(options.newline);
119 buf.push_str(cur_padding);121 buf.push_str(cur_padding);
120 }122 }
121 } else if mtype == ManifestType::Std {123 } else if mtype == ManifestType::Std {
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
1use crate::function::StaticBuiltin;1use crate::function::StaticBuiltin;
2use crate::typed::{Any, Null, PositiveF64, VecVal, M1};2use crate::typed::{Any, PositiveF64, VecVal, M1};
3use crate::{self as jrsonnet_evaluator, Either, ObjValue};
4use crate::{3use crate::{
5 builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},4 builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},
6 equals,5 equals,
10 typed::{Either2, Either4},9 typed::{Either2, Either4},
11 with_state, ArrValue, Context, FuncVal, IndexableVal, Val,10 with_state, ArrValue, Context, FuncVal, IndexableVal, Val,
12};11};
12use crate::{Either, ObjValue};
13use format::{format_arr, format_obj};13use format::{format_arr, format_obj};
14use gcmodule::Cc;14use gcmodule::Cc;
15use jrsonnet_interner::IStr;15use jrsonnet_interner::IStr;
145fn builtin_length(x: Either![IStr, VecVal, ObjValue, Cc<FuncVal>]) -> Result<usize> {145fn builtin_length(x: Either![IStr, VecVal, ObjValue, Cc<FuncVal>]) -> Result<usize> {
146 use Either4::*;146 use Either4::*;
147 Ok(match x {147 Ok(match x {
148 A(x) => x.len(),148 A(x) => x.chars().count(),
149 B(x) => x.0.len(),149 B(x) => x.0.len(),
150 C(x) => x150 C(x) => x
151 .fields_visibility()151 .fields_visibility()
568#[jrsonnet_macros::builtin]568#[jrsonnet_macros::builtin]
569fn builtin_manifest_json_ex(value: Any, indent: IStr) -> Result<String> {569fn builtin_manifest_json_ex(
570 value: Any,
571 indent: IStr,
572 newline: Option<IStr>,
573 key_val_sep: Option<IStr>,
574) -> Result<String> {
575 let newline = newline.as_deref().unwrap_or("\n");
576 let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");
570 manifest_json_ex(577 manifest_json_ex(
571 &value.0,578 &value.0,
572 &ManifestJsonOptions {579 &ManifestJsonOptions {
573 padding: &indent,580 padding: &indent,
574 mtype: ManifestType::Std,581 mtype: ManifestType::Std,
582 newline,
583 key_val_sep,
575 },584 },
576 )585 )
577}586}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
5 clippy::ptr_arg5 clippy::ptr_arg
6)]6)]
7
8// For jrsonnet-macros
9extern crate self as jrsonnet_evaluator;
710
8mod builtin;11mod builtin;
9mod ctx;12mod ctx;
975 );978 );
976 }979 }
980
981 #[test]
982 fn json_minified() {
983 assert_json!(
984 r#"std.manifestJsonMinified({a:3, b:4, c:6})"#,
985 r#""{\"a\":3,\"b\":4,\"c\":6}""#
986 );
987 }
977988
978 #[test]989 #[test]
979 fn parse_json() {990 fn parse_json() {
modifiedcrates/jrsonnet-evaluator/src/typed/conversions.rsdiffbeforeafterboth
19 ($($ty:ty)*) => {$(19 ($($ty:ty)*) => {$(
20 impl Typed for $ty {20 impl Typed for $ty {
21 const TYPE: &'static ComplexValType =21 const TYPE: &'static ComplexValType =
22 &ComplexValType::BoundedNumber(Some(<$ty>::MIN as f64), Some(<$ty>::MAX as f64));22 &ComplexValType::BoundedNumber(Some(Self::MIN as f64), Some(Self::MAX as f64));
23 }23 }
24 impl TryFrom<Val> for $ty {24 impl TryFrom<Val> for $ty {
25 type Error = LocError;25 type Error = LocError;
modifiedcrates/jrsonnet-evaluator/src/val.rsdiffbeforeafterboth
400 &ManifestJsonOptions {400 &ManifestJsonOptions {
401 padding: "",401 padding: "",
402 mtype: ManifestType::ToString,402 mtype: ManifestType::ToString,
403 newline: "\n",
404 key_val_sep: ": ",
403 },405 },
404 )?406 )?
405 .into(),407 .into(),
484 } else {486 } else {
485 ManifestType::Manifest487 ManifestType::Manifest
486 },488 },
489 newline: "\n",
490 key_val_sep: ": ",
487 },491 },
488 )492 )
489 .map(|s| s.into())493 .map(|s| s.into())
496 &ManifestJsonOptions {500 &ManifestJsonOptions {
497 padding: &" ".repeat(padding),501 padding: &" ".repeat(padding),
498 mtype: ManifestType::Std,502 mtype: ManifestType::Std,
503 newline: "\n",
504 key_val_sep: ": ",
499 },505 },
500 )506 )
501 .map(|s| s.into())507 .map(|s| s.into())
modifiedcrates/jrsonnet-macros/src/lib.rsdiffbeforeafterboth
105 if let Some(opt_ty) = extract_type_from_option(&t.ty) {105 if let Some(opt_ty) = extract_type_from_option(&t.ty) {
106 quote! {{106 quote! {{
107 if let Some(value) = parsed.get(#ident) {107 if let Some(value) = parsed.get(#ident) {
108 Some(jrsonnet_evaluator::push_description_frame(108 Some(::jrsonnet_evaluator::push_description_frame(
109 || format!("argument <{}> evaluation", #ident),109 || format!("argument <{}> evaluation", #ident),
110 || <#opt_ty>::try_from(value.evaluate()?),110 || <#opt_ty>::try_from(value.evaluate()?),
111 )?)111 )?)
117 quote! {{117 quote! {{
118 let value = parsed.get(#ident).unwrap();118 let value = parsed.get(#ident).unwrap();
119119
120 jrsonnet_evaluator::push_description_frame(120 ::jrsonnet_evaluator::push_description_frame(
121 || format!("argument <{}> evaluation", #ident),121 || format!("argument <{}> evaluation", #ident),
122 || <#ty>::try_from(value.evaluate()?),122 || <#ty>::try_from(value.evaluate()?),
123 )?123 )?
136 #[derive(Clone, Copy, gcmodule::Trace)]136 #[derive(Clone, Copy, gcmodule::Trace)]
137 #vis struct #name {}137 #vis struct #name {}
138 const _: () = {138 const _: () = {
139 use jrsonnet_evaluator::function::{Builtin, StaticBuiltin, BuiltinParam, ArgsLike};139 use ::jrsonnet_evaluator::function::{Builtin, StaticBuiltin, BuiltinParam, ArgsLike};
140 const PARAMS: &'static [BuiltinParam] = &[140 const PARAMS: &'static [BuiltinParam] = &[
141 #(#params),*141 #(#params),*
142 ];142 ];
156 PARAMS156 PARAMS
157 }157 }
158 fn call(&self, context: Context, loc: Option<&ExprLocation>, args: &dyn ArgsLike) -> Result<Val> {158 fn call(&self, context: Context, loc: Option<&ExprLocation>, args: &dyn ArgsLike) -> Result<Val> {
159 let parsed = jrsonnet_evaluator::function::parse_builtin_call(context, &PARAMS, args, false)?;159 let parsed = ::jrsonnet_evaluator::function::parse_builtin_call(context, &PARAMS, args, false)?;
160160
161 let result: #result = #name(#(#args),*);161 let result: #result = #name(#(#args),*);
162 let result = result?;162 let result = result?;
modifiedcrates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth
373373
374 manifestJson(value):: std.manifestJsonEx(value, ' ') tailstrict,374 manifestJson(value):: std.manifestJsonEx(value, ' ') tailstrict,
375375
376 manifestJsonMinified(value):: std.manifestJsonEx(value, '', '', ':'),
377
376 manifestJsonEx:: $intrinsic(manifestJsonEx),378 manifestJsonEx:: $intrinsic(manifestJsonEx),
377379
378 manifestYamlDoc:: $intrinsic(manifestYamlDoc),380 manifestYamlDoc:: $intrinsic(manifestYamlDoc),
529 }531 }
530 else532 else
531 patch,533 patch,
534
535 get(o, f, default = null, inc_hidden = true)::
536 if std.objectHasEx(o, f, inc_hidden) then o[f] else default,
532537
533 objectFields(o)::538 objectFields(o)::
534 std.objectFieldsEx(o, false),539 std.objectFieldsEx(o, false),