1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//! Source span representation for position tracking.
//!
//! This module provides [`SpanIR`], a stable, serializable span type that
//! represents byte ranges in source code. Unlike a parser's own span type,
//! `SpanIR` is plain byte positions and is designed for ABI stability.
//!
//! ## Positions
//!
//! A position is a byte offset plus one: the first byte of the file is
//! position 1. Byte offsets (not character indices or line/column pairs)
//! stay exact with multi-byte UTF-8 characters. To read the spanned text,
//! use [`SpanIR::source_range`], which gives the 0-based byte range.
//!
//! ## Example
//!
//! ```rust
//! use macroforge_ts_syn::SpanIR;
//!
//! // "x" in "let x = 42;" is byte 4, so its span is positions 5..6.
//! let source = "let x = 42;";
//! let span = SpanIR::new(5, 6);
//! assert_eq!(span.len(), 1);
//! assert_eq!(&source[span.source_range()], "x");
//! ```
use ;
/// A stable source span using byte offsets.
///
/// Represents a contiguous range in source code from `start` (inclusive)
/// to `end` (exclusive). Positions are byte offsets plus one, as the host
/// produces them from the parser's spans; see the [module docs](self).
///
/// # Fields
///
/// - `start` - The starting position (inclusive)
/// - `end` - The ending position (exclusive)
///
/// # Invariants
///
/// - `start <= end` for a valid, non-empty span
/// - `start == end` represents an empty span (e.g., for insertion points)
///
/// # Example
///
/// ```rust
/// use macroforge_ts_syn::SpanIR;
///
/// // "hello" in "say hello world" is bytes 4..9, so positions 5..10.
/// let span = SpanIR::new(5, 10);
/// assert_eq!(span.len(), 5);
/// assert_eq!(&"say hello world"[span.source_range()], "hello");
/// ```