diff --git a/Cargo.toml b/Cargo.toml index 9aeec9e1..ea695059 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ json = ["serde_json"] yaml = ["yaml-rust"] ini = ["rust-ini"] json5 = ["json5_rs", "serde/derive"] -gura = ["dep:gura"] +gura = ["serde_gura"] convert-case = ["convert_case"] preserve_order = ["indexmap", "toml?/preserve_order", "serde_json?/preserve_order", "ron?/indexmap"] async = ["async-trait"] @@ -37,7 +37,7 @@ yaml-rust = { version = "0.4", optional = true } rust-ini = { version = "0.19", optional = true } ron = { version = "0.8", optional = true } json5_rs = { version = "0.4", optional = true, package = "json5" } -gura = { version = "0.5", optional = true } +serde_gura = { version = "0.1", optional = true } indexmap = { version = "2.0.0", features = ["serde"], optional = true } convert_case = { version = "0.6", optional = true } pathdiff = "0.2" diff --git a/src/file/format/gura.rs b/src/file/format/gura.rs index 658dd94f..324631e6 100644 --- a/src/file/format/gura.rs +++ b/src/file/format/gura.rs @@ -1,52 +1,14 @@ use std::error::Error; -use gura::GuraType; - use crate::format; use crate::map::Map; -use crate::value::{Value, ValueKind}; +use crate::value::Value; pub fn parse( uri: Option<&String>, text: &str, ) -> Result, Box> { - let value = from_gura_value(uri, gura::parse(text).unwrap()); + // Parse a Gura input from the provided text + let value = format::from_parsed_value(uri, serde_gura::from_str(text)?); format::extract_root_table(uri, value) } - -fn from_gura_value(uri: Option<&String>, value: GuraType) -> Value { - let vk = match value { - GuraType::String(value) => ValueKind::String(value), - - GuraType::Integer(value) => ValueKind::I64(value as i64), - GuraType::BigInteger(value) => ValueKind::I128(value), - GuraType::Float(value) => ValueKind::Float(value), - - GuraType::Bool(value) => ValueKind::Boolean(value), - - GuraType::Object(table) => { - let m = table - .into_iter() - .map(|(k, v)| (k, from_gura_value(uri, v))) - .collect(); - - ValueKind::Table(m) - } - - GuraType::Array(array) => { - let l = array - .into_iter() - .map(|v| from_gura_value(uri, v)) - .collect(); - - ValueKind::Array(l) - } - - GuraType::Null => ValueKind::Nil, - - // Remaining types (only intended for internal use): - _ => ValueKind::Nil, - }; - - Value::new(uri, vk) -} diff --git a/src/file/format/mod.rs b/src/file/format/mod.rs index 64e0db24..779fdb50 100644 --- a/src/file/format/mod.rs +++ b/src/file/format/mod.rs @@ -59,7 +59,7 @@ pub enum FileFormat { #[cfg(feature = "json5")] Json5, - /// GURA (parsed with gura) + /// GURA (parsed with serde_gura) #[cfg(feature = "gura")] Gura, } diff --git a/tests/Settings-enum-test.ura b/tests/Settings-enum-test.ura index e0500383..082272dd 100644 --- a/tests/Settings-enum-test.ura +++ b/tests/Settings-enum-test.ura @@ -1,3 +1,3 @@ # comment -bar: "bar is a lowercase param" \ No newline at end of file +bar: "bar is a lowercase param" diff --git a/tests/Settings.ura b/tests/Settings.ura index 46593319..0ba64562 100644 --- a/tests/Settings.ura +++ b/tests/Settings.ura @@ -17,4 +17,4 @@ place: email: "jsmith@localhost" FOO: "FOO should be overridden" -bar: "I am bar" \ No newline at end of file +bar: "I am bar"