Skip to content

Commit

Permalink
Expression: fix bracketed expressions, add modulo operator
Browse files Browse the repository at this point in the history
Expressions with brackets such as `10 - (4*2)` would silently discard the part before the bracket, `10 - `.
  • Loading branch information
HENDRIX-ZT2 committed Nov 21, 2019
1 parent 7967fd6 commit 5964711
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pyffi/object_models/xml/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class Expression(object):
"""

operators = set(('==', '!=', '>=', '<=', '&&', '||', '&', '|', '-', '!',
'<', '>', '/', '*', '+'))
'<', '>', '/', '*', '+', '%'))

def __init__(self, expr_str, name_filter=None):
try:
Expand Down Expand Up @@ -155,6 +155,8 @@ def eval(self, data=None):
return left * right
elif self._op == '+':
return left + right
elif self._op == '%':
return left % right
else:
raise NotImplementedError("expression syntax error: operator '" + self._op + "' not implemented")

Expand Down Expand Up @@ -228,7 +230,7 @@ def _partition(cls, expr_str):
# and if so, find the position of the starting bracket and the ending
# bracket
left_startpos, left_endpos = cls._scan_brackets(expr_str)
if left_startpos >= 0:
if left_startpos == 0:
# yes, it is a bracketted expression
# so remove brackets and whitespace,
# and let that be the left hand side
Expand Down

0 comments on commit 5964711

Please sign in to comment.