Function assert

  • Defines a TokenParser or SymbolParser that will execute parser and pass it's result to assertion.

    • If parser returns with an error, the error is propagated without executing the assertion
    • If assertion evaluates to some Identifiable object, that object will be returned as the error of the assertion.
    • If assertion evaluates to null, then the assertion is considered successful and the result of parser is propagated.

    It can be used to attach assertion operations in a parser result and determine if a token satisfies specific criteria at that lexical scope.

    Returns

    A new TokenParser or SymbolParser that will execute parser and attach assertion operations defined by assertion.

    Type Parameters

    Parameters

    • parser: TokenParser<D, E>

      The parser to which assertions are attached.

    • assertion: ((state: ParseState<D, E>) => null | E)

      The function which will either return a new error if the assertion is falsy, or null if the assertion is truthy.

    Returns TokenParser<D, E>

  • Type Parameters

    Parameters

    Returns SymbolParser<D, E>