Skip to content

Commit

Permalink
allow ident's in array dimension
Browse files Browse the repository at this point in the history
  • Loading branch information
arun3688 committed Dec 6, 2024
1 parent 317b944 commit a44f0ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 3 additions & 4 deletions OMPython/OMTypedParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,12 @@ def evaluateExpression(s, loc, toks):
try:
# Evaluate the expression safely
return eval(expr)
except Exception as e:
print(f"Error evaluating expression: {expr}")
return None
except NameError:
return expr

# Number parsing (supports arithmetic expressions in dimensions) (e.g., {1 + 1, 1})
arrayDimension = infixNotation(
Word(nums),
Word(alphas + "_", alphanums + "_") | Word(nums),
[
(Word("+-", exact=1), 1, opAssoc.RIGHT),
(Word("*/", exact=1), 2, opAssoc.LEFT),
Expand Down
6 changes: 6 additions & 0 deletions tests/test_ArrayDimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def test_ArrayDimension(self):
result = omc.sendExpression("getComponents(A)")
assert result[0][-1] == (6,7), f"array dimension does not match the expected value. Got: {result[0][-1]}, Expected: {(6, 7)}"

omc.sendExpression("loadString(\"model A Integer y = 5; Integer x[y+1,1+8]; end A;\")")
omc.sendExpression("getErrorString()")

result = omc.sendExpression("getComponents(A)")
assert result[-1][-1] == ('y+1',9), f"array dimension does not match the expected value. Got: {result[-1][-1]}, Expected: {('y+1', 9)}"

omc.__del__()
shutil.rmtree(tempdir, ignore_errors= True)

0 comments on commit a44f0ab

Please sign in to comment.