modparc is a Modelica parser in Python based on parser combinator.
- Free software: GNU General Public License v3
- Source code: https://github.com/xie-dongping/modparc.
- Documentation: https://modparc.readthedocs.io.
Contents
Install the package from PyPI:
$ pip install modparc
To parse a Modelica source file "your_modelica_file.mo":
import modparc
model_definition = modparc.parse_file("your_modelica_file.mo")
To list all the equations in the model_definition instance:
all_equations = model_definition.search('Equation')
for equation in all_equations:
print(equation.code()) # The code of the equation as string
To get the name of the model loaded:
print(model_definition.name()) # get the name of the stored class
print(model_definition.class_type()) # get the type of the class
- Experimentally parses Modelica Standard Library 3.2.1
- Search element of a certain class
- Handling tokenization of Q-IDENT and comments, which comes first?
- Assertion syntax not defined in Modelica specification
- Default recursion depth is not enough for long vector literals
- Cyclic import is neccessary for the Modelica syntax definition
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
The test cases used code from the `ModelicaByExample library (MIT License by Michael Tiller)`_.