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

Method parse_import

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

Parse an import statement: import "path/to/file.fdl";

(self)

Source from the content-addressed store, hash-verified

325 return (option_name, option_value)
326
327 def parse_import(self) -> Import:
328 """Parse an import statement: import "path/to/file.fdl";"""
329 start = self.current()
330 self.consume(TokenType.IMPORT)
331
332 # Check for forbidden import modifiers (protobuf syntax)
333 if self.check(TokenType.PUBLIC):
334 raise ParseError(
335 "'import public' is not supported in FDL.\n"
336 " Reason: FDL uses a simpler import model where all imported types\n"
337 " are available to the importing file. Re-exporting imports is not\n"
338 " supported. Simply use 'import \"path/to/file.fdl\";' instead.\n"
339 " If you need types from multiple files, import each file directly.",
340 start.line,
341 start.column,
342 )
343
344 if self.check(TokenType.WEAK):
345 raise ParseError(
346 "'import weak' is not supported in FDL.\n"
347 " Reason: Weak imports are a protobuf-specific feature for optional\n"
348 " dependencies. FDL requires all imports to be present at compile time.\n"
349 " Use 'import \"path/to/file.fdl\";' instead.",
350 start.line,
351 start.column,
352 )
353
354 path_token = self.consume(TokenType.STRING, "Expected import path string")
355
356 self.consume(TokenType.SEMI, "Expected ';' after import statement")
357
358 return Import(
359 path=path_token.value,
360 line=start.line,
361 column=start.column,
362 location=self.make_location(start),
363 )
364
365 def parse_enum(self) -> Enum:
366 """Parse an enum: enum Color [id=101] { ... }

Callers 1

parseMethod · 0.95

Calls 6

currentMethod · 0.95
consumeMethod · 0.95
checkMethod · 0.95
make_locationMethod · 0.95
ImportClass · 0.90
ParseErrorClass · 0.70

Tested by

no test coverage detected