Skip to main content

parse

Function parse 

Source
pub fn parse<'a, P: SourceProvider>(
    arena: &'a Bump,
    root_path: &Path,
    provider: P,
    config: ElaborateConfig,
) -> Result<Diagram, ParseError<'a>>
Expand description

Parse an Orrery file into a semantic diagram.

This is the main entry point for parsing Orrery diagram source code. It orchestrates the complete parsing pipeline:

  1. Resolve — Recursively load the root file and all its imports via the SourceProvider, building a virtual address space in the SourceMap and populating the import tree. For each file:
    • Tokenize — Convert source text to tokens
    • Parse — Build an AST from tokens
  2. Desugar — Normalize syntax sugar and flatten imported types
  3. Validate — Check semantic validity
  4. Elaborate — Transform to semantic model

§Arguments

  • arena — A Bump arena that owns all source text. The arena must outlive the returned error (if any), since ParseError borrows source data from it.
  • root_path — Path to the root/entry Orrery file.
  • provider — A SourceProvider implementation that resolves import paths and reads source text.
  • config — Configuration for the elaboration phase.

§Returns

Returns the parsed orrery_core::semantic::Diagram on success, or a ParseError with location information on failure.

§Example

let arena = Bump::new();
let mut provider = InMemorySourceProvider::new();
provider.add_file("main.orr", "diagram component; box: Rectangle;");

let diagram = parse(&arena, Path::new("main.orr"), provider, ElaborateConfig::default())
    .map_err(|e| e.to_string())?;