| Crates.io | bhc-span |
| lib.rs | bhc-span |
| version | 0.2.1 |
| created_at | 2026-01-25 17:28:21.230965+00 |
| updated_at | 2026-01-25 18:25:04.991759+00 |
| description | Source location tracking and span management for BHC |
| homepage | |
| repository | https://github.com/raskell-io/bhc |
| max_upload_size | |
| id | 2069132 |
| size | 21,331 |
Source location tracking and span management for the Basel Haskell Compiler.
This crate provides types for tracking source locations throughout the compilation pipeline, enabling accurate error reporting and source mapping.
| Type | Description |
|---|---|
BytePos |
A byte offset into a source file |
Span |
A half-open byte range [lo, hi) representing a region of source code |
Spanned<T> |
A value with an associated span |
FileId |
Unique identifier for a source file |
FullSpan |
A span with an associated file ID for cross-file spans |
LineCol |
Line and column information (1-indexed) |
SourceFile |
Information about a source file including content and line offsets |
use bhc_span::{Span, BytePos, SourceFile, FileId};
// Create a span from byte positions
let span = Span::new(BytePos::new(10), BytePos::new(20));
assert_eq!(span.len(), 10);
// Create a source file and look up line/column
let file = SourceFile::new(
FileId::new(0),
"example.hs".to_string(),
"main = putStrLn \"Hello\"".to_string()
);
let loc = file.lookup_line_col(BytePos::new(7));
assert_eq!(loc.line, 1);
assert_eq!(loc.col, 8);
// Merge spans
let span1 = Span::from_raw(10, 20);
let span2 = Span::from_raw(15, 30);
let merged = span1.merge(span2);
assert_eq!(merged, Span::from_raw(10, 30));
u32 values)serdeDUMMY span ([0, 0)) is used for generated code or when location is irrelevantbhc-diagnostics - Uses spans for error reportingbhc-lexer - Attaches spans to tokensbhc-parser - Attaches spans to AST nodes