(self, file_path: str)
| 39 | tree_sitter.Language.build_library(c_sharp_library_path, [tree_sitter_csharp_folder_path]) |
| 40 | |
| 41 | def parse(self, file_path: str) -> tree_sitter.Tree: |
| 42 | if not os.path.exists(file_path) or not os.path.isfile(file_path): |
| 43 | raise RuntimeError(f"File {file_path} does not exist") |
| 44 | |
| 45 | with open(file_path, 'r') as source_file: |
| 46 | source_str = source_file.read() |
| 47 | if len(source_str) < 1: |
| 48 | raise RuntimeError(f"File {file_path} is empty") |
| 49 | |
| 50 | if self._config["source"]["csharp"]["convert_macros_to_comments"]: |
| 51 | source_str = self._replace_macros_with_comments(source_str) |
| 52 | |
| 53 | source_bytes = bytes(source_str, "utf8") |
| 54 | |
| 55 | try: |
| 56 | |
| 57 | result: tree_sitter.Tree = self._parser.parse(source_bytes) |
| 58 | if result.root_node: |
| 59 | return result |
| 60 | else: |
| 61 | raise RuntimeError(f"Failed to parse '{file_path}': no root node found") |
| 62 | |
| 63 | except Exception as ex: |
| 64 | raise RuntimeError(f"Failed to parse '{file_path}': threw exception while parsing", ex) |
| 65 | |
| 66 | @classmethod |
| 67 | def _c_sharp_library_path(cls) -> str: |
no test coverage detected