#Nanaloveyuki/parsec/lexer

    lexer provides source-location data for tokenizers and parser diagnostics. Offsets are character offsets, lines and columns are one-based, and spans are half-open ranges: [start, end).

    ///|
    test "locate a parser error" {
    let source = @lexer.Source::new("ab\ncd")
    match source.position_at(3) {
    Some(position) => {
    inspect(position.line(), content="2")
    inspect(position.column(), content="1")
    }
    None => fail("expected source position")
    }
    }

    Use Source::error_position to map a root @parsec.ParseError to text. This package does not own token trivia, recovery, CST construction, or AST lowering.

    Located

    pub struct Located[T] {
    // private fields
    }

    Located::map

    fn[T, U] Located::map(self : Located[T], transform : (T) -> U) -> Located[U]

    Located::new

    fn[T] Located::new(value : T, span : Span) -> Located[T]

    Located::span

    fn[T] Located::span(self : Located[T]) -> Span

    Located::value

    fn[T] Located::value(self : Located[T]) -> T

    Position

    pub struct Position {
    // private fields
    }

    Position::column

    fn Position::column(self : Position) -> Int

    Position::line

    fn Position::line(self : Position) -> Int

    Position::offset

    fn Position::offset(self : Position) -> Int

    Source

    pub struct Source {
    // private fields
    }

    Source::error_position

    fn Source::error_position(self : Source, error :
    ParseError
    ) -> Position?

    Source::length

    fn Source::length(self : Source) -> Int

    Source::line_count

    fn Source::line_count(self : Source) -> Int

    Source::new

    fn Source::new(text : String) -> Source

    Source::position_at

    fn Source::position_at(self : Source, offset : Int) -> Position?

    Source::span

    fn Source::span(self : Source, start : Int, end : Int) -> Span?

    Source::text

    fn Source::text(self : Source) -> String

    Span

    pub struct Span {
    // private fields
    }

    Span::end

    fn Span::end(self : Span) -> Position

    Span::length

    fn Span::length(self : Span) -> Int

    Span::start

    fn Span::start(self : Span) -> Position

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io