Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 1.93 KB

README.md

File metadata and controls

76 lines (52 loc) · 1.93 KB

modelica-fmt

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.

Running

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

To run the examples:

./modelica-fmt examples/gmt-building.mo > examples/gmt-building-out.mo
./modelica-fmt examples/gmt-coolingtower.mo > examples/gmt-coolingtower-out.mo

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
  hooks:
  -
    id: modelica-fmt
    name: Modelica Formatter
    types: [file]
    files: \.(mo)$
    entry: modelicafmt
    args: ["-w"]
    language: system

See https://pre-commit.com/ for more information about the framework.

Building

# install go with brew, or follow instructions here: https://golang.org/doc/install
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.

./generate_parser.sh

Known Issues