oxur_smap/
lib.rs

1//! Source mapping for Oxur language
2//!
3//! This crate provides source mapping capabilities for tracking code
4//! transformations through the Oxur compilation pipeline. It enables
5//! rustc compiler errors to be translated back to the original Oxur
6//! source code positions.
7//!
8//! # Architecture
9//!
10//! The source map tracks three transformation stages:
11//!
12//! 1. **Surface Forms** → **Core Forms** (macro expansion)
13//! 2. **Core Forms** → **Rust AST** (lowering)
14//! 3. **Rust errors** → **Original Source** (backward lookup)
15//!
16//! # Example
17//!
18//! ```
19//! use oxur_smap::{SourceMap, new_node_id, SourcePos, Span};
20//!
21//! let mut map = SourceMap::new();
22//!
23//! // Parser creates surface node with span
24//! let surface = new_node_id();
25//! let span = Span::repl(1, 1, 1, 10);
26//! // Convert span to SourcePos for recording
27//! let pos: SourcePos = (&span).into();
28//! map.record_surface_node(surface, pos);
29//!
30//! // Expander creates core node
31//! let core = new_node_id();
32//! map.record_expansion(surface, core);
33//!
34//! // Lowering creates rust node
35//! let rust = new_node_id();
36//! map.record_lowering(core, rust);
37//!
38//! // Error translator looks up original position
39//! let original = map.lookup(&rust).unwrap();
40//! assert_eq!(original.line, 1);
41//! assert_eq!(original.column, 1);
42//! ```
43
44mod node_id;
45mod source_map;
46mod source_pos;
47mod span;
48
49// Re-export public API
50pub use node_id::{new_node_id, NodeId, NodeIdGenerator};
51pub use source_map::{LookupStats, SourceMap, SourceMapStats};
52pub use source_pos::SourcePos;
53pub use span::Span;