Skip to content

Commit

Permalink
Merge pull request #123 from akihiro17/trailing-comma
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM authored May 29, 2024
2 parents ded67b3 + f23b4e6 commit 225d8c4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/modules/expression/literal/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ impl SyntaxModule<ParserMetadata> 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)?;
Expand Down
9 changes: 9 additions & 0 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "
Expand Down

0 comments on commit 225d8c4

Please sign in to comment.