- assert<D, E>(parser: TokenParser<D, E>, assertion: ((state: ParseState<D, E>) => null | E)): TokenParser<D, E>
-
Parameters
-
-
assertion: ((state: ParseState<D, E>) => null | E)
-
- (state: ParseState<D, E>): null | E
-
Returns null | E
- assert<D, E>(parser: SymbolParser<D, E>, assertion: ((state: ParseState<D, E>) => null | E)): SymbolParser<D, E>
-
Parameters
-
-
assertion: ((state: ParseState<D, E>) => null | E)
-
- (state: ParseState<D, E>): null | E
-
Returns null | E
Defines a TokenParser or SymbolParser that will execute
parser
and pass it's result toassertion
.parser
returns with an error, the error is propagated without executing theassertion
assertion
evaluates to some Identifiable object, that object will be returned as the error of the assertion.assertion
evaluates tonull
, then the assertion is considered successful and the result ofparser
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 byassertion
.