Skip to content

Commit

Permalink
trailing comma in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
akihiro17 committed May 28, 2024
1 parent ded67b3 commit f23b4e6
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 f23b4e6

Please sign in to comment.