]> git.huck.website - metaforge.git/commitdiff
fixed: whitespace handling in substitutions
authorHuck Boles <huck@huck.website>
Wed, 31 May 2023 19:23:27 +0000 (14:23 -0500)
committerHuck Boles <huck@huck.website>
Wed, 31 May 2023 19:23:27 +0000 (14:23 -0500)
files/test_site/source/unit_tests/expand/spaces.meta [new file with mode: 0644]
src/metafile/file/variables.rs
src/parser.rs
src/parser/meta.pest
src/tests.rs

diff --git a/files/test_site/source/unit_tests/expand/spaces.meta b/files/test_site/source/unit_tests/expand/spaces.meta
new file mode 100644 (file)
index 0000000..073cf92
--- /dev/null
@@ -0,0 +1,6 @@
+${
+    var1 = 'GOOD'
+    var2 = 'GOOD'
+}
+
+${var1} ${var2}
index 033f38c2b125748b8d2155ea4f6a6c7df5c6596b..08f09f81fb7bba42ed88c3f3be0e76a0392b9fe8 100644 (file)
@@ -12,13 +12,13 @@ impl<'a> MetaFile<'a> {
             2
         );
         let long_key = self.name()? + "." + &key.to_string();
-        if let Some(val) = self.variables.get(&Scope::into_local(&long_key)) {
+        if let Some(val) = self.variables.get(&Scope::create_local(&long_key)) {
             Ok(val.clone())
-        } else if let Some(val) = self.variables.get(&Scope::into_global(&long_key)) {
+        } else if let Some(val) = self.variables.get(&Scope::create_global(&long_key)) {
             Ok(val.clone())
-        } else if let Some(val) = self.variables.get(&Scope::into_local(key)) {
+        } else if let Some(val) = self.variables.get(&Scope::create_local(key)) {
             Ok(val.clone())
-        } else if let Some(val) = self.variables.get(&Scope::into_global(key)) {
+        } else if let Some(val) = self.variables.get(&Scope::create_global(key)) {
             Ok(val.clone())
         } else if self.opts.undefined || self.header.panic_undefined {
             return Err(MetaError::UndefinedExpand {
index 259ddbaeb01681a46e45c7778c30d882f095b8bf..d30dea521005f73a1104c0552f4458b808a42707 100644 (file)
@@ -11,7 +11,7 @@ use source::*;
 #[cfg(test)]
 mod tests;
 
-use crate::{log, Header, MetaError, MetaFile, Options};
+use crate::{Header, MetaError, MetaFile, Options};
 use eyre::Result;
 use pest::{
     iterators::{Pair, Pairs},
index a4aa0d74513b046f4bf5400a684414bffd7b51e9..1116c97b24f721075ff94fcf711c7d92056b98b0 100644 (file)
@@ -17,10 +17,10 @@ char   =  _{
 
 array = _{
     "[" ~ "]"
-  | "[" 
-  ~ WHITESPACE* 
-  ~ string 
-  ~ (WHITESPACE* ~ "," ~ WHITESPACE* ~ string)* 
+  | "["
+  ~ WHITESPACE*
+  ~ string
+  ~ (WHITESPACE* ~ "," ~ WHITESPACE* ~ string)*
   ~ WHITESPACE* ~ ","? ~ WHITESPACE*
   ~ "]"
 }
@@ -46,9 +46,9 @@ substitution = _{ sigil ~ key ~ "}" }
 var_sub      =  { &("$") ~ substitution }
 arr_sub      =  { &("@") ~ substitution }
 pat_sub      =  { &("&") ~ substitution }
-identifier   = _{ var_sub | pat_sub | arr_sub }
+identifier   = _{ var_sub | pat_sub | arr_sub | COMMENT}
 
-source = { (identifier | char_seq)* }
+source = ${ (identifier | char_seq)* }
 
 file = {
     SOI ~ header? ~ definition* ~ source? ~ EOI
index 26fb1779ff4480f8ec2972b1d87f5cc180339b2f..aaa3fc055c777e83fd53b61c2e2c27223b2d6e3c 100644 (file)
@@ -47,58 +47,62 @@ macro_rules! panic_test (
 );
 
 unit_test!(blank_pattern, "blank/blank_pattern", "");
-unit_test!(blank_variable, "blank/blank_variable", "<html>\n</html>\n");
-unit_test!(blank_array, "blank/blank_array", "<html>\n</html>\n");
-unit_test!(blank_comment, "blank/comment", "<html>\n</html>\n");
+unit_test!(
+    blank_variable,
+    "blank/blank_variable",
+    "<html>\n\n\n</html>\n"
+);
+unit_test!(blank_array, "blank/blank_array", "<html>\n\n\n</html>\n");
+unit_test!(blank_comment, "blank/comment", "<html>\n\n\n\n</html>\n");
 unit_test!(
     inline_comment,
     "blank/inline_comment",
-    "<html>\n<p>inline comment</p>\n</html>\n"
+    "<html>\n<p>inline comment</p>\n\n\n\n</html>\n"
 );
 unit_test!(
     expand_var_in_src,
     "expand/variable_in_source",
-    "<html>\n<p>GOOD</p>\n</html>\n"
+    "<html>\n<p>GOOD</p>\n\n\n\n</html>\n"
 );
 unit_test!(
     expand_var_in_pat,
     "expand/variable_in_pattern",
-    "<html>\nGOOD</html>\n"
+    "<html>\nGOOD\n\n\n</html>\n"
 );
 unit_test!(
     expand_arr_in_src,
     "expand/array_in_source",
-    "<html>\n<p>12345</p>\n</html>\n"
+    "<html>\n<p>1 2 3 4 5</p>\n\n\n\n</html>\n"
 );
 unit_test!(
     expand_arr_in_pat,
     "expand/array_in_pattern",
-    "<html>\n12345</html>\n"
+    "<html>\n1\n2\n3\n4\n5\n\n\n</html>\n"
 );
 unit_test!(
     expand_pat_in_src,
     "expand/pattern_in_source",
-    "<p>GOOD</p>\n"
+    "<p>GOOD</p>\n\n"
 );
 unit_test!(
     expand_pat_in_pat,
     "expand/pattern_in_pattern",
-    "<html>\nGOOD\nGOOD\n</html>\n"
+    "<html>\nGOOD\nGOOD\n\n\n\n</html>\n"
 );
 unit_test!(
     override_var,
     "override/variable",
-    "<html>\n<p>GOOD</p>\n</html>\n"
+    "<html>\n<p>GOOD</p>\n\n\n\n</html>\n"
 );
 unit_test!(
     override_pat,
     "override/pattern",
-    "<html>\nGOOD\nGOOD\n</html>\n"
+    "<html>\nGOOD\n GOOD\n\n\n\n</html>\n"
 );
 unit_test!(
     header_no_pandoc,
     "header/pandoc",
-    "# This should not become html\n"
+    "# This should not become html\n\n"
 );
 
 unit_test!(header_blank, "header/blank", "");
@@ -106,13 +110,19 @@ unit_test!(header_blank, "header/blank", "");
 unit_test!(
     pat_file,
     "expand/file.meta",
-    "<html>\n<p>GOOD</p>\n</html>\n"
+    "<html>\n<p>GOOD</p>\n\n\n\n</html>\n"
 );
 
 unit_test!(
     direct_call,
     "expand/direct_call",
-    "<html>\n<p>abcd</p>\n</html>\n"
+    "<html>\n<p>a b c d</p>\n\n\n\n</html>\n"
+);
+
+unit_test!(
+    expand_spaces,
+    "expand/spaces",
+    "<html>\n<p>GOOD GOOD</p>\n\n\n\n</html>\n"
 );
 
 panic_test!(ignore, "ignore.meta", "");
@@ -157,12 +167,12 @@ fn test_global() -> Result<()> {
 
     assert_eq!(
         fs::read_to_string(dir.join("build/unit_tests/global/pattern.html"))?,
-        "<p>GOOD GOOD</p>\n"
+        "<p>GOOD</p>\n<p>GOOD</p>\n\n"
     );
 
     assert_eq!(
         fs::read_to_string(dir.join("build/unit_tests/global/variable.html"))?,
-        "<p>GOODGOOD</p>\n"
+        "<p>GOOD GOOD</p>\n\n"
     );
 
     Ok(())