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