Open kataph opened 3 days ago
@arun3688 how do you see that? Is it easy to fix?
@kataph the immediate solution would be to use parsed=False in sendExpression and then you do some conversion on the string by yourself in python see below
>>> import OMPython
>>> omc = OMPython.OMCSessionZMQ()
>>> omc.sendExpression("loadString(\"model A Integer x[1+1,1]; end A;\")")
>>> omc.sendExpression("getComponents(A)", parsed=False) ## this returns the unparsed string
the problem seems to be x[1+1, 1]
@arun3688 Yes, the problem appears to be (at least) due arithmetic expressions. In the codebase I have to interact with there are various parameters that determine the dimensions of certain arrays by means of arithmetic operations, in particular summation. The solution I am using at the moment indeed takes the raw input and parses it in a cursorily way. However, it is not trivial for me to develop a parser that could parse any output of getComponent(...) with full generality.
@kataph I added the rules to parser which can handle simple arithmetic operations in array dimensions, see the below examples
>>> import OMPython
>>> omc = OMPython.OMCSessionZMQ()
>>> omc.sendExpression("loadString(\"model A Integer x[5*3,1+7]; end A;\")")
True
>>> omc.sendExpression("getComponents(A)")
(('Integer', 'x', '', 'public', False, False, False, False, 'unspecified', 'none', 'unspecified', (15, 8)),)
I hope you have simple arithmetic operations like in the example, if that is the case i will push the code soon
@kataph the issue is fixed with this commit 317b944d32e98d824e66dc644b62331b20664fd8, update your master or pip install viapython -m pip install -U https://github.com/OpenModelica/OMPython/archive/master.zip
Description
in modelica, array declarations allow subscripts to be expressions (consider e.g. this lines in the specifications:
) Indeed, the openmodelica compiler can parse such things. However, OMPython cannot deal with the ensuing outputs.
Steps to Reproduce
Minimum example:
Actual result:
Expected Behavior
That OMPython is able to parse correctly the raw output of the open modelica compiler getComponents scripting function, which in this case would be:
so, hypothetically, something like
Version and OS