Skip to content

Commit ca012e5

Browse files
committed
adjusted solidpython to meet py_scadparser changes
- [un]subbed_keyword should now handle $parameters - it should be possible to remove all $fn <-> segments code from everywhere and let [un]subbed_keyword do the work
1 parent 2de5803 commit ca012e5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

solid/solidpython.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ def sp_code_in_scad_comment(calling_file: PathStr) -> str:
614614
def parse_scad_callables(filename: str) -> List[dict]:
615615
from .py_scadparser import scad_parser
616616

617-
_, _, modules, functions, _ = scad_parser.parseFile(filename)
617+
modules, functions, _ = scad_parser.parseFile(filename)
618618

619619
callables = []
620620
for c in modules + functions:
@@ -720,9 +720,15 @@ def _subbed_keyword(keyword: str) -> str:
720720
if keyword in PYTHON_ONLY_RESERVED_WORDS:
721721
new_key = keyword + "_"
722722

723-
if keyword[0].isdigit():
723+
elif keyword[0].isdigit():
724724
new_key = "_" + keyword
725725

726+
elif keyword == "$fn":
727+
new_key = "segments"
728+
729+
elif keyword[0] == "$":
730+
new_key = "__" + keyword[1:]
731+
726732
if new_key != keyword:
727733
print(f"\nFound OpenSCAD code that's not compatible with Python. \n"
728734
f"Imported OpenSCAD code using `{keyword}` \n"
@@ -738,9 +744,15 @@ def _unsubbed_keyword(subbed_keyword: str) -> str:
738744
if subbed_keyword.endswith("_") and subbed_keyword[:-1] in PYTHON_ONLY_RESERVED_WORDS:
739745
return subbed_keyword[:-1]
740746

741-
if subbed_keyword.startswith("_") and subbed_keyword[1].isdigit():
747+
elif subbed_keyword.startswith("__"):
748+
return "$" + subbed_keyword[2:]
749+
750+
elif subbed_keyword.startswith("_") and subbed_keyword[1].isdigit():
742751
return subbed_keyword[1:]
743752

753+
elif subbed_keyword == "segments":
754+
return "$fn"
755+
744756
return subbed_keyword
745757

746758
# now that we have the base class defined, we can do a circular import

0 commit comments

Comments
 (0)