[Haskell-cafe] Parsers are monadic?
Malcolm Wallace
Malcolm.Wallace at cs.york.ac.uk
Wed Jul 4 12:38:11 EDT 2007
"Claus Reinke" <claus.reinke at talk21.com> wrote:
> (b) i like my combinator grammars to be reversible, so that a single
> grammar specification can be used for both parsing and
> unparsing/pretty-printing. that means i have to define the
> details myself anyway.
Oh cool - this is something I have wanted for a long time. Anything
released or otherwise available?
> about the only thing that spoils this nice setup is error handling.
> ... so it is easier to see where it is headed: a
> three-valued logic.
I wrote a set of monadic combinators (the polyparse library) for exactly
this reason - improving error messages (in HaXml originally). As
indeed, the basic error structure is a three-valued logic, with success
and two separate kinds of error:
type EitherE a b = Either (Bool,a) b
The error categories I used were "recoverable failure", to enable
backtracking, and "hard failure" to disallow backtracking when no
alternative good parses were possible. The combinator 'commit' changes
recoverable failures into hard failures.
I guess you could easily model this setup with three continuations
instead of a monad.
Regards,
Malcolm
More information about the Haskell-Cafe
mailing list