From: Huck Boles Date: Thu, 4 May 2023 00:37:44 +0000 (-0500) Subject: parser into metasource file X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=98cc1886c461714a064ecd0e3b25b0bfdd9f19f9;p=metaforge.git parser into metasource file --- diff --git a/src/parser/meta.pest b/src/parser/meta.pest index 6ae0337..b951124 100644 --- a/src/parser/meta.pest +++ b/src/parser/meta.pest @@ -6,7 +6,9 @@ sigil = _{ ("$" | "@" | "&") ~ "{" } raw_char = _{ !(sigil) ~ ANY } char_seq = { raw_char+ } -string = @{ "\"" ~ char+ ~ "\"" } +string = { escaped_string | raw_string } +escaped_string = @{ "\"" ~ char+ ~ "\"" } +raw_string = @{ "'" ~ (!("'") ~ ANY)+ ~ "'" } char = _{ !("\"" | "\\") ~ ANY | "\\" ~ ("\"" | "\\" | "/" | "b" | "f" | "n" | "r" | "t") diff --git a/src/parser/parse.rs b/src/parser/parse.rs index 82ff15a..b314c40 100644 --- a/src/parser/parse.rs +++ b/src/parser/parse.rs @@ -84,7 +84,14 @@ fn parse_assign(pair: Pair) -> (&'_ str, &'_ str) { key = pair.as_str(); } if Rule::value == pair.as_rule() { - val = pair.as_str(); + let tmp = pair.as_str(); + // blank and default shoud be handled by whoever is getting the value + // set it to empty strings do remove it from the HashMap + if tmp == "BLANK" || tmp == "DEFAULT" { + return ("", ""); + } + // remove surrounding quotes from values + val = &tmp[1..tmp.len() - 1]; } } @@ -111,7 +118,10 @@ fn parse_array(pairs: Pairs) -> Vec<&'_ str> { for pair in pairs { if Rule::string == pair.as_rule() { - vec.push(pair.as_str()); + let tmp = pair.as_str(); + // remove surrounding quotes from values + let val = &tmp[1..tmp.len() - 1]; + vec.push(val); } } vec diff --git a/src/tests/test_parser.rs b/src/tests/test_parser.rs index c404f84..db62c24 100644 --- a/src/tests/test_parser.rs +++ b/src/tests/test_parser.rs @@ -24,7 +24,6 @@ fn build_meta_file() -> Result<()> { &vec!["stuff", "with", "spaces"] ); assert_eq!(source.arrays.get("not_defined"), None); - assert_eq!(source.arrays.get("blank"), None); assert_eq!(source.patterns.get("pat").unwrap(), &"pattern"); assert_eq!(source.patterns.get("pat.sub_pat"), None); diff --git a/src/tests/test_source.meta b/src/tests/test_source.meta index 3d346be..818a5f9 100644 --- a/src/tests/test_source.meta +++ b/src/tests/test_source.meta @@ -1,12 +1,12 @@ ${ var = "good" + single = 'quotes' blank = BLANK } @{ sub.array = ["sub","value"] - arr = ["split","up","values"] - blank = BLANK -{ post line comment } + arr = ["split",'up',"values"] with_spaces = [ "stuff", "with" , "spaces" ] }