diff --git a/src/ifcopenshell-python/ifcopenshell/express/rule_compiler.py b/src/ifcopenshell-python/ifcopenshell/express/rule_compiler.py index fc61ce899b..1ed05df3d0 100644 --- a/src/ifcopenshell-python/ifcopenshell/express/rule_compiler.py +++ b/src/ifcopenshell-python/ifcopenshell/express/rule_compiler.py @@ -335,17 +335,18 @@ def process_domain_rule(context): assert ({context.expression}) is not False """ +def wrap_parens(s): + s = str(s) + if " " in s: + s = '(%s)' % s + return s + def process_expression(context): - def wrap(s): - s = str(s) - if " " in s: - s = '(%s)' % s - return s def concat(a, b, **kwargs): return " ".join(map(str, sum(zip( [None] + a.branches(**kwargs), - map(wrap, b.branches(**kwargs)) + map(wrap_parens, b.branches(**kwargs)) ), ())[1:])) if context.rel_op_extended: @@ -443,11 +444,10 @@ def simple_concat(context): # correction: still necessary, apparently. # branches = list(map(str, context.branches())) - concat = "" if len(branches) == 2 and branches[0] == 'not': - concat = " " - - v = concat.join(branches) + return f"{branches[0]} {wrap_parens(branches[1])}" + else: + v = "".join(branches) return v