logo
pub fn optional<'a, Input: 'a>(
    input: Input
) -> IResult<Input, Optional<Input>, Error<Input>> where
    Input: Clone + Display + Offset + InputLength + InputTake + InputTakeAtPosition<Item = char> + Slice<RangeFrom<usize>> + InputIter + for<'s> Compare<&'s str>,
    <Input as InputIter>::Item: AsChar + Copy,
    Error<Input>: ParseError<Input>,
    for<'s> &'s str: FindToken<<Input as InputIter>::Item>, 
Expand description

Parses an optional as defined in the grammar spec.

Grammar

optional           = '(' text-in-optional+ ')'
text-in-optional   = (- optional-to-escape) | ('\', optional-to-escape)
optional-to-escape = '(' | ')' | '{' | '/' | '\'

Example

(name)
(with spaces)
(escaped \/\{\()
(no need to escape })
(🦀)

Errors

Recoverable Error

  • If input doesn’t start with (.

Irrecoverable Failure