rule<E, A> function

Parser<E, A> rule<E, A>(
  1. Parser<E, A> thunk()
)

Creates a left-recursion-enabled memoized parser (Warth seed-growth).

Left-recursive rules like expr -> expr '+' term | term work without grammar transformation.

Place rule() at the level where left recursion occurs (e.g. chained postfix operations). For binary operator precedence, use chainl1 instead and make the rule the operand of the lowest chainl1 layer.

Implementation

Parser<E, A> rule<E, A>(Parser<E, A> Function() thunk) =>
    Memo<E, A>(Defer<E, A>(thunk), MemoKey<E, A>(), enableLR: true);