|
16 | 16 | import sys
|
17 | 17 | import tempfile
|
18 | 18 | from pathlib import Path
|
19 |
| -import keyword |
20 | 19 |
|
21 | 20 | from typing import Set, Sequence, List, Callable, Optional, Union, Iterable
|
22 | 21 |
|
|
26 | 25 | import pkg_resources
|
27 | 26 | import regex as re
|
28 | 27 |
|
| 28 | +from .helpers import _subbed_keyword, _unsubbed_keyword |
| 29 | + |
29 | 30 | PathStr = Union[Path, str]
|
30 | 31 | AnimFunc = Callable[[Optional[float]], 'OpenSCADObject']
|
31 | 32 | # These are features added to SolidPython but NOT in OpenSCAD.
|
32 | 33 | # Mark them for special treatment
|
33 | 34 | non_rendered_classes = ['hole', 'part']
|
34 | 35 |
|
35 |
| -# Words reserved in Python but not OpenSCAD |
36 |
| -# Re: https://github.com/SolidCode/SolidPython/issues/99 |
37 |
| - |
38 |
| -PYTHON_ONLY_RESERVED_WORDS = keyword.kwlist |
39 |
| - |
40 |
| - |
41 | 36 | # =========================
|
42 | 37 | # = Internal Utilities =
|
43 | 38 | # =========================
|
@@ -709,39 +704,6 @@ def new_openscad_class_str(class_name: str,
|
709 | 704 |
|
710 | 705 | return result
|
711 | 706 |
|
712 |
| -def _subbed_keyword(keyword: str) -> str: |
713 |
| - """ |
714 |
| - Append an underscore to any python reserved word. |
715 |
| - Prepend an underscore to any OpenSCAD identifier starting with a digit. |
716 |
| - No-op for all other strings, e.g. 'or' => 'or_', 'other' => 'other' |
717 |
| - """ |
718 |
| - new_key = keyword |
719 |
| - |
720 |
| - if keyword in PYTHON_ONLY_RESERVED_WORDS: |
721 |
| - new_key = keyword + "_" |
722 |
| - |
723 |
| - if keyword[0].isdigit(): |
724 |
| - new_key = "_" + keyword |
725 |
| - |
726 |
| - if new_key != keyword: |
727 |
| - print(f"\nFound OpenSCAD code that's not compatible with Python. \n" |
728 |
| - f"Imported OpenSCAD code using `{keyword}` \n" |
729 |
| - f"can be accessed with `{new_key}` in SolidPython\n") |
730 |
| - return new_key |
731 |
| - |
732 |
| -def _unsubbed_keyword(subbed_keyword: str) -> str: |
733 |
| - """ |
734 |
| - Remove trailing underscore for already-subbed python reserved words. |
735 |
| - Remove prepending underscore if remaining identifier starts with a digit. |
736 |
| - No-op for all other strings: e.g. 'or_' => 'or', 'other_' => 'other_' |
737 |
| - """ |
738 |
| - if subbed_keyword.endswith("_") and subbed_keyword[:-1] in PYTHON_ONLY_RESERVED_WORDS: |
739 |
| - return subbed_keyword[:-1] |
740 |
| - |
741 |
| - if subbed_keyword.startswith("_") and subbed_keyword[1].isdigit(): |
742 |
| - return subbed_keyword[1:] |
743 |
| - |
744 |
| - return subbed_keyword |
745 | 707 |
|
746 | 708 | # now that we have the base class defined, we can do a circular import
|
747 | 709 | from . import objects
|
|
0 commit comments