]> git.huck.website - metaforge.git/commitdiff
parser into metasource file
authorHuck Boles <huck@huck.website>
Thu, 4 May 2023 00:37:44 +0000 (19:37 -0500)
committerHuck Boles <huck@huck.website>
Thu, 4 May 2023 00:37:44 +0000 (19:37 -0500)
src/parser/meta.pest
src/parser/parse.rs
src/tests/test_parser.rs
src/tests/test_source.meta

index 6ae0337629d244af8f32609fc20ee60b33a75886..b951124d60a6cc7adc820c71e6890782731f3ca9 100644 (file)
@@ -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")
index 82ff15a938d78f39a52075168f3e580ba80e5091..b314c400903e26adc2fff60ce8982f4b49ce4145 100644 (file)
@@ -84,7 +84,14 @@ fn parse_assign(pair: Pair<Rule>) -> (&'_ 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<Rule>) -> 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
index c404f84210229f09ec32b843a9e30fed4e90c4c7..db62c2448bb7df56b30c7ff47e6ac1fcb672f245 100644 (file)
@@ -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);
index 3d346be7f1f6bc69b43b3a46fa6ae75516054ed2..818a5f9ab84f7af99502b53073d94dd7f6b245f1 100644 (file)
@@ -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" ]
 }