Skip to content

Conversation

@TOTBWF
Copy link
Contributor

@TOTBWF TOTBWF commented Aug 5, 2025

It is surprisingly difficult to get haskell build tools to pass options to happy: cabal only lets you do it via cabal.project files or via --happy-options, and the --happy-option flag in stack is just flat-out broken. This PR tries to fix this by adding a OPTIONS_HAPPY pragma to the happy grammar, which lets you specify options to pass to happy directly within the .y file.

@TOTBWF TOTBWF changed the title Happy options pragma Add OPTIONS_HAPPY pragma for passing flags to happy Aug 5, 2025
Copy link
Collaborator

@sgraf812 sgraf812 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! I agree it would be a nice feature to have. But I have a few smaller suggestions.

sgraf812 and others added 6 commits August 16, 2025 17:56
…rse`

Otherwise we get a clash when users omit a `%name` declaration, because
then the default name for the parser is `happyParse`.
Suggested-by: Sebastian Graf <sgraf1337@gmail.com>
Suggested-by: Sebastian Graf <sgraf1337@gmail.com>
@sgraf812 sgraf812 force-pushed the happy-options-pragma branch from 3d906d7 to 0e38381 Compare August 16, 2025 16:08
@sgraf812 sgraf812 force-pushed the happy-options-pragma branch from 0e38381 to b4df3e2 Compare August 16, 2025 17:38
@sgraf812 sgraf812 merged commit eedf2e2 into haskell:master Aug 16, 2025
27 of 28 checks passed
@sgraf812
Copy link
Collaborator

Thanks! I released 2.1.7 with this feature.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Aug 21, 2025
## 2.1.7

* Add support for `{-# OPTIONS_HAPPY ... #-}` pragmas
  ([#342](haskell/happy#342)).

* Tested with GHC 8.0 - 9.12.2.
  The Haskell code generated by Happy is for GHC 8.0 and up.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Aug 21, 2025
## 2.1.7

* Add support for `{-# OPTIONS_HAPPY ... #-}` pragmas
  ([#342](haskell/happy#342)).

* Tested with GHC 8.0 - 9.12.2.
  The Haskell code generated by Happy is for GHC 8.0 and up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants