Parse CDDL content and return modules.
(self)
| 1047 | logger.info(f"Loaded CDDL file: {self.cddl_path}") |
| 1048 | |
| 1049 | def parse(self) -> dict[str, CddlModule]: |
| 1050 | """Parse CDDL content and return modules.""" |
| 1051 | # Remove comments |
| 1052 | content = self._remove_comments(self.content) |
| 1053 | |
| 1054 | # Extract all definitions |
| 1055 | self._extract_definitions(content) |
| 1056 | |
| 1057 | # Extract event names from event union definitions |
| 1058 | self._extract_event_names() |
| 1059 | |
| 1060 | # Extract type definitions by module |
| 1061 | self._extract_types() |
| 1062 | |
| 1063 | # Extract event definitions by module |
| 1064 | self._extract_events() |
| 1065 | |
| 1066 | # Extract command definitions by module |
| 1067 | self._extract_commands() |
| 1068 | |
| 1069 | # If no modules found, create a default one from the filename |
| 1070 | if not self.modules: |
| 1071 | module_name = self.cddl_path.stem |
| 1072 | default_module = CddlModule(name=module_name) |
| 1073 | self.modules[module_name] = default_module |
| 1074 | logger.warning(f"No modules found in CDDL, creating default: {module_name}") |
| 1075 | |
| 1076 | return self.modules |
| 1077 | |
| 1078 | def _remove_comments(self, content: str) -> str: |
| 1079 | """Remove comments from CDDL content.""" |
no test coverage detected