
I've been hacking along on a NetBeans Haskell plugin (*) Looking at Parser.y.pp, because both Eclipse and NetBeans work with antlr, it seems like there are interesting cases in which chimeric constructions parse correctly. Here's an example: class ParsedModule m where let { a = 1; b = 2; } in a + b :: Int :: Int This is mostly accepted by ghc, which complains with an invalid type signature. This got me to thinking that either ghc has issues or I have some fundamental misunderstanding of Haskell syntax. Or, maybe I should use someone else's grammar. -scooter (*) Don't tell me about eclipsefp2: I know already. It's the Monty Python parrot of Haskell IDE support. And the code is about as Teutonic as one can get. :-)

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Apr 28, 2009, at 01:24 , Scott Michel wrote:
I've been hacking along on a NetBeans Haskell plugin (*) Looking at Parser.y.pp, because both Eclipse and NetBeans work with antlr, it seems like there are interesting cases in which chimeric constructions parse correctly. Here's an example:
class ParsedModule m where let { a = 1; b = 2; } in a + b :: Int :: Int
This is mostly accepted by ghc, which complains with an invalid type signature.
Looking at the Online Report, my guess is it parses as: exp^0 = "let {a = 1; b = 2; } in a + b" type = "Int :: Int" and of course "Int :: Int" is an invalid type signature. (::) parses as if it were a very low precedence operator. - -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.10 (Darwin) iEYEARECAAYFAkn3Xg4ACgkQIn7hlCsL25XQpgCdFnKgoxE8DlJWMpLTabR6gkIW tZIAnjnR8HheL8RtO87Z3ZteRqfHewUo =eptK -----END PGP SIGNATURE-----

2009/4/28 Scott Michel
This got me to thinking that either ghc has issues or I have some fundamental misunderstanding of Haskell syntax. Or, maybe I should use someone else's grammar.
GHC's parser is over-generous by design. See http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Parser. A precise description of what is valid Haskell it is certainly NOT, but it will certainly accept any valid Haskell program. This may not be quite what you want for an IDE - but it might be good enough for a first cut. Cheers, Max

On Tue, Apr 28, 2009 at 1:09 PM, Max Bolingbroke
2009/4/28 Scott Michel
: This got me to thinking that either ghc has issues or I have some fundamental misunderstanding of Haskell syntax. Or, maybe I should use someone else's grammar.
GHC's parser is over-generous by design. See http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/Parser. A precise description of what is valid Haskell it is certainly NOT, but it will certainly accept any valid Haskell program. This may not be quite what you want for an IDE - but it might be good enough for a first cut.
Actually, given what ghc will accept, I seriously doubt that the LR grammar can ever successfully translate to a LL(*) grammar. Liberal, it may be, but it probably should be valid. I just followed the current parser rules to their ultimate conclusion. I suspect that people would be quite surprised by what Parser.y.pp will actually accept. Basically, my understanding is that a 'let' should not be allowed in a 'class' declaration and yet, ghc is quite happy to allow it. So my understanding is correct, but ghc grammar is (perhaps) too flexible. -scooter PS: Anyone got a multicore Haskell experience they want to share at Supercomputing this year? The guys from Galois did a great job shocking the audience last year.
participants (3)
-
Brandon S. Allbery KF8NH
-
Max Bolingbroke
-
Scott Michel