Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I suppress warnings in generated code?

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?

like image 657
Patrick Collins Avatar asked Sep 05 '25 01:09

Patrick Collins


1 Answers

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.

like image 147
ErikR Avatar answered Sep 07 '25 16:09

ErikR