git.delta.rocks / jrsonnet / refs/commits / 78734bcaf74c

difftreelog

fix manifest formats

Yaroslav Bolyukin2024-05-17parent: #4f2e8db.patch.diff
in: master

4 files changed

modifiedcrates/jrsonnet-evaluator/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/manifest.rs
+++ b/crates/jrsonnet-evaluator/src/manifest.rs
@@ -241,7 +241,6 @@
 					Minify => {}
 				};
 
-				buf.push_str(cur_padding);
 				State::push_description(
 					|| format!("elem <{i}> manifestification"),
 					|| manifest_json_ex_buf(&item, buf, cur_padding, options),
@@ -298,8 +297,8 @@
 						buf.push_str(options.newline);
 						buf.push_str(cur_padding);
 					}
-					ToString => buf.push(' '),
-					Minify => {}
+					ToString if i != 0 => buf.push(' '),
+					Minify | ToString => {}
 				}
 
 				escape_string_json_buf(&key, buf);
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -164,7 +164,7 @@
 		("objectRemoveKey", builtin_object_remove_key::INST),
 		// Manifest
 		("escapeStringJson", builtin_escape_string_json::INST),
-		("escapeStringPython", builtin_escape_string_json::INST),
+		("escapeStringPython", builtin_escape_string_python::INST),
 		("escapeStringXML", builtin_escape_string_xml::INST),
 		("manifestJsonEx", builtin_manifest_json_ex::INST),
 		("manifestJson", builtin_manifest_json::INST),
modifiedcrates/jrsonnet-stdlib/src/manifest/mod.rsdiffbeforeafterboth
before · crates/jrsonnet-stdlib/src/manifest/mod.rs
1mod python;2mod toml;3mod xml;4mod yaml;56use jrsonnet_evaluator::{7	function::builtin,8	manifest::{escape_string_json, JsonFormat, YamlStreamFormat},9	IStr, ObjValue, Result, Val,10};11pub use python::{PythonFormat, PythonVarsFormat};12pub use toml::TomlFormat;13pub use xml::XmlJsonmlFormat;14pub use yaml::YamlFormat;1516#[builtin]17pub fn builtin_escape_string_json(str_: IStr) -> Result<String> {18	Ok(escape_string_json(&str_))19}2021#[builtin]22pub fn builtin_manifest_json_ex(23	value: Val,24	indent: String,25	newline: Option<IStr>,26	key_val_sep: Option<IStr>,2728	#[default(false)]29	#[cfg(feature = "exp-preserve-order")]30	preserve_order: bool,31) -> Result<String> {32	let newline = newline.as_deref().unwrap_or("\n");33	let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");34	value.manifest(JsonFormat::std_to_json(35		indent,36		newline,37		key_val_sep,38		#[cfg(feature = "exp-preserve-order")]39		preserve_order,40	))41}4243#[builtin]44pub fn builtin_manifest_json(45	value: Val,4647	#[default(false)]48	#[cfg(feature = "exp-preserve-order")]49	preserve_order: bool,50) -> Result<String> {51	builtin_manifest_json_ex(52		value,53		"    ".to_owned(),54		None,55		None,56		#[cfg(feature = "exp-preserve-order")]57		preserve_order,58	)59}6061#[builtin]62pub fn builtin_manifest_json_minified(63	value: Val,6465	#[default(false)]66	#[cfg(feature = "exp-preserve-order")]67	preserve_order: bool,68) -> Result<String> {69	value.manifest(JsonFormat::minify(70		#[cfg(feature = "exp-preserve-order")]71		preserve_order,72	))73}7475#[builtin]76pub fn builtin_manifest_yaml_doc(77	value: Val,78	#[default(false)] indent_array_in_object: bool,79	#[default(true)] quote_keys: bool,8081	#[default(false)]82	#[cfg(feature = "exp-preserve-order")]83	preserve_order: bool,84) -> Result<String> {85	value.manifest(YamlFormat::std_to_yaml(86		indent_array_in_object,87		quote_keys,88		#[cfg(feature = "exp-preserve-order")]89		preserve_order,90	))91}9293#[builtin]94pub fn builtin_manifest_yaml_stream(95	value: Val,96	#[default(false)] indent_array_in_object: bool,97	#[default(true)] c_document_end: bool,98	#[default(true)] quote_keys: bool,99100	#[default(false)]101	#[cfg(feature = "exp-preserve-order")]102	preserve_order: bool,103) -> Result<String> {104	value.manifest(YamlStreamFormat::std_yaml_stream(105		YamlFormat::std_to_yaml(106			indent_array_in_object,107			quote_keys,108			#[cfg(feature = "exp-preserve-order")]109			preserve_order,110		),111		c_document_end,112	))113}114115#[builtin]116pub fn builtin_manifest_toml_ex(117	value: ObjValue,118	indent: String,119120	#[default(false)]121	#[cfg(feature = "exp-preserve-order")]122	preserve_order: bool,123) -> Result<String> {124	Val::Obj(value).manifest(TomlFormat::std_to_toml(125		indent,126		#[cfg(feature = "exp-preserve-order")]127		preserve_order,128	))129}130131#[builtin]132pub fn builtin_manifest_toml(133	value: ObjValue,134135	#[default(false)]136	#[cfg(feature = "exp-preserve-order")]137	preserve_order: bool,138) -> Result<String> {139	builtin_manifest_toml_ex(140		value,141		"  ".to_owned(),142		#[cfg(feature = "exp-preserve-order")]143		preserve_order,144	)145}146147#[builtin]148pub fn builtin_to_string(a: Val) -> Result<IStr> {149	a.to_string()150}151152#[builtin]153pub fn builtin_manifest_python(154	v: Val,155156	#[default(false)]157	#[cfg(feature = "exp-preserve-order")]158	preserve_order: bool,159) -> Result<String> {160	v.manifest(PythonFormat::std(161		#[cfg(feature = "exp-preserve-order")]162		preserve_order,163	))164}165#[builtin]166pub fn builtin_manifest_python_vars(167	v: Val,168169	#[default(false)]170	#[cfg(feature = "exp-preserve-order")]171	preserve_order: bool,172) -> Result<String> {173	v.manifest(PythonVarsFormat::std(174		#[cfg(feature = "exp-preserve-order")]175		preserve_order,176	))177}178179#[builtin]180pub fn builtin_escape_string_xml(str_: String) -> String {181	xml::escape_string_xml(str_.as_str())182}183184#[builtin]185pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {186	value.manifest(XmlJsonmlFormat::std_to_xml())187}
after · crates/jrsonnet-stdlib/src/manifest/mod.rs
1mod python;2mod toml;3mod xml;4mod yaml;56use jrsonnet_evaluator::{7	function::builtin,8	manifest::{escape_string_json, JsonFormat, YamlStreamFormat},9	IStr, ObjValue, Result, Val,10};11pub use python::{PythonFormat, PythonVarsFormat};12pub use toml::TomlFormat;13pub use xml::XmlJsonmlFormat;14pub use yaml::YamlFormat;1516#[builtin]17pub fn builtin_escape_string_json(str_: IStr) -> Result<String> {18	Ok(escape_string_json(&str_))19}2021#[builtin]22pub fn builtin_escape_string_python(str: IStr) -> Result<String> {23	Ok(escape_string_json(&str))24}2526#[builtin]27pub fn builtin_manifest_json_ex(28	value: Val,29	indent: String,30	newline: Option<IStr>,31	key_val_sep: Option<IStr>,3233	#[default(false)]34	#[cfg(feature = "exp-preserve-order")]35	preserve_order: bool,36) -> Result<String> {37	let newline = newline.as_deref().unwrap_or("\n");38	let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");39	value.manifest(JsonFormat::std_to_json(40		indent,41		newline,42		key_val_sep,43		#[cfg(feature = "exp-preserve-order")]44		preserve_order,45	))46}4748#[builtin]49pub fn builtin_manifest_json(50	value: Val,5152	#[default(false)]53	#[cfg(feature = "exp-preserve-order")]54	preserve_order: bool,55) -> Result<String> {56	builtin_manifest_json_ex(57		value,58		"    ".to_owned(),59		None,60		None,61		#[cfg(feature = "exp-preserve-order")]62		preserve_order,63	)64}6566#[builtin]67pub fn builtin_manifest_json_minified(68	value: Val,6970	#[default(false)]71	#[cfg(feature = "exp-preserve-order")]72	preserve_order: bool,73) -> Result<String> {74	value.manifest(JsonFormat::minify(75		#[cfg(feature = "exp-preserve-order")]76		preserve_order,77	))78}7980#[builtin]81pub fn builtin_manifest_yaml_doc(82	value: Val,83	#[default(false)] indent_array_in_object: bool,84	#[default(true)] quote_keys: bool,8586	#[default(false)]87	#[cfg(feature = "exp-preserve-order")]88	preserve_order: bool,89) -> Result<String> {90	value.manifest(YamlFormat::std_to_yaml(91		indent_array_in_object,92		quote_keys,93		#[cfg(feature = "exp-preserve-order")]94		preserve_order,95	))96}9798#[builtin]99pub fn builtin_manifest_yaml_stream(100	value: Val,101	#[default(false)] indent_array_in_object: bool,102	#[default(true)] c_document_end: bool,103	#[default(true)] quote_keys: bool,104105	#[default(false)]106	#[cfg(feature = "exp-preserve-order")]107	preserve_order: bool,108) -> Result<String> {109	value.manifest(YamlStreamFormat::std_yaml_stream(110		YamlFormat::std_to_yaml(111			indent_array_in_object,112			quote_keys,113			#[cfg(feature = "exp-preserve-order")]114			preserve_order,115		),116		c_document_end,117	))118}119120#[builtin]121pub fn builtin_manifest_toml_ex(122	value: ObjValue,123	indent: String,124125	#[default(false)]126	#[cfg(feature = "exp-preserve-order")]127	preserve_order: bool,128) -> Result<String> {129	Val::Obj(value).manifest(TomlFormat::std_to_toml(130		indent,131		#[cfg(feature = "exp-preserve-order")]132		preserve_order,133	))134}135136#[builtin]137pub fn builtin_manifest_toml(138	value: ObjValue,139140	#[default(false)]141	#[cfg(feature = "exp-preserve-order")]142	preserve_order: bool,143) -> Result<String> {144	builtin_manifest_toml_ex(145		value,146		"  ".to_owned(),147		#[cfg(feature = "exp-preserve-order")]148		preserve_order,149	)150}151152#[builtin]153pub fn builtin_to_string(a: Val) -> Result<IStr> {154	a.to_string()155}156157#[builtin]158pub fn builtin_manifest_python(159	v: Val,160161	#[default(false)]162	#[cfg(feature = "exp-preserve-order")]163	preserve_order: bool,164) -> Result<String> {165	v.manifest(PythonFormat::std(166		#[cfg(feature = "exp-preserve-order")]167		preserve_order,168	))169}170#[builtin]171pub fn builtin_manifest_python_vars(172	conf: Val,173174	#[default(false)]175	#[cfg(feature = "exp-preserve-order")]176	preserve_order: bool,177) -> Result<String> {178	conf.manifest(PythonVarsFormat::std(179		#[cfg(feature = "exp-preserve-order")]180		preserve_order,181	))182}183184#[builtin]185pub fn builtin_escape_string_xml(str_: String) -> String {186	xml::escape_string_xml(str_.as_str())187}188189#[builtin]190pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {191	value.manifest(XmlJsonmlFormat::std_to_xml())192}
modifiedcrates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/strings.rs
+++ b/crates/jrsonnet-stdlib/src/strings.rs
@@ -37,8 +37,8 @@
 }
 
 #[builtin]
-pub fn builtin_escape_string_dollars(str: String) -> String {
-	str.replace('$', "$$")
+pub fn builtin_escape_string_dollars(str_: String) -> String {
+	str_.replace('$', "$$")
 }
 
 #[builtin]