Skip to content


Repository files navigation


The Modelica Formatter provides the ability to automatically format Modelica code providing a consistent file structure to aid in the readability of the files and the ability to compare the difference between similar files.


modelica-fmt [-w] [-help] <sources>...
  -w  overwrite source with formatted output. If flag is not present print to stdout
  sources  one or more files or directories to format

To run the examples:

./modelica-fmt examples/ > examples/
./modelica-fmt examples/ > examples/

The resulting .mo file can be diffed to the previous file to compare how the modelica-fmt updates the file.

Usage with pre-commit framework

After adding modelicafmt to your system path, add the following lines to your .pre-commit-config.yaml file under the repos: section. Also, make sure to allow modelicafmt to run (especially on Mac).

  repo: local
    id: modelica-fmt
    name: Modelica Formatter
    types: [file]
    files: \.(mo)$
    entry: modelicafmt
    args: ["-w"]
    language: system

See for more information about the framework.


# install go with brew, or follow instructions here:
brew install go

# if you have an older version of the go tool, you may need to explicitly
# download the dependencies (in repo root directory)
go get -d ./...

# in the repository root directory
go build .

# optionally, with `-o` you can specify a custom name for your executable
# (on Windows remember to add `.exe` to the name)
go build -o modelicafmt

Updating Parser (Modelica Grammar)

If the grammar file (Modelica.g4) has been edited, you'll need to regenerate the parser by running the following commmand which runs Antlr in a Docker container.


Known Issues