[Haskell-cafe] Re: Proving my point
Achim Schneider
barsoap at web.de
Fri May 16 17:14:04 EDT 2008
Philippa Cowderoy <flippa at flippac.org> wrote:
> On Fri, 16 May 2008, Achim Schneider wrote:
>
> > Philippa Cowderoy <flippa at flippac.org> wrote:
> >
> > > On Fri, 16 May 2008, Achim Schneider wrote:
> > >
> > > Guess who ran into that with a separate token for
> > > layout-inserted braces?
> > >
> > It can't be me, as I attempted to be as lazy as possible, not going
> > for a tokenising pass, and ended up being too lazy.
> >
>
> Nah, you just picked the wrong way to attempt discipline. I don't use
> separate tokenising/lexing passes in a lot of my code (though you
> can't really avoid it when you want to do layout), it's a matter of
> knowing how it's done. Unless you've got a lexical structure that
> prevents it (which is to say, there're situations in which two tokens
> following each other aren't allowed to have whitespace between them),
> it's a good idea to have your token productions eat any whitespace
> following them, and then your toplevel becomes:
>
> do {whitespace; r <- realTopLevel; eof; return r}
>
> and then you need never worry about it again.
>
My problem is that realTopLevel = expr, and that I get into an infinite
recursion, never "closing" enough parens, never hitting eof.
Additionally, two passes are definitely easier to reason about, and
it's wise to be lazy there.
Btw: Is there any way to make Parsec return a tree of things it tried?
The end-user error messages are quite often just not informative enough
while debugging the parser itself.
--
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited.
More information about the Haskell-Cafe
mailing list