Disabling warnings in generated Haskell code

21 views
Skip to first unread message

Iván Pérez

unread,
Jan 6, 2021, 3:25:21 PM1/6/21
to BNFC Developers and Users
Hi everyone!

I'm running GHC with all warnings enabled and it's reporting numerous issues with code generated by BFNC.

Although those should not be ignored in the long run, right now I'd like to disable them to focus on the warnings for the code I wrote in Haskell myself.

Normally, you'd do this by adding an OPTIONS_GHC -w pragma to the top of the file (unless someone knows a better way), but that would mean I'd have to change every file. Because my grammar files change often, it's going to become annoying soon.

Is there any way of telling BNFC to add the necessary pragmas to disable all warnings?

Thanks,
Ivan

Andreas Abel

unread,
Jan 8, 2021, 5:25:04 AM1/8/21
to bnfc...@googlegroups.com
Hello Ivan,

what I do in this case is to

- do the modification (e.g. adding these pragmas) once
- record a patch using `diff`
(See https://www.thegeekstuff.com/2014/12/patch-command-examples/)
- modify the `Makefile` to automatically `patch` the BNFC-generated files

E.g., one of my `Makefile`s has this rule
```
cmm/Yylex $(CUPFILE) cmm/Test.java cmm/Absyn/Exp.java : cmm.cf Exp.patch
bnfc --java $<
patch --input=Exp.patch cmm/Absyn/Exp.java
```
The last line is the relevant line here.

Hope that helps as a workaround.

Apparently, BNFC 2.7.1 generated warning-free Haskell code for GHC 7.4:


https://github.com/BNFC/bnfc/blame/0ad87322fce4cfe309512fa9fd56a63a06ff9c19/source/CHANGELOG.md#L117

We should recover this, I filed https://github.com/BNFC/bnfc/issues/331.

Cheers,
Andreas
> --
> You received this message because you are subscribed to the Google
> Groups "BNFC Developers and Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to bnfc-dev+u...@googlegroups.com
> <mailto:bnfc-dev+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bnfc-dev/54346555-0ea9-43e2-9f04-1ece41c44b75n%40googlegroups.com
> <https://groups.google.com/d/msgid/bnfc-dev/54346555-0ea9-43e2-9f04-1ece41c44b75n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Gáspár Erdélyi

unread,
Jan 8, 2021, 5:34:57 AM1/8/21
to BNFC Developers and Users
Hello Ivan and Andreas,

  I have some different modications: the best is to have the modification as a patch that can be applied by a modification in the Makefile.
  Then patching will become part of making automatically.

Best regars,
Gaspar

To unsubscribe from this group and stop receiving emails from it, send an email to bnfc-dev+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bnfc-dev/7e1a14e7-3a5f-8294-082d-e04e7ca49a4f%40ifi.lmu.de.

Iván Pérez

unread,
Feb 5, 2021, 3:07:46 PM2/5/21
to BNFC Developers and Users
Thanks!

So, I'm not using makefiles, and, in our internal policy, keeping a patch that we apply later to automatically-generated code is discouraged (I'd say there are good reasons for that).

I ended up being able to deal with this differently for my use case. In my cabal file, I:

- Created an internal library that holds the grammar(s) only. The compilation flags do NOT include -Wall.
- Created a library that imports the other internal library. The compilation flags DO include -Wall.

Fin

Ivan

Andreas Abel

unread,
Mar 1, 2021, 3:38:09 AM3/1/21
to BNFC Developers and Users
Hi Ivan,

I made some effort to eliminate warnings from the generated Haskell code.
Please try if BNFC 2.9.1 solves your problem (released just now).

Best,
Andreas

Iván Pérez

unread,
Mar 2, 2021, 2:43:01 PM3/2/21
to BNFC Developers and Users
This is fantastic! Thanks a lot! I tried it and it works perfectly.

So, and I'm saying this knowing that it's always "easier said than done": Do you think it might be possible to also make BNFC generate warning free haddock comments?

I'm not familiar enough with Alex and Happy (I used them, but mostly like a decade ago). They may not allow you to control the comments of the definitions they put in the generated Lex* and Par* modules. For some modules (like the AST and the Pretty Printers), it might be as simple as adding the grammar rules that the definitions come from.

Cheers,

Ivan

Andreas Abel

unread,
Mar 10, 2021, 2:50:10 AM3/10/21
to bnfc...@googlegroups.com
On 2021-03-02 20:43, Iván Pérez wrote:
> This is fantastic! Thanks a lot! I tried it and it works perfectly.

Great!

> So, and I'm saying this knowing that it's always "easier said than
> done": Do you think it might be possible to also make BNFC generate
> warning free haddock comments? >
> I'm not familiar enough with Alex and Happy (I used them, but mostly
> like a decade ago). They may not allow you to control the comments of
> the definitions they put in the generated Lex* and Par* modules.

Indeed. The code they produce is not for human consumption.

You could create wrapper modules that reexport the lexer and parser and
include some haddockumentation.

> For some modules (like the AST and the Pretty Printers), it might be as
> simple as adding the grammar rules that the definitions come from.

We are planning this for BNFC 3.0 at least for the AST.

Best,
Andreas
> <https://www.thegeekstuff.com/2014/12/patch-command-examples/>)
>    - modify the `Makefile` to automatically `patch` the
> BNFC-generated files
>
> E.g., one of my `Makefile`s has this rule
> ```
> cmm/Yylex $(CUPFILE) cmm/Test.java cmm/Absyn/Exp.java :
> cmm.cf <http://cmm.cf> Exp.patch
>         bnfc --java $<
>         patch --input=Exp.patch cmm/Absyn/Exp.java
> ```
> The last line is the relevant line here.
>
> Hope that helps as a workaround.
>
> Apparently, BNFC 2.7.1 generated warning-free Haskell
> code for GHC 7.4:
>
>
> https://github.com/BNFC/bnfc/blame/0ad87322fce4cfe309512fa9fd56a63a06ff9c19/source/CHANGELOG.md#L117
> <https://github.com/BNFC/bnfc/blame/0ad87322fce4cfe309512fa9fd56a63a06ff9c19/source/CHANGELOG.md#L117>
>
> We should recover this, I filed
> https://github.com/BNFC/bnfc/issues/331
> <https://github.com/BNFC/bnfc/issues/331>.
> <https://groups.google.com/d/msgid/bnfc-dev/54346555-0ea9-43e2-9f04-1ece41c44b75n%40googlegroups.com?utm_medium=email&utm_source=footer
> <https://groups.google.com/d/msgid/bnfc-dev/54346555-0ea9-43e2-9f04-1ece41c44b75n%40googlegroups.com?utm_medium=email&utm_source=footer>>.
>
> --
> You received this message because you are subscribed to
> the Google Groups "BNFC Developers and Users" group.
>
> To unsubscribe from this group and stop receiving emails
> from it, send an email to bnfc-dev+u...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bnfc-dev/7e1a14e7-3a5f-8294-082d-e04e7ca49a4f%40ifi.lmu.de
> <https://groups.google.com/d/msgid/bnfc-dev/7e1a14e7-3a5f-8294-082d-e04e7ca49a4f%40ifi.lmu.de>.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "BNFC Developers and Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/bnfc-dev/kap38pxxg28/unsubscribe
> <https://groups.google.com/d/topic/bnfc-dev/kap38pxxg28/unsubscribe>.
> To unsubscribe from this group and all its topics, send an email to
> bnfc-dev+u...@googlegroups.com
> <mailto:bnfc-dev+u...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/bnfc-dev/989499cf-a4c3-49b8-b27e-9d9aa5fde264n%40googlegroups.com
> <https://groups.google.com/d/msgid/bnfc-dev/989499cf-a4c3-49b8-b27e-9d9aa5fde264n%40googlegroups.com?utm_medium=email&utm_source=footer>.
Reply all
Reply to author
Forward
0 new messages