[Haskell-cafe] Re: Partial parsers in Happy

Simon Marlow simonmarhaskell at gmail.com
Tue Apr 17 08:06:40 EDT 2007


Juan Carlos Arevalo Baeza wrote:
>    More info: I managed to do a hack that works around it, but it is 
> clearly not acceptable. Part of the Haskell code generated by Happy 
> contains this:
> 
> ---------------------------------------------------------------------------
> -- Accepting the parse
> 
> -- If the current token is 0#, it means we've just accepted a partial
> -- parse (a %partial parser).  We must ignore the saved token on the top of
> -- the stack in this case.
> happyAccept 0# tk st sts (_ `HappyStk` ans `HappyStk` _) =
>     happyReturn1 ans
> happyAccept j tk st sts (HappyStk ans _) =
>     (happyTcHack j (happyTcHack st)) (happyReturn1 ans)
> 
>    That looked suspect. There's a "tk" parameter that is summarily 
> ignored! So I started mucking with it. ...

You're quite right, Happy does consume an extra token because it always has one 
token of lookahead.  The %partial feature was added mainly so that I could parse 
the header of a module in GHC without parsing the whole module, so I didn't need 
to recover and parse the rest of the module in this case.

By all means fix Happy in whatever way you think is useful, and send me the patch.

Cheers,
	Simon


More information about the Haskell-Cafe mailing list