1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! # Orrery Parser
//!
//! Parser for the Orrery diagram language. This crate provides the
//! parsing pipeline from source text to semantic diagram representation.
//!
//! ## Usage
//!
//! ```
//! # use std::path::Path;
//! # use bumpalo::Bump;
//! # use orrery_parser::{parse, ElaborateConfig, InMemorySourceProvider};
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let arena = Bump::new();
//! let source = r#"
//! diagram component;
//! user: Rectangle;
//! server: Rectangle;
//! user -> server: "Request";
//! "#;
//!
//! let mut provider = InMemorySourceProvider::new();
//! provider.add_file("main.orr", source);
//!
//! let diagram = parse(&arena, Path::new("main.orr"), provider, ElaborateConfig::default())
//! .map_err(|e| e.to_string())?;
//! # Ok(())
//! # }
//! ```
pub use ElaborateConfig;
pub use ;
pub use Span;
use Path;
use Bump;
use Diagram;
use Builder;
use ParseError;
use Resolver;
/// 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
///
/// ```
/// # use std::path::Path;
/// # use bumpalo::Bump;
/// # use orrery_parser::{parse, ElaborateConfig, InMemorySourceProvider};
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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())?;
/// # Ok(())
/// # }
/// ```