parserz icon indicating copy to clipboard operation
parserz copied to clipboard

Hide state from user API

Open sergei-shabanau opened this issue 5 years ago • 0 comments

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))

sergei-shabanau avatar Mar 28 '20 15:03 sergei-shabanau