pointfreeco/swift-parsing

Explore branch and factor combinators for printer-parsers

echatav opened this issue · 1 comments

I think result builder syntax for printer-parsers should roughly correspond with combinators branch and factor with signatures like:

func factor<A,A0,A1>
  (A -> (A0, A1), (A0, A1) -> A)
  (Parser<A0>)
  (Parser<A1>)
  -> Parser<A>

func branch<A,A0,A1>
  (A -> Either<A0, A1>, Either<A0, A1> -> A)
  (Parser<A0>)
  (Parser<A1>)
  -> Parser<A>

Apologies for my poor Swift. The first arguments of factor and branch can be packaged up as Conversions.

Using the identity Conversion you can define operators like:

func >*< <A,A0,A1>
  (left: Parser<A0>, right: Parser<A1>)
  -> Parser<(A0,A1)>

func >|< <A,A0,A1>
  (left: Parser<A0>, right: Parser<A1>)
  -> Parser<Either<A0,A1>>