Creates a Parser that tries to apply the given parser optionally. It returns the inner parser's result if succesful, and otherwise indicates success at the starting offset with a null
value.
If the inner parser returns a fatal failure, the error is returned as-is.
Signature:
export declare function optional<T>(parser: Parser<T>): Parser<T | null>;
Parameter | Type | Description |
---|---|---|
parser | Parser<T> | Parser to attempt to apply |
Returns:
Parser<T | null>