optional method

  1. @useResult
Parser<R?> optional()

Returns new parser that accepts the receiver, if possible. The resulting parser returns the result of the receiver, or null if not applicable.

For example, the parser letter().optional() accepts a letter as input and returns that letter. When given something else the parser succeeds as well, does not consume anything and returns null.

Implementation

@useResult
Parser<R?> optional() => OptionalParser<R?>(this, null);