Syntax.Source
Source identity for the versioned syntax artifacts: source files and half-open byte spans.
Byte offsets are the canonical position vocabulary (line and column are projections for people, never a second identity), and these are the Prism-side types the token and surface-syntax exports decode into.
Types
Span
type Span = Span { lo: Int, hi: Int } deriving (Eq, Show)
A half-open byte range [lo, hi) into one source text.
span_len(Span { lo = 3, hi = 8 })
5
SourceFile
type SourceFile = SourceFile { digest: String, text: String } deriving (Eq)
One source file as an artifact embeds it: the exact text and its digest. Every span in an artifact indexes this text, so a persisted document needs no external file.
Functions and Values
span_len
span_len : (Syntax.Source.Span) -> Int
The number of bytes a span covers.
span_valid
span_valid : (Syntax.Source.Span) -> Bool
Whether a span is well formed: non-negative start, start at or before end.
(span_valid(Span { lo = 2, hi = 2 }), span_valid(Span { lo = 5, hi = 4 }))
(true, false)
span_contains
span_contains : (Syntax.Source.Span, Int) -> Bool
Whether a byte offset falls inside the span (half-open, so the end offset is outside).
line_col
line_col : (String, Int) -> (Int, Int)
The one-based line and column of a byte offset, as a projection over the text. Offsets past the end clamp to the final position.
line_col("ab\ncd", 4)
(2, 2)