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