[Haskell-cafe] Lazy Parsing
S. Doaitse Swierstra
doaitse at swierstra.net
Fri May 29 04:49:19 EDT 2009
In the uu-parsinglib we actually have two versions of parsers: lazy
ones and strict ones, which have different types. So by giving a type
annotation you can select the one you want. Notice that in the left-
hand side of a monadic construct it does not make sense to use a lazy
parser, since its result will be used as a parameter to the right-hand
side operator, so in case of a monad our library system automagically
selects the strict version for the left hand side. For the right hand
side it depends on the type of the overall expression. Unfortunately
in Haskell both the left and right hand side of a bind need the to be
elements of the same monad, whereas in the case of a lazy oevrall
parser this is not the case. We solve this problem by tupling the two
parsers (NOT the parsing results), so still the do-notation can be used.
The use of the library is free of any trickery!
Doaitse Swierstra
On 28 mei 2009, at 11:41, Malcolm Wallace wrote:
> Henning Thielemann <schlepptop at henning-thielemann.de> wrote:
>
>> I don't think that it is in general possible to use the same parser
>> for lazy and strict parsing, just because of the handling of parser
>> failure.
>
> Polyparse demonstrates that you can mix-and-match lazy parsers with
> strict parsers in the different parts of a grammar (by choosing
> whether
> to use applicative or monadic style). You can also switch between
> lazy
> or strict interpretations of the applicative parts of your grammar (by
> changing the import that decides which version of the parser
> primitives
> is in scope).
>
>> I also used polyparse for lazy parsing, but I found it unintuitive
>> how
>> to make a parser lazy.
>
> It can certainly be tricky, and requires a certain amount of
> experimentation. I think the difficulties are mainly due to the mix
> of
> lazy (applicative) and strict (monadic) styles in different
> non-terminals. A parser that you intend to be lazy, may turn out to
> be
> stricter than you hope, because of the strictness of another parser
> that
> it depends upon.
>
> Regards,
> Malcolm
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list