mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Express rules: enclose rhs of not in parens when needed
This commit is contained in:
@@ -335,17 +335,18 @@ def process_domain_rule(context):
|
|||||||
assert ({context.expression}) is not False
|
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 process_expression(context):
|
||||||
def wrap(s):
|
|
||||||
s = str(s)
|
|
||||||
if " " in s:
|
|
||||||
s = '(%s)' % s
|
|
||||||
return s
|
|
||||||
|
|
||||||
def concat(a, b, **kwargs):
|
def concat(a, b, **kwargs):
|
||||||
return " ".join(map(str, sum(zip(
|
return " ".join(map(str, sum(zip(
|
||||||
[None] + a.branches(**kwargs),
|
[None] + a.branches(**kwargs),
|
||||||
map(wrap, b.branches(**kwargs))
|
map(wrap_parens, b.branches(**kwargs))
|
||||||
), ())[1:]))
|
), ())[1:]))
|
||||||
|
|
||||||
if context.rel_op_extended:
|
if context.rel_op_extended:
|
||||||
@@ -443,11 +444,10 @@ def simple_concat(context):
|
|||||||
# correction: still necessary, apparently.
|
# correction: still necessary, apparently.
|
||||||
# branches = list(map(str, context.branches()))
|
# branches = list(map(str, context.branches()))
|
||||||
|
|
||||||
concat = ""
|
|
||||||
if len(branches) == 2 and branches[0] == 'not':
|
if len(branches) == 2 and branches[0] == 'not':
|
||||||
concat = " "
|
return f"{branches[0]} {wrap_parens(branches[1])}"
|
||||||
|
else:
|
||||||
v = concat.join(branches)
|
v = "".join(branches)
|
||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user