Skip to main content

Module source_map

Module source_map 

Source
Expand description

Source map for multi-file span tracking.

This module provides a virtual byte address space that maps spans from multiple source files into a single continuous address space. Each file is placed at a unique offset range, with 1-byte gaps between files to ensure no span can accidentally straddle a file boundary.

This follows the pattern used by rustc and rust-analyzer.

§Virtual Address Space Layout

File A (100 bytes): offsets 0..100
gap: 1 byte (offset 100)
File B (80 bytes):  offsets 101..181
gap: 1 byte (offset 181)
File C (50 bytes):  offsets 182..232

§Example

# use orrery_parser::source_map::SourceMap;
let mut map = SourceMap::new();

let offset_a = map.add_file("a.orr", "hello", None);
assert_eq!(offset_a, 0);

let offset_b = map.add_file("b.orr", "world", None);
assert_eq!(offset_b, 6); // 5 bytes + 1-byte gap

Structs§

SourceFile
A single source file registered in the source map.
SourceMap
Maps virtual byte offsets to source files.