| 33 | from .file import file |
| 34 | |
| 35 | class StreamTransformer(Transformer): |
| 36 | file: file |
| 37 | |
| 38 | def string(self, items): |
| 39 | return str(items[0])[1:-1] |
| 40 | |
| 41 | def float(self, items): |
| 42 | return float(items[0]) |
| 43 | |
| 44 | def ifcint(self, items): |
| 45 | return int(items[0]) |
| 46 | |
| 47 | def null(self, items): |
| 48 | return None |
| 49 | |
| 50 | def derived(self, items): |
| 51 | return None |
| 52 | |
| 53 | def enum(self, items): |
| 54 | if items[0] == ".T.": |
| 55 | return True |
| 56 | elif items[0] == ".F.": |
| 57 | return False |
| 58 | elif items[0] == ".U.": |
| 59 | return "UNKNOWN" |
| 60 | return str(items[0])[1:-1] |
| 61 | |
| 62 | def list(self, items): |
| 63 | # List is always called twice, I think due to an ambiguity in the Lark |
| 64 | # definition between a list and an arg, but I'm not quite sure. |
| 65 | # print('calling list with', items) |
| 66 | if items and isinstance(items[0], dict): |
| 67 | return tuple(items[0]["list"]) |
| 68 | return {"list": items} |
| 69 | |
| 70 | def inline_type(self, items): |
| 71 | # inline_type is also always called twice. Why? |
| 72 | if items and isinstance(items[0], dict): |
| 73 | return items[0]["inline_type"] |
| 74 | entity = ifcopenshell.create_entity(items[0]) |
| 75 | entity[0] = items[1] |
| 76 | return {"inline_type": entity} |
| 77 | |
| 78 | def reference(self, items): |
| 79 | return self.file.by_id(int(items[0][1:])) |
| 80 | |
| 81 | def arg(self, items): |
| 82 | return items[0] |
| 83 | |
| 84 | def args(self, items): |
| 85 | return items |
| 86 | |
| 87 | def start(self, items): |
| 88 | return (int(items[0]), str(items[1]), items[2]) |
| 89 | |
| 90 | class stream(file): |
| 91 | def __init__(self, filepath: str): |