{-# LINE 100 "Foo.hs #-} vs. # 100 "Foo.hs"

Marcin 'Qrczak' Kowalczyk qrczak@knm.org.pl
16 Jan 2001 21:09:07 GMT

Tue, 16 Jan 2001 19:47:31 +0000, Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk> pisze:

> I recently discovered that some of the GHC toolset actually
> generates and recognises
>              {-# LINE 100 "Foo.hs  -}
> which is somewhere in between a comment and a pragma.  Has
> this been fixed yet?

I've heard about it... Oops, it appears that since the CVS version
of ghc no longer translates cpp-style markers into LINE pragmas in
a separate pass, but interprets them itself in the compiler proper,
ghc -E does not perform that pass and now outputs cpp-style markers,
which do get into happy's templates. So it's indeed "fixed": to
cpp-style markers :-(

It can be properly fixed either by postprocessing the templates
during building of happy, or implementing that pass separately again
for explicit invocation of ghc -E. Since ghc -E does not seem to be
a widely used and very standard feature, perhaps it's enough to do
the former.

Moreover, there was one place internal to ghc which output
    {-# LINE 1 "File" -}
and I will commit a fix in a minute.

> The 1.00 release of nhc98 (incorrectly) rejects almost all pragmas.
> The 1.01 (CVS) version correctly accepts (but ignores) almost all
> pragmas.  In time, it will learn to use the information from a small
> number of pragmas.  When that happens, LINE can certainly be one
> of them.

ghc recognizes {-# together with the pragma's keyword during lexical
analysis, emits e.g. '{-# SPECIALIZE' as a single token, and treats
unrecognized pragmas as comments. nhc98 passes all pragmas to the

The difference is that ghc ignores pragmas with unknown keywords
placed in unusual places (e.g. in the middle of an expression),
where nhc98 flags them as errors.

Of course LINE can appear anywhere without respect to layout so must
be dealt with during the lexical analysis.

Haskell 98 does not say anything about case sensitivity of pragmas'
keywords but uses lowercase and mixedCase examples. ghc ignores the
case. hbc understands both all-uppercase and all-lowercase forms but
no mixing. I've seen only uppercase in practice. Perhaps something
should be said about it more explicitly. Perhaps official support
for uppercase only is enough (the rest of Haskell is case sensitive).

 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
  ^^                      SYGNATURA ZASTĘPCZA