Skip to main content

A Modelica parser based on parser generator

Project description


.. image::

.. image::

.. image::
:alt: Documentation Status

.. image::
:alt: Updates

modparc is a Modelica parser in Python based on parser combinator.

* Free software: GNU General Public License v3
* Documentation:

.. contents::

.. section-numbering::


Install the package from PyPI:

.. code-block:: bash

$ pip install modparc

To parse a Modelica source file `""`:

.. code-block:: python

import modparc
with open("", 'r') as f:
modelica_source_code =
model_definition = modparc.parse(modelica_source_code)

To use the `model_definition` instance:

.. code-block:: python

all_equations ='Equation')
for equation in all_equations:
print(equation.code()) # The code of the equation as string

One could also parse a certain syntax element in Modelica:

.. code-block:: python

import modparc
from modparc.syntax import tokenize
source_code = """
if init==InitializationOptions.FixedPopulation then
population = initial_population;
elseif init==InitializationOptions.SteadyState then
der(population) = 0;
end if
tokens_list = tokenize(source_code)
if_equation_element = modparc.syntax.equations.if_equation(tokens_list)
sub_equations ='Equation')
for equation in sub_equations:
print(equation.code()) # The code of the equation as string


* Experimentally parses Modelica Standard Library 3.2.1
* Search element of a certain class

Known Issues

* Handling tokenization of Q-IDENT and comments, which comes first?
* Assertion syntax not defined in modelica specification
* Recursion limit (since no tail recursion optimization)
* Test case for long vector literals
* 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.

.. _Cookiecutter:
.. _`audreyr/cookiecutter-pypackage`:


0.1.0 (2016-10-22)

* First release on PyPI.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for modparc, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size modparc-0.1.2-py2.py3-none-any.whl (5.9 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page