Parse fields from a struct/table body.
(body: str)
| 258 | |
| 259 | |
| 260 | def _parse_fields(body: str) -> List[FBSField]: |
| 261 | """Parse fields from a struct/table body.""" |
| 262 | fields = [] |
| 263 | for line in body.split(";"): |
| 264 | line = line.strip() |
| 265 | if not line: |
| 266 | continue |
| 267 | |
| 268 | # Parse: name: type (attributes) = default |
| 269 | match = re.match( |
| 270 | r"(\w+)\s*:\s*(\[?\w+\]?)\s*(?:\(([^)]*)\))?\s*(?:=\s*([^;]+))?", line |
| 271 | ) |
| 272 | if match: |
| 273 | name = match.group(1) |
| 274 | type_str = match.group(2) |
| 275 | attrs = match.group(3) or "" |
| 276 | default = match.group(4).strip() if match.group(4) else None |
| 277 | required = "required" in attrs |
| 278 | fields.append(FBSField(name, type_str, required, default)) |
| 279 | |
| 280 | return fields |
| 281 | |
| 282 | |
| 283 | # Config for compound type factory methods. |