summaryrefslogtreecommitdiffstats
path: root/src/file/format/hjson.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/file/format/hjson.rs')
-rw-r--r--src/file/format/hjson.rs54
1 files changed, 0 insertions, 54 deletions
diff --git a/src/file/format/hjson.rs b/src/file/format/hjson.rs
deleted file mode 100644
index 4b76114..0000000
--- a/src/file/format/hjson.rs
+++ /dev/null
@@ -1,54 +0,0 @@
-use std::error::Error;
-
-use crate::map::Map;
-use crate::value::{Value, ValueKind};
-
-pub fn parse(
- uri: Option<&String>,
- text: &str,
-) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> {
- // Parse a JSON object value from the text
- // TODO: Have a proper error fire if the root of a file is ever not a Table
- let value = from_hjson_value(uri, &serde_hjson::from_str(text)?);
- match value.kind {
- ValueKind::Table(map) => Ok(map),
-
- _ => Ok(Map::new()),
- }
-}
-
-fn from_hjson_value(uri: Option<&String>, value: &serde_hjson::Value) -> Value {
- match *value {
- serde_hjson::Value::String(ref value) => Value::new(uri, ValueKind::String(value.clone())),
-
- serde_hjson::Value::I64(value) => Value::new(uri, ValueKind::Integer(value)),
-
- serde_hjson::Value::U64(value) => Value::new(uri, ValueKind::Integer(value as i64)),
-
- serde_hjson::Value::F64(value) => Value::new(uri, ValueKind::Float(value)),
-
- serde_hjson::Value::Bool(value) => Value::new(uri, ValueKind::Boolean(value)),
-
- serde_hjson::Value::Object(ref table) => {
- let mut m = Map::new();
-
- for (key, value) in table {
- m.insert(key.clone(), from_hjson_value(uri, value));
- }
-
- Value::new(uri, ValueKind::Table(m))
- }
-
- serde_hjson::Value::Array(ref array) => {
- let mut l = Vec::new();
-
- for value in array {
- l.push(from_hjson_value(uri, value));
- }
-
- Value::new(uri, ValueKind::Array(l))
- }
-
- serde_hjson::Value::Null => Value::new(uri, ValueKind::Nil),
- }
-}