Proposal: Allow optional trailing comma in lists
It could be beneficial to allow an optional trailing comma in array, vector, matrix, enumeration, and other list-like constructs in Modelica, similar to features in Python and Julia. This improves readability, diff-friendliness, and consistency in multi-line definitions.
Proposed Grammar Updates
enum-list :
enumeration-literal { "," enumeration-literal } [ "," ]
import-list :
IDENT { "," IDENT } [ "," ]
argument-list :
argument { "," argument } [ "," ]
component-list :
component-declaration { "," component-declaration } [ "," ]
expression-list :
expression { "," expression } [ "," ]
Note: output-expression-list remains unchanged:
output-expression-list :
[ expression ] { "," [ expression ] }
Benefits
- Diff-friendly: Adding or removing elements in multi-line lists no longer requires editing the previous line, reducing unnecessary version control noise.
type Color = enumeration(
Red,
Green,
Blue, // optional trailing comma
);
-
Consistency: Aligns with common practices in modern languages like Python, Julia, and Go.
-
Tooling-friendly: Simplifies code generation and parser implementation by removing the “special case” for the last element.
This enhancement is fully backward-compatible, as all existing code without trailing commas continues to parse correctly.
Proposal: Allow optional trailing comma in lists
It could be beneficial to allow an optional trailing comma in array, vector, matrix, enumeration, and other list-like constructs in Modelica, similar to features in Python and Julia. This improves readability, diff-friendliness, and consistency in multi-line definitions.
Proposed Grammar Updates
Benefits
Consistency: Aligns with common practices in modern languages like Python, Julia, and Go.
Tooling-friendly: Simplifies code generation and parser implementation by removing the “special case” for the last element.
This enhancement is fully backward-compatible, as all existing code without trailing commas continues to parse correctly.