From f23b4e660b77f223f710789a86d75fcd0cb8deb6 Mon Sep 17 00:00:00 2001 From: akihiro17 <7583548+akihiro17@users.noreply.github.com> Date: Tue, 28 May 2024 22:18:22 +0900 Subject: [PATCH] trailing comma in arrays --- src/modules/expression/literal/array.rs | 3 +++ src/tests/validity.rs | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/src/modules/expression/literal/array.rs b/src/modules/expression/literal/array.rs index c6138e2f..bbdd3374 100644 --- a/src/modules/expression/literal/array.rs +++ b/src/modules/expression/literal/array.rs @@ -50,6 +50,9 @@ impl SyntaxModule for Array { if token(meta, "[").is_ok() { return error!(meta, tok, "Arrays cannot be nested due to the Bash limitations") } + if token(meta, "]").is_ok() { + break; + } // Parse array value let mut value = Expr::new(); syntax(meta, &mut value)?; diff --git a/src/tests/validity.rs b/src/tests/validity.rs index ea663a7f..60dbddd4 100644 --- a/src/tests/validity.rs +++ b/src/tests/validity.rs @@ -534,6 +534,15 @@ fn array_init() { test_amber!(code, "1 2 3 4 5"); } +#[test] +fn array_init_with_trailing_comma() { + let code = " + let a = [1, 2, 3, 4, 5,] + echo a + "; + test_amber!(code, "1 2 3 4 5"); +} + #[test] fn array_assign() { let code = "