Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Extending OMC Corba interface with Python

Extending OMC Corba interface with Python

Hello,

I am currently creating python functions to simplify the use of the OMC - Corba - Python interface by
1) Adding parsers to parse function return strings
2) Create more complex functions to manipulate the modelica code
3) etc.

(Side comment: the parsing could probably be done better directly within the OMC source code but I don't want to go there at this point)
Are there other interested users who have developed such functionality, I would be willing to share the code I have and eventually publish this back to OpenModelica users.

Thanks

Chahé

Re: Extending OMC Corba interface with Python

While we do plan to make the OMC interface more powerful in the future (automatically generating idl files and entry-points to API calls), it's a long way off.

The OMC Java interface (http://openmodelica.org/index.php/resea … :msc:2009) is just a parser + runtime for casting the parsed objects to the expected types, so it's probably similar to what you are doing (except Java is a horrible mess to work with; needing tons of reflective API).

Re: Extending OMC Corba interface with Python

How about exporting the AST maybe in XML instead of java objects?

BTW, this is what the python parser looks like, its very concise using pyparsing library. For example to parse the result of getElementsInfo, the parser is just these few lines:

elementRecord = lCurly.suppress() + Suppress("rec(") +  delimitedList(eqStatement) + Suppress(")") + rCurly.suppress()
elementRecordList = lCurly.suppress() + ZeroOrMore(delimitedList(elementRecord)) + rCurly.suppress()

This will parse something like the following and create a nested list which is already a step forward

{ rec(elementvisibility=public, elementfile="C:/Work/OpenModelica-Python/MSL32/Modelica/../Modelica/Blocks/package.mo", elementreadonly="writable", elementStartLine=16, elementStartColumn=5, elementEndLine=16, elementEndColumn=35, final=false, replaceable=false, inout="none", elementtype=extends, path=Modelica.Icons.Example) }',
                            '{ rec(elementvisibility=public, elementfile="C:/Work/OpenModelica-Python/MSL32/Modelica/../Modelica/Blocks/package.mo", elementreadonly="writable", elementStartLine=17, elementStartColumn=5, elementEndLine=18, elementEndColumn=35, final=false, replaceable=false, inout="none", elementtype=component, typename=Modelica.SIunits.Angle, names={driveAngle,"Reference distance to move"}, flow=false, stream=false, variability="parameter", direction="unspecified") }',
                            '{ rec(elementvisibility=public, elementfile="C:/Work/OpenModelica-Python/MSL32/Modelica/../Modelica/Blocks/package.mo", elementreadonly="writable", elementStartLine=19, elementStartColumn=5, elementEndLine=29, elementEndColumn=18, final=false, replaceable=false, inout="none", elementtype=component, typename=Modelica.Blocks.Continuous.LimPID, names={PI,""}, flow=false, stream=false, variability="unspecified", direction="unspecified") }']

Re: Extending OMC Corba interface with Python

XML is even more annoying to parse than the OMC output though...
Anyway, the Java interface uses an ANTLR grammar. It works very well for the typed API. The untyped API is very odd, returning Ok instead of true and so on, so these calls usually have to be manually parsed. OMEdit used a lot of weird rules to try parsing the untyped API, instead of just rewriting the output to be in a sane format current/smile

There are 0 guests and 0 other users also viewing this topic
You are here: