Skip to content

Latest commit

 

History

History
26 lines (15 loc) · 822 Bytes

prsc.optional.md

File metadata and controls

26 lines (15 loc) · 822 Bytes

Home > prsc > optional

optional() function

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>;

Parameters

Parameter Type Description
parser Parser<T> Parser to attempt to apply

Returns:

Parser<T | null>