Modelica Code Formatter
Project description
mofmt - Modelica code formatter
Mofmt is a code formatter for Modelica 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:
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 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.
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):
Q_flow = alpha * surfaceArea *
(T_a - T_b);
and only adjust it slightly:
Q_flow = alpha * surfaceArea
* (T_a - T_b);
If wrap is placed inside function call, array etc.:
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:
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mofmt-0.3.4.tar.gz
.
File metadata
- Download URL: mofmt-0.3.4.tar.gz
- Upload date:
- Size: 72.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ab045d81ca554fc51f7a6a49af9816ec54df1d42c55f3425522f08e3d679b6e |
|
MD5 | f214bae70ffb42a02ab3014680377119 |
|
BLAKE2b-256 | 95da26dad8667b028779faff07c1e332a875206efcd1829022eaa9e67362bb6a |
File details
Details for the file mofmt-0.3.4-py3-none-any.whl
.
File metadata
- Download URL: mofmt-0.3.4-py3-none-any.whl
- Upload date:
- Size: 77.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.2 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc03940fc0cbb9684558406b3e84f0dbc9322afcf2eef5854957b0c1b0ab6fc8 |
|
MD5 | 92223ccb14f00009bec5b2d964aa97d0 |
|
BLAKE2b-256 | 3f7d1b5ab1bfb069ae5c5581b8e9e711b823398581d63c4d887d9f69d7d76770 |