Skip to content

Optional trailing comma for list entities #3869

@beutlich

Description

@beutlich

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

  1. 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
);
  1. Consistency: Aligns with common practices in modern languages like Python, Julia, and Go.

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions