Metadata-Version: 2.1
Name: mofmt
Version: 0.3.3
Summary: Modelica Code Formatter
Home-page: https://github.com/ErykMroczek/mofmt
License: MIT
Keywords: Modelica,automation,formatter
Author: Eryk Mroczek
Author-email: mroczek.eryk@gmail.com
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: antlr4-python3-runtime (==4.13.0)
Project-URL: Repository, https://github.com/ErykMroczek/mofmt
Project-URL: changelog, https://github.com/ErykMroczek/mofmt/blob/main/CHANGELOG.md
Description-Content-Type: text/markdown

# mofmt - Modelica code formatter

*Mofmt* is a code formatter for [Modelica](https://modelica.org/)
language. It aims to enhance readability and provide style constistency
across different Modelica projects.

Although functionality is basically finished, it can of course exhibit
buggy behavior. *mofmt* doesn't modify files if it meets syntax errors.
I advice to double-check changed files.

Code style applied by the *mofmt* is described in `code-style.md`.

## Installation and usage

### Installation

*Mofmt* can be installed from PYPI:

```shell
pip install mofmt
```

On top of that, repo contains a necessary `pre-commit-hooks.yaml` file,
so if you are using Git, you can delegate running *mofmt* to
[pre-commit](https://pre-commit.com/) framework.

### Usage

*mofmt* takes one kind of argument - path that points to Modelica source
file or directory that is supposed to contain such files. *mofmt* can
accept multiple such arguments.

```shell
mofmt PATH ...
```

## Features and limitations

### Vertical spacing and grouping

*Mofmt* aims to ensure that Modelica code is vertically grouped and
indented in a intuitive way that additionally allows you to fold/unfold
specific sections in your text editor. Yet it will try to preserve
single blank lines that you have placed manually, unless they were
placed in places that *mofmt* considers prohibited.

### Comments

Modelica language specification allows you to place comments between any
lexical units, but at least some software doesn't respect that and
displace your comments if it feels like it. *Mofmt* tries to avoid that
(but bugs may happen!). Both comments and whitespaces between them are
preserved. Additionally, *mofmt* preceeds your inline comments with a
single space to enhance readability.

### Line wrapping

*Mofmt* doesn't have a notion of maximum line length and doesn't wrap
lines automatically. This is a deliberate choice, for many expressions
in Modelica are written in a way that resembles textbook formulas. Such
formulas contain terms that have a specific meaning and probably are
kept on the same line by Modelica developers. Any (reasonably simple)
algorithm would probably be too stupid for that, so there is no wrapping
algorithm in *mofmt*. Instead, it will respect your wrapping inside
expressions (provided you wrapped at some operator):

```modelica
Q_flow = alpha * surfaceArea *
(T_a - T_b);
```

and only adjust it slightly:

```modelica
Q_flow = alpha * surfaceArea
  * (T_a - T_b);
```

If wrap is placed inside function call, array etc.:

```modelica
cp = specificHeat_pT(p = p, T = temperature_ph(p = p,
h = h));
```

*mofmt* will ensure that the whole argument list is formatted
consistently, including nested calls:

```modelica
cp = specificHeat_pT(
  p = p,
  T = temperature_ph(
    p = p,
    h = h));
```

## TODO

* improve parsing performance
* (maybe) include HTML pretty-printer

## License

MIT

## Authors

Eryk Mroczek: <mroczek.eryk@gmail.com>

