Skip to main content

sipha_source/
lib.rs

1//! Centralized source file management and byte-offset to line/column conversion.
2//!
3//! This crate provides utilities for managing source files, converting between
4//! byte offsets and line/column positions, and extracting source snippets for
5//! diagnostics and error reporting.
6//!
7//! # Example
8//!
9//! ```rust
10//! use sipha_source::SourceFile;
11//! use sipha_core::span::Span;
12//!
13//! let source = SourceFile::new(
14//!     "fn main() {\n    println!(\"Hello\");\n}".to_string(),
15//!     None,
16//! );
17//!
18//! // Convert byte offset to line/column
19//! let pos = source.byte_to_line_col(16).unwrap();
20//! assert_eq!(pos.line(), 2);
21//! assert_eq!(pos.column(), 5);
22//!
23//! // Extract a span
24//! let span = Span::new(16, 23);
25//! let snippet = source.extract_span(span).unwrap();
26//! assert_eq!(snippet, "println");
27//! ```
28
29pub mod content;
30pub mod line_map;
31pub mod position;
32pub mod source_file;
33pub mod source_map;
34
35pub use content::SourceContent;
36pub use line_map::LineMap;
37pub use position::Position;
38pub use source_file::{SourceFile, SourceSnippet};
39pub use source_map::SourceMap;