Sign in

    moonrockz/gleam-parser/span does not have a README file

    CoordinateError

    pub(all) suberror CoordinateError {
    InvalidByteOffset(Int)
    InvalidUtf16Offset(Int)
    InvalidByteLength(Int)
    InvalidLineNumber(Int)
    InvalidColumnNumber(Int)
    InvalidLineCount(Int)
    ReversedSpan(start~ : Int, end~ : Int)
    } derive(Eq,
    Debug
    )

    A source coordinate or range violates its domain. Each case retains the raw value that failed validation.

    ByteLength

    pub struct ByteLength {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    A non-negative number of UTF-8 bytes. Construct with the native constructor, or use from_int to get Option.

    ByteLength::ByteLength

    fn ByteLength::ByteLength(value : Int) -> ByteLength raise CoordinateError

    Create a validated ByteLength. Raise CoordinateError outside its domain. Use from_int to get Option.

    test {
    let value = @span.ByteLength(1)
    assert_eq(value.to_int(), 1)
    }

    ByteLength::from_int

    #alias(new, deprecated="Use `ByteLength::from_int(...)` instead")
    fn ByteLength::from_int(value : Int) -> ByteLength?

    Return a validated value, or None below 0.

    ByteLength::to_int

    fn ByteLength::to_int(self : ByteLength) -> Int

    The numeric value for serialization or string and array operations.

    ByteOffset

    pub struct ByteOffset {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    A zero-based offset in UTF-8 bytes. It does not identify a character boundary until checked against a source text. Construct with the native constructor, or use from_int to get Option.

    ByteOffset::ByteOffset

    fn ByteOffset::ByteOffset(value : Int) -> ByteOffset raise CoordinateError

    Create a validated ByteOffset. Raise CoordinateError outside its domain. Use from_int to get Option.

    test {
    let value = @span.ByteOffset(1)
    assert_eq(value.to_int(), 1)
    }

    ByteOffset::from_int

    #alias(new, deprecated="Use `ByteOffset::from_int(...)` instead")
    fn ByteOffset::from_int(value : Int) -> ByteOffset?

    Return a validated value, or None below 0.

    test {
    debug_inspect(@span.ByteOffset::from_int(-1), content="None")
    debug_inspect(
    @span.ByteOffset::from_int(0),
    content=(
    #|Some({ value: 0 })
    ),
    )
    }

    ByteOffset::shift

    fn ByteOffset::shift(self : ByteOffset, delta : Int) -> ByteOffset?

    Move by a signed displacement. Return None on underflow or overflow.

    test {
    let offset = @span.ByteOffset::from_int(2).unwrap()
    debug_inspect(offset.shift(-3), content="None")
    debug_inspect(
    offset.shift(1),
    content=(
    #|Some({ value: 3 })
    ),
    )
    }

    ByteOffset::to_int

    fn ByteOffset::to_int(self : ByteOffset) -> Int

    The numeric value for serialization or string and array operations.

    ByteOffset::zero

    fn ByteOffset::zero() -> ByteOffset

    The offset at the beginning of a source.

    ColumnNumber

    pub struct ColumnNumber {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    A one-based column number that counts Unicode code points. Construct with the native constructor, or use from_int to get Option.

    ColumnNumber::ColumnNumber

    fn ColumnNumber::ColumnNumber(value : Int) -> ColumnNumber raise CoordinateError

    Create a validated ColumnNumber. Raise CoordinateError outside its domain. Use from_int to get Option.

    test {
    let value = @span.ColumnNumber(1)
    assert_eq(value.to_int(), 1)
    }

    ColumnNumber::from_int

    #alias(new, deprecated="Use `ColumnNumber::from_int(...)` instead")
    fn ColumnNumber::from_int(value : Int) -> ColumnNumber?

    Return a validated value, or None below 1.

    ColumnNumber::to_int

    fn ColumnNumber::to_int(self : ColumnNumber) -> Int

    The numeric value for serialization or string and array operations.

    LineCount

    pub struct LineCount {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    The number of source lines. Even an empty source contains one line.

    LineCount::LineCount

    fn LineCount::LineCount(value : Int) -> LineCount raise CoordinateError

    Create a validated LineCount. Raise CoordinateError outside its domain. Use from_int to get Option.

    test {
    let value = @span.LineCount(1)
    assert_eq(value.to_int(), 1)
    }

    LineCount::from_int

    #alias(new, deprecated="Use `LineCount::from_int(...)` instead")
    fn LineCount::from_int(value : Int) -> LineCount?

    Validate a source line count. Return None below one.

    LineCount::to_int

    fn LineCount::to_int(self : LineCount) -> Int

    The number of lines for serialization or allocation.

    LineNumber

    pub struct LineNumber {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    A one-based line number. Construct with the native constructor, or use from_int to get Option.

    LineNumber::LineNumber

    fn LineNumber::LineNumber(value : Int) -> LineNumber raise CoordinateError

    Create a validated LineNumber. Raise CoordinateError outside its domain. Use from_int to get Option.

    test {
    let value = @span.LineNumber(1)
    assert_eq(value.to_int(), 1)
    }

    LineNumber::from_int

    #alias(new, deprecated="Use `LineNumber::from_int(...)` instead")
    fn LineNumber::from_int(value : Int) -> LineNumber?

    Return a validated value, or None below 1.

    LineNumber::to_int

    fn LineNumber::to_int(self : LineNumber) -> Int

    The numeric value for serialization or string and array operations.

    Position

    pub struct Position {
    line : LineNumber
    column : ColumnNumber
    } derive(Eq, Hash,
    Debug
    )

    A one-based line and column. Columns count Unicode code points.

    Position::Position

    fn Position::Position(line : Int, column : Int) -> Position raise CoordinateError

    Create a one-based position from raw coordinates. Raise CoordinateError for a line or column below one. Use from_ints to get Option, or at with validated coordinates.

    test {
    let position = @span.Position(2, 1)
    assert_eq(position.line.to_int(), 2)
    }

    Position::at

    fn Position::at(line : LineNumber, column : ColumnNumber) -> Position

    Create a position from validated coordinates.

    test {
    let position = @span.Position::at(
    @span.LineNumber::from_int(2).unwrap(),
    @span.ColumnNumber::from_int(1).unwrap(),
    )
    assert_eq(position, @span.Position::from_ints(2, 1).unwrap())
    }

    Position::from_ints

    #alias(new, deprecated="Use `Position::from_ints(...)` instead")
    fn Position::from_ints(line : Int, column : Int) -> Position?

    Create a position from raw coordinates. Return None below one.

    test {
    debug_inspect(@span.Position::from_ints(0, 1), content="None")
    let position = @span.Position::from_ints(1, 2).unwrap()
    assert_eq(position.column.to_int(), 2)
    }

    SrcSpan

    pub struct SrcSpan {
    start : ByteOffset
    end : ByteOffset
    } derive(Eq, Hash,
    Debug
    )

    A half-open UTF-8 byte range, or the compiler's EOF location. Fields are readable. Only validated constructors can create a span.

    SrcSpan::SrcSpan

    fn SrcSpan::SrcSpan(start : Int, end : Int) -> SrcSpan raise CoordinateError

    Create an ordered byte range. Raise CoordinateError for negative offsets or an end before the start. Use from_ints to get Option.

    test {
    let span = @span.SrcSpan(2, 5)
    assert_eq(span.length().map(n => n.to_int()), Some(3))
    }

    SrcSpan::contains

    fn SrcSpan::contains(self : SrcSpan, byte : ByteOffset) -> Bool

    Whether the byte offset lies in the half-open range. EOF contains nothing.

    SrcSpan::eof

    fn SrcSpan::eof(start : ByteOffset) -> SrcSpan

    Create the compiler's start..0 location. A positive start gives a reversed EOF sentinel with no byte length. At zero, this is the empty range 0..0, as in the compiler.

    test {
    let location = @span.SrcSpan::eof(@span.ByteOffset::from_int(5).unwrap())
    assert_eq(location.is_eof(), true)
    assert_eq(location.length(), None)
    }

    SrcSpan::from_compiler

    fn SrcSpan::from_compiler(start : ByteOffset, end : ByteOffset) -> SrcSpan?

    Import compiler offsets. A reversed start..0 is an EOF sentinel. Return None for any other reversed range.

    SrcSpan::from_ints

    #alias(new, deprecated="Use `SrcSpan::from_ints(...)` instead")
    fn SrcSpan::from_ints(start : Int, end : Int) -> SrcSpan?

    Create an ordered range from raw byte offsets. Return None for negative offsets or an end before the start.

    test {
    debug_inspect(@span.SrcSpan::from_ints(3, 2), content="None")
    let span = @span.SrcSpan::from_ints(2, 5).unwrap()
    debug_inspect(span.length().map(n => n.to_int()), content="Some(3)")
    }

    SrcSpan::from_offsets

    #alias(between, deprecated="Use `SrcSpan::from_offsets(...)` instead")
    fn SrcSpan::from_offsets(start : ByteOffset, end : ByteOffset) -> SrcSpan?

    Create an ordered range. Return None when the end precedes the start.

    SrcSpan::is_eof

    fn SrcSpan::is_eof(self : SrcSpan) -> Bool

    Whether this is a reversed compiler EOF sentinel. EOF at byte zero has the same representation as the empty range at zero.

    SrcSpan::length

    fn SrcSpan::length(self : SrcSpan) -> ByteLength?

    The range's byte length, or None for a compiler EOF location.

    Utf16Offset

    pub struct Utf16Offset {
    // private fields
    } derive(Compare, Eq, Hash,
    Debug
    )

    A zero-based offset in UTF-16 code units. It is distinct from a byte offset. Construct with the native constructor, or use from_int to get Option.

    Utf16Offset::Utf16Offset

    fn Utf16Offset::Utf16Offset(value : Int) -> Utf16Offset raise CoordinateError

    Create a validated Utf16Offset. Raise CoordinateError outside its domain. Use from_int to get Option.

    test {
    let value = @span.Utf16Offset(1)
    assert_eq(value.to_int(), 1)
    }

    Utf16Offset::from_int

    #alias(new, deprecated="Use `Utf16Offset::from_int(...)` instead")
    fn Utf16Offset::from_int(value : Int) -> Utf16Offset?

    Return a validated value, or None below 0.

    test {
    debug_inspect(@span.Utf16Offset::from_int(-1), content="None")
    debug_inspect(
    @span.Utf16Offset::from_int(2),
    content=(
    #|Some({ value: 2 })
    ),
    )
    }

    Utf16Offset::shift

    fn Utf16Offset::shift(self : Utf16Offset, delta : Int) -> Utf16Offset?

    Move by a signed displacement. Return None on underflow or overflow.

    Utf16Offset::to_int

    fn Utf16Offset::to_int(self : Utf16Offset) -> Int

    The numeric value for serialization or string and array operations.

    Utf16Offset::zero

    fn Utf16Offset::zero() -> Utf16Offset

    The offset at the beginning of a source.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io