dartpetitparser

What is an example of use case for epsilon in dart petitparser?


I don't understand the comment:

/// Returns a parser that consumes nothing and succeeds.
///
/// For example, `char('a').or(epsilon())` is equivalent to
/// `char('a').optional()`.
@useResult
Parser<void> epsilon() => epsilonWith<void>(null);

Could someone give a specific example?


Solution

  • It appears to do exactly what it says. Instead of writing "foo = optional bar" you can define a step with "foo = bar or epsilon".

    In the "indent" parser in the repo, I see it is used to attach .where and .map options with side-effects. You can check that out for details.