mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 03:14:23 +00:00
Merge v0.7.0 -- src\ifcopenshell-python\ifcopenshell\express
This commit is contained in:
@@ -420,6 +420,15 @@ def process_expression(context):
|
||||
exclude=[context.rel_op_extended],
|
||||
)
|
||||
else:
|
||||
if len(context.simple_expression.branches()) == 2 and str(context.rel_op_extended) == 'in':
|
||||
# IfcBlobTexture
|
||||
try:
|
||||
is_literal_str_list = set(map(type, ast.literal_eval(str(context.simple_expression.branches()[1])))) == {str}
|
||||
except:
|
||||
is_literal_str_list = False
|
||||
if is_literal_str_list:
|
||||
a, b = map(str, context.simple_expression.branches())
|
||||
return f"{a}.lower() {str(context.rel_op_extended)} {b}"
|
||||
return concat(context.rel_op_extended, context.simple_expression)
|
||||
elif context.multiplication_like_op:
|
||||
if str(context.multiplication_like_op.branches()[0]) == "||":
|
||||
@@ -444,6 +453,7 @@ def process_expression(context):
|
||||
|
||||
break_points[-1].append(len(args))
|
||||
|
||||
# @todo don't depend on registered schema
|
||||
S = ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema.name)
|
||||
entity = S.declaration_by_name(typename)
|
||||
entity_attributes = entity.attributes()
|
||||
@@ -806,7 +816,26 @@ if __name__ == "__main__":
|
||||
import subprocess
|
||||
|
||||
schema = ifcopenshell.express.express_parser.parse(sys.argv[1]).schema
|
||||
ofn = os.path.join(os.path.dirname(__file__), "rules", f"{schema.name}.py")
|
||||
|
||||
try:
|
||||
ifcopenshell.ifcopenshell_wrapper.schema_by_name(schema.name)
|
||||
except:
|
||||
# @nb note the difference here between:
|
||||
#
|
||||
# - ifcopenshell.express.express_parser.parse
|
||||
# - ifcopenshell.express.parse.parse
|
||||
#
|
||||
# First generates a pyparsing AST
|
||||
#
|
||||
# Second populates a latebound schema
|
||||
# that can be registered in C++.
|
||||
builder = ifcopenshell.express.parse(sys.argv[1])
|
||||
ifcopenshell.register_schema(builder)
|
||||
|
||||
try:
|
||||
ofn = sys.argv[2]
|
||||
except IndexError as e:
|
||||
ofn = os.path.join(os.path.dirname(__file__), "rules", f"{schema.name}.py")
|
||||
output = io.StringIO()
|
||||
|
||||
print("import ifcopenshell", file=output, sep="\n")
|
||||
@@ -1025,5 +1054,8 @@ INDETERMINATE = indeterminate_type()
|
||||
trsf.assign_parent_refs(tree)
|
||||
trsf.visit(tree)
|
||||
|
||||
with open(ofn, "w") as f:
|
||||
f.write(ast.unparse(tree))
|
||||
if ofn == "-":
|
||||
print(ast.unparse(tree))
|
||||
else:
|
||||
with open(ofn, "w") as f:
|
||||
f.write(ast.unparse(tree))
|
||||
|
||||
Reference in New Issue
Block a user