Function withSpan

  • Wraps a parser so that its result includes span information (start and end positions). Useful for building ASTs with location data for language servers / editors. Requires setInputStr to have been called with the full input.

    Type Parameters

    • T

    Parameters

    Returns Parser<{
        span: Span;
        value: T;
    }>

    Example

    const locatedWord = withSpan(word);
    // Result: { value: "hello", span: { start: { offset: 0, line: 0, column: 0 }, end: { offset: 5, line: 0, column: 5 } } }

Generated using TypeDoc