From: Huck Boles Date: Wed, 24 May 2023 15:16:57 +0000 (-0500) Subject: fixed: trailing commas and newlines in array definitions X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=8e99d72fabfd9f006386fd38455705ce02278c3b;p=metaforge.git fixed: trailing commas and newlines in array definitions --- diff --git a/src/parser/meta.pest b/src/parser/meta.pest index e4e2073..a4aa0d7 100644 --- a/src/parser/meta.pest +++ b/src/parser/meta.pest @@ -17,7 +17,12 @@ char = _{ array = _{ "[" ~ "]" - | "[" ~ " "* ~ string ~ (" "* ~ "," ~ " "* ~ string)* ~ " "* ~ "]" + | "[" + ~ WHITESPACE* + ~ string + ~ (WHITESPACE* ~ "," ~ WHITESPACE* ~ string)* + ~ WHITESPACE* ~ ","? ~ WHITESPACE* + ~ "]" } key_chars = @{ (ASCII_ALPHANUMERIC | "_" | ".")* } diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 03f929f..5f30461 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -11,6 +11,16 @@ fn no_spaces_in_def() { test_str!(r#"${v='v'}@{a=['a']}&{p='p'}"#); } +#[test] +fn newlines_in_array() { + test_str!("@{ a = [\n'stuff',\n'other stuff'\n] }"); +} + +#[test] +fn trailing_commas() { + test_str!(r#"@{ a = ['stuff','other stuff',] }"#); +} + #[test] fn just_source_string() { test_str!(r#"This is just a &{source} snippet"#);