[GHC] #7396: Improve "parse error on input `$'" when TemplateHaskell PRAGMA not declared
GHC
cvs-ghc at haskell.org
Wed Nov 7 03:12:13 CET 2012
#7396: Improve "parse error on input `$'" when TemplateHaskell PRAGMA not declared
---------------------------------+------------------------------------------
Reporter: ydewit | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Template Haskell | Version: 7.4.2
Keywords: | Os: MacOS X
Architecture: x86 | Failure: Building GHC failed
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
---------------------------------+------------------------------------------
Changes (by simonpj):
* difficulty: => Unknown
* type: bug => feature request
Old description:
> Spent close to 1h chasing what possibly could go wrong here:
> {{{
> import Data.Binary
> import Data.DeriveTH
>
> data Test = Pass | Failed
>
> $(derive makeBinary ''Test)
> }}
>
> Until, stupid me, I realized that the TemplateHaskell PRAGMA was missing.
> Could this message be a bit more friendly pointing me to the real issue?
>
> If fixing this is simple, you could give me a few pointers and I'll try
> to provide a patch even though my Haskell experience is a bit thin.
New description:
Spent close to 1h chasing what possibly could go wrong here:
{{{
import Data.Binary
import Data.DeriveTH
data Test = Pass | Failed
$(derive makeBinary ''Test)
}}}
Until, stupid me, I realized that the TemplateHaskell PRAGMA was missing.
Could this message be a bit more friendly pointing me to the real issue?
If fixing this is simple, you could give me a few pointers and I'll try to
provide a patch even though my Haskell experience is a bit thin.
--
Comment:
The error I get is
{{{
T7396.hs:5:1: parse error on input `$'
}}}
which of course is right, absent TH. Is that what happened to you?
I think one could improve the error mesage by parsing a top-level
declaration splice (which is otherwise not legal Haskell 98), and then
reporting "Perhaps you meant -XTemplateHaskell" in the renamer, or
something like that.
But for expression splices it's not so easy:
{{{
f x = g $(foo)
}}}
really does mean something in Haskell 98, namely
{{{
f x = f $ foo
}}}
So in expressions we can't parse as TH and reject later.
If you want to have a shot at this, by all means. One difficulty is that
the ''lexer'' recognises the token "`$(`" as a single lexeme when TH is
on. It can't do that when TH is off. Maybe in the parser you can have a
new production
{{{
topdecl ::= '$' '(' exp ')'
}}}
but I have not thought through all the consequences.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7396#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list