enhancementgood first issuelow-priority
Repository metrics
- Stars
- (351 stars)
- PR merge metrics
- (PR metrics pending)
Description
Is your feature request related to a problem? Please describe.
A trailing comma in array elements will generate "weird" error messages. For example arr : [...] := [1, 2, 3, 4, 5,]; currently returns
error: Unexpected token: expected Literal but found ]
┌─ target/demo.st:3:53
│
3 │ arr : ARRAY[1..5] OF DINT := [1, 2, 3, 4, 5,];
│ ^ Unexpected token: expected Literal but found ]
error: Unresolved constant 'arr' variable: Cannot resolve constant: EmptyStatement
┌─ target/demo.st:3:38
│
3 │ arr : ARRAY[1..5] OF DINT := [1, 2, 3, 4, 5,];
│ ^^^^^^^^^^^^^^^^ Unresolved constant 'arr' variable: Cannot resolve constant: EmptyStatement
Describe the solution you'd like
Either allow trailing commas returning a warning about it or make it a hard error. In either case a better error message would be great. Technically the error message is already clear if not for the second error.
Edit, additional context: We get the second error because the generated AST will look like the following due to the trailing comma
LiteralArray {
elements: ExpressionList {
expressions: [
LiteralInteger { value: 1 },
...
LiteralInteger { value: 5 },
EmptyStatement,
],
},
}