-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- No `.unwrap()` concern now. - Leverage the common `from_parsed_value` method. - Greatly simplified format support. Signed-off-by: Brennan Kinney <[email protected]>
- Loading branch information
1 parent
0b781b8
commit 4140214
Showing
5 changed files
with
8 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Map<String, Value>, Box<dyn Error + Send + Sync>> { | ||
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# comment | ||
|
||
bar: "bar is a lowercase param" | ||
bar: "bar is a lowercase param" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,4 @@ place: | |
email: "jsmith@localhost" | ||
|
||
FOO: "FOO should be overridden" | ||
bar: "I am bar" | ||
bar: "I am bar" |