MCPcopy Create free account
hub / github.com/apache/fory / parse_package

Method parse_package

compiler/fory_compiler/frontend/fdl/parser.py:261–289  ·  view source on GitHub ↗

Parse a package declaration: package foo.bar [alias baz];

(self)

Source from the content-addressed store, hash-verified

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)."""

Callers 1

parseMethod · 0.95

Calls 5

consumeMethod · 0.95
checkMethod · 0.95
advanceMethod · 0.95
currentMethod · 0.95
appendMethod · 0.45

Tested by

no test coverage detected