-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update OMTypedParser.py to support variable length arrays (:) #147
base: master
Are you sure you want to change the base?
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the correct fix. Modelica values do not contain :
as expressions. And from the linked issue, the problem is that getComponents() is not part of the typed API. Perhaps it could be parsed if it returned ":"
instead of :
, but that might require changes to OMEdit as well (and would be an issue for https://github.com/OpenModelica/OpenModelica)
@sjoelund Sorry for some of the previous responses. Took me a few tries to understand what you were saying. Yes, agreed that the parser would have been able to handle this if it was returning However I am not sure I understand why having the parser handle # Send the command
string = self._omc.sendExpression(expression, parsed=False)
# TODO: Issue https://github.com/OpenModelica/OMPython/issues/138
# OMTypedParser doesn't understand ":" when parsing
string = string.replace("{:}", "{__UNBOUNDED__}")\
.replace("{:,", "{__UNBOUNDED__,")\
.replace(",:,", ",__UNBOUNDED__,")\
.replace(",:}", ",__UNBOUNDED__}")
if string.startswith("Error"):
self.raise_error("Expression '{}' returned the error '{}'.".format(expression, string))
# Manually call the parser and replace the value
response = OMTypedParser.parseString(string) and then later # Get the components for this model
for c in ctx.send("getComponents({})".format(name)):
element_name, instance_name = c[0:2]
attribute = c[8]
# TODO: Hack for unbounded dimensions (see below)
dimensions = []
for dim in c[11]:
dimensions.append(dim if dim != "__UNBOUNDED__" else ":") I basically have to pre-process the string before passing it to the parser and then post-process it later. I would really love to avoid having this in my code permanently (or pointing to my branched fix forever) and this is the only way I am aware to do it |
The problem is that the untyped API has many such special cases that are illegal code. We have many such instances and also cases where AST fragments are returned. This particular case looks like something that is not all too hard to change in the compiler itself. Perhaps even to typed API and in that case OMEdit could get faster performance by skipping a lot parsing and type checking. I would guess that OMPython.OMParser could parse this as it was implemented to parse anything in the untyped API. It's quite annoying to use though, especially for things that are returned in a structured way. |
Closes #138