git.delta.rocks / jrsonnet / refs/commits / 88907d8b259a

difftreelog

perf move ini manifestification to native

Yaroslav Bolyukin2024-05-19parent: #0ef9787.patch.diff
in: master

5 files changed

modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
--- a/crates/jrsonnet-cli/src/manifest.rs
+++ b/crates/jrsonnet-cli/src/manifest.rs
@@ -4,7 +4,7 @@
 use jrsonnet_evaluator::manifest::{
 	JsonFormat, ManifestFormat, StringFormat, ToStringFormat, YamlStreamFormat,
 };
-use jrsonnet_stdlib::{TomlFormat, XmlJsonmlFormat, YamlFormat};
+use jrsonnet_stdlib::{IniFormat, TomlFormat, XmlJsonmlFormat, YamlFormat};
 
 #[derive(Clone, Copy, ValueEnum)]
 pub enum ManifestFormatName {
@@ -14,6 +14,7 @@
 	Yaml,
 	Toml,
 	XmlJsonml,
+	Ini,
 }
 
 #[derive(Parser)]
@@ -72,6 +73,10 @@
 					preserve_order,
 				)),
 				ManifestFormatName::XmlJsonml => Box::new(XmlJsonmlFormat::cli()),
+				ManifestFormatName::Ini => Box::new(IniFormat::cli(
+					#[cfg(feature = "exp-preserve-order")]
+					preserve_order,
+				)),
 			}
 		};
 		if self.yaml_stream {
modifiedcrates/jrsonnet-stdlib/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/lib.rs
+++ b/crates/jrsonnet-stdlib/src/lib.rs
@@ -179,6 +179,7 @@
 		("manifestPython", builtin_manifest_python::INST),
 		("manifestPythonVars", builtin_manifest_python_vars::INST),
 		("manifestXmlJsonml", builtin_manifest_xml_jsonml::INST),
+		("manifestIni", builtin_manifest_ini::INST),
 		// Parse
 		("parseJson", builtin_parse_json::INST),
 		("parseYaml", builtin_parse_yaml::INST),
modifiedcrates/jrsonnet-stdlib/src/manifest/mod.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/mod.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/mod.rs
@@ -1,8 +1,10 @@
+mod ini;
 mod python;
 mod toml;
 mod xml;
 mod yaml;
 
+pub use ini::IniFormat;
 use jrsonnet_evaluator::{
 	function::builtin,
 	manifest::{escape_string_json, JsonFormat, YamlStreamFormat},
@@ -190,3 +192,17 @@
 pub fn builtin_manifest_xml_jsonml(value: Val) -> Result<String> {
 	value.manifest(XmlJsonmlFormat::std_to_xml())
 }
+
+#[builtin]
+pub fn builtin_manifest_ini(
+	ini: Val,
+
+	#[default(false)]
+	#[cfg(feature = "exp-preserve-order")]
+	preserve_order: bool,
+) -> Result<String> {
+	ini.manifest(IniFormat::std(
+		#[cfg(feature = "exp-preserve-order")]
+		preserve_order,
+	))
+}
modifiedcrates/jrsonnet-stdlib/src/manifest/toml.rsdiffbeforeafterboth
--- a/crates/jrsonnet-stdlib/src/manifest/toml.rs
+++ b/crates/jrsonnet-stdlib/src/manifest/toml.rs
@@ -196,7 +196,7 @@
 		#[cfg(feature = "exp-preserve-order")]
 		options.preserve_order,
 	) {
-		let value = value?;
+		let value = value.with_description(|| format!("field <{key}> evaluation"))?;
 		if is_section(&value)? {
 			sections.push((key, value));
 		} else {
modifiedcrates/jrsonnet-stdlib/src/std.jsonnetdiffbeforeafterboth
25 else25 else
26 error 'Assertion failed. ' + a + ' != ' + b,26 error 'Assertion failed. ' + a + ' != ' + b,
2727
28 manifestIni(ini)::
29 local body_lines(body) =
30 std.join([], [
31 local value_or_values = body[k];
32 if std.isArray(value_or_values) then
33 ['%s = %s' % [k, value] for value in value_or_values]
34 else
35 ['%s = %s' % [k, value_or_values]]
36
37 for k in std.objectFields(body)
38 ]);
39
40 local section_lines(sname, sbody) = ['[%s]' % [sname]] + body_lines(sbody),
41 main_body = if std.objectHas(ini, 'main') then body_lines(ini.main) else [],
42 all_sections = [
43 section_lines(k, ini.sections[k])
44 for k in std.objectFields(ini.sections)
45 ];
46 std.join('\n', main_body + std.flattenArrays(all_sections) + ['']),
47
48 mergePatch(target, patch)::28 mergePatch(target, patch)::
49 if std.isObject(patch) then29 if std.isObject(patch) then
50 local target_object =30 local target_object =