pub struct Span {
pub start: u32,
pub len: u32,
}Expand description
a region of the source: start is a byte offset, len is a byte length.
u32 fields cap a source file at 4 GiB, which is fine for a single-file
teaching language and halves the struct size against usize. Copy matters
because spans are attached to every token and every AST node and get cloned
constantly.
Fields§
§start: u32byte offset of the first byte of this region, from the start of the source.
len: u32length of this region in bytes.
Implementations§
Source§impl Span
impl Span
Sourcepub fn new(start: usize, len: usize) -> Self
pub fn new(start: usize, len: usize) -> Self
construct a span from a byte offset and a byte length.
Sourcepub fn merge(self, other: Span) -> Span
pub fn merge(self, other: Span) -> Span
the smallest span covering both inputs.
uses min on the start and max on the end, so the result is correct
regardless of argument order and whether the two spans overlap, touch, or
have a gap between them. the parser uses this to span a whole expression
from its first token to its last.
Sourcepub fn to(self, other: Span) -> Span
pub fn to(self, other: Span) -> Span
alias for Span::merge; reads better at parser call sites
(first.to(last)).