Parse a package declaration: package foo.bar [alias baz];
(self)
| 259 | ) |
| 260 | |
| 261 | def parse_package(self) -> tuple[str, Optional[str]]: |
| 262 | """Parse a package declaration: package foo.bar [alias baz];""" |
| 263 | self.consume(TokenType.PACKAGE) |
| 264 | |
| 265 | # Package name can be dotted: foo.bar.baz |
| 266 | parts = [self.consume(TokenType.IDENT).value] |
| 267 | while self.check(TokenType.DOT): |
| 268 | self.advance() # consume the dot |
| 269 | parts.append( |
| 270 | self.consume(TokenType.IDENT, "Expected identifier after '.'").value |
| 271 | ) |
| 272 | |
| 273 | alias = None |
| 274 | if self.check(TokenType.IDENT) and self.current().value == "alias": |
| 275 | self.advance() # consume alias keyword |
| 276 | alias_parts = [ |
| 277 | self.consume(TokenType.IDENT, "Expected identifier after 'alias'").value |
| 278 | ] |
| 279 | while self.check(TokenType.DOT): |
| 280 | self.advance() |
| 281 | alias_parts.append( |
| 282 | self.consume( |
| 283 | TokenType.IDENT, "Expected identifier after '.' in alias" |
| 284 | ).value |
| 285 | ) |
| 286 | alias = ".".join(alias_parts) |
| 287 | |
| 288 | self.consume(TokenType.SEMI, "Expected ';' after package declaration") |
| 289 | return ".".join(parts), alias |
| 290 | |
| 291 | def parse_option_value(self): |
| 292 | """Parse an option value (string, bool, int, or identifier).""" |