Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trailing comma in arrays #123

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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