From 8e99d72fabfd9f006386fd38455705ce02278c3b Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Wed, 24 May 2023 10:16:57 -0500 Subject: [PATCH] fixed: trailing commas and newlines in array definitions --- src/parser/meta.pest | 7 ++++++- src/parser/tests.rs | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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"#); -- 2.45.2