parserz
parserz copied to clipboard
Hide state from user API
Currently state is exposed in grammars
sealed abstract class Grammar[-SI, +SO, +E, A]
This results in state container (a Tuple) being allocated and returned at each step of execution
case Grammar.GADT.Produce(a) => (s: S, i: Input) => (s, Right((i, a)))
which is a huge performance overhead.
What if state is only returned at the very end? So instead of
def parser[S, E, A](grammar: Grammar[S, S, E, A]): (S, Input) => (S, E \/ (Input, A))
we have
def parser[E, A](grammar: Grammar[E, A]): Input => (State, E \/ (Input, A))