3

I'm building a lexer and parser with Alex and Happy. The code they generate throws a huge number of warnings with ghc-options: -Wall turned on in my project's .cabal file.

This makes it difficult to catch real warnings. How can I turn off the warnings only inside the generated files? I know it can be done with a pragma:

{#- GHC_OPTIONS -w -#}

But I can't think of an easy way to stick this pragma at the top of every generated file, every time they're rebuilt.

What's the right way to do this?

melpomene
  • 84,125
  • 8
  • 85
  • 148
Patrick Collins
  • 10,306
  • 5
  • 30
  • 69
  • How about organizing your cabal file so that the alex and happy modules are in their own library component, and use `ghc-options: -w` for that component? – ErikR Aug 08 '15 at 19:14

1 Answers1

5

A typical alex file begins with some stuff at the top - usually a module declaration which will get copied verbatim into the generated file:

{
module Main where
}
%wrapper "basic"
...

So just add the GHC_OPTIONS pragma before the module Main ... line, e.g.:

{
{-# GHC_OPTIONS -w #-}
module Main where
}
%wrapper "basic"

and it will be present in your generated file. The same can be done with happy files.

ErikR
  • 51,541
  • 9
  • 73
  • 124