Skip to main content

Crate sipha_source

Crate sipha_source 

Source
Expand description

Centralized source file management and byte-offset to line/column conversion.

This crate provides utilities for managing source files, converting between byte offsets and line/column positions, and extracting source snippets for diagnostics and error reporting.

§Example

use sipha_source::SourceFile;
use sipha_core::span::Span;

let source = SourceFile::new(
    "fn main() {\n    println!(\"Hello\");\n}".to_string(),
    None,
);

// Convert byte offset to line/column
let pos = source.byte_to_line_col(16).unwrap();
assert_eq!(pos.line(), 2);
assert_eq!(pos.column(), 5);

// Extract a span
let span = Span::new(16, 23);
let snippet = source.extract_span(span).unwrap();
assert_eq!(snippet, "println");

Re-exports§

pub use content::SourceContent;
pub use line_map::LineMap;
pub use position::Position;
pub use source_file::SourceFile;
pub use source_file::SourceSnippet;
pub use source_map::SourceMap;

Modules§

content
Source content representation supporting both UTF-8 and binary data.
line_map
Efficient line boundary tracking for source files.
position
Line and column position types for source locations.
source_file
Source file management and position conversion.
source_map
Multi-file source management.