quarto_source_map/lib.rs
1//! Source mapping for Quarto
2//!
3//! This crate provides unified source location tracking with support for
4//! transformations (extraction, concatenation, normalization). It enables
5//! precise error reporting and mapping positions back through transformation
6//! chains to original source files.
7//!
8//! # Overview
9//!
10//! The core types are:
11//! - [`SourceInfo`]: Enum tracking a location and its transformation history
12//! - [`SourceContext`]: Manages files and provides content for mapping
13//! - [`MappedLocation`]: Result of mapping through transformation chains
14//!
15//! # Example
16//!
17//! ```rust
18//! use quarto_source_map::*;
19//!
20//! // Create a context and register a file
21//! let mut ctx = SourceContext::new();
22//! let file_id = ctx.add_file("main.qmd".into(), Some("# Hello\nWorld".into()));
23//!
24//! // Create a source location (stores only offsets)
25//! let info = SourceInfo::original(file_id, 0, 7);
26//!
27//! // Map to get row/column information
28//! let mapped = info.map_offset(0, &ctx).unwrap();
29//! assert_eq!(mapped.location.row, 0);
30//! assert_eq!(mapped.location.column, 0);
31//! ```
32
33pub mod context;
34pub mod file_info;
35pub mod mapping;
36pub mod source_info;
37pub mod types;
38pub mod utils;
39
40// Re-export main types
41pub use context::{FileMetadata, SourceContext, SourceFile};
42pub use file_info::FileInformation;
43pub use mapping::MappedLocation;
44pub use source_info::{Anchor, AnchorRole, By, SourceInfo, SourcePiece};
45pub use types::{FileId, Location, Range};
46pub use utils::{line_col_to_offset, offset_to_location, range_from_offsets};