Skip to content

Commit

Permalink
Add reUnknownExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
philderbeast committed Jan 7, 2024
1 parent 9c22057 commit 0c993a5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
17 changes: 11 additions & 6 deletions Cabal-described/src/Distribution/Described/Extension.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module Distribution.Described.Extension
( reEnableExtension
, reKnownExtension
, reUnknownExtension
, reDisableExtension
, reXs
-- * Extension groups
Expand Down Expand Up @@ -38,15 +39,22 @@ import Language.Haskell.Extension

instance Described Extension where
describe _ = REUnion
[ RENamed "enable-extension" reKnownExtension
, RENamed "disable-extension" reDisableExtension
[ reEnableExtension
, reDisableExtension
, reUnknownExtension
]

reXs :: [KnownExtension] -> GrammarRegex a
reXs xs = REUnion (fromString . prettyShow <$> xs)

reEnableExtension :: GrammarRegex a
reEnableExtension = "enable-extension"
reEnableExtension = RENamed "enable-known-extension" reKnownExtension

reDisableExtension :: GrammarRegex a
reDisableExtension = REUnion ["No" <> reEnableExtension]

reUnknownExtension :: GrammarRegex a
reUnknownExtension = RENamed "unknown-extension" RETodo

reKnownExtension :: GrammarRegex a
reKnownExtension = REUnion
Expand Down Expand Up @@ -74,9 +82,6 @@ reKnownExtension = REUnion
, RENamed "ungrouped-extension" $ reXs xUngrouped
]

reDisableExtension :: GrammarRegex a
reDisableExtension = REUnion ["No" <> RENamed "enable-extension" reKnownExtension]

-- The comments in the xGroup* lists are taken from the GHC User's Guide. Stop
-- the formatter from rearranging them with:
{- FOURMOLU_DISABLE -}
Expand Down
8 changes: 5 additions & 3 deletions Cabal-syntax-docs/ghc/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ main = do
contents <- run $ Z
{ zGhcBuildInfoFields = biGhc
, zProductions =
[ zproduction "disable-extension" reDisableExtension
[ zproduction "disable-known-extension" reDisableExtension
"Disable a language extension by prepending the extension with \"No\"."
, zproduction "enable-extension" reKnownExtension
"All GHC language extensions known to cabal. There may be more and some of these may be on by default."
, zproduction "enable-known-extension" reKnownExtension
"All \"known\" language extensions. There may be more and some of these may be on by default."
, zproduction "unknown-extension" reUnknownExtension
"Any token for any unknown extension is acceptable."
, zproduction "interactive-extension" (reXs xGroupInteractive)
"Language Extensions related to GHC interactive."
, zproduction "phase-extension" (reXs xGroupPhase)
Expand Down
27 changes: 18 additions & 9 deletions doc/ghc-syntax.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ default-extensions

.. math::
\mathrm{optcommalist}\left\{ \mathop{\mathit{enable\text{-}extension}}\mid\mathop{\mathit{disable\text{-}extension}} \right\}
\mathrm{optcommalist}\left\{ \mathop{\mathit{enable\text{-}known\text{-}extension}}\mid\mathop{\mathord{``}\mathtt{No}\mathord{"}}\mathop{\mathit{enable\text{-}known\text{-}extension}}\mid\mathop{\mathit{unknown\text{-}extension}} \right\}
.. _ghc-default-language:

Expand All @@ -39,7 +39,7 @@ extensions

.. math::
\mathrm{optcommalist}\left\{ \mathop{\mathit{enable\text{-}extension}}\mid\mathop{\mathit{disable\text{-}extension}} \right\}
\mathrm{optcommalist}\left\{ \mathop{\mathit{enable\text{-}known\text{-}extension}}\mid\mathop{\mathord{``}\mathtt{No}\mathord{"}}\mathop{\mathit{enable\text{-}known\text{-}extension}}\mid\mathop{\mathit{unknown\text{-}extension}} \right\}
.. _ghc-other-extensions:

Expand All @@ -49,7 +49,7 @@ other-extensions

.. math::
\mathrm{optcommalist}\left\{ \mathop{\mathit{enable\text{-}extension}}\mid\mathop{\mathit{disable\text{-}extension}} \right\}
\mathrm{optcommalist}\left\{ \mathop{\mathit{enable\text{-}known\text{-}extension}}\mid\mathop{\mathord{``}\mathtt{No}\mathord{"}}\mathop{\mathit{enable\text{-}known\text{-}extension}}\mid\mathop{\mathit{unknown\text{-}extension}} \right\}
.. _ghc-other-languages:

Expand Down Expand Up @@ -77,24 +77,33 @@ users' guide on language extensions.
of the ``.cabal`` file specification and shown here only as a convenience.
The GHC users' guide is the place to look these up.

.. _ghc-disable-extension:
.. _ghc-disable-known-extension:

disable-extension
disable-known-extension
Disable a language extension by prepending the extension with "No".

.. math::
\mathop{\mathord{``}\mathtt{No}\mathord{"}}\mathop{\mathit{enable\text{-}extension}}
\mathop{\mathord{``}\mathtt{No}\mathord{"}}\mathop{\mathit{enable\text{-}known\text{-}extension}}
.. _ghc-enable-extension:
.. _ghc-enable-known-extension:

enable-extension
All GHC language extensions known to cabal. There may be more and some of these may be on by default.
enable-known-extension
All "known" language extensions. There may be more and some of these may be on by default.

.. math::
\left\{ \begin{gathered}\mathop{\mathit{interactive\text{-}extension}}\\\mathop{\mathit{phase\text{-}extension}}\\\mathop{\mathit{syntax\text{-}extension}}\\\mathop{\mathit{import\text{-}export\text{-}extension}}\\\mathop{\mathit{type\text{-}extension}}\\\mathop{\mathit{record\text{-}extension}}\\\mathop{\mathit{deriving\text{-}extension}}\\\mathop{\mathit{pattern\text{-}extension}}\\\mathop{\mathit{classes\text{-}instances\text{-}extension}}\\\mathop{\mathit{literals\text{-}extension}}\\\mathop{\mathit{constraint\text{-}extension}}\\\mathop{\mathit{type\text{-}signature\text{-}extension}}\\\mathop{\mathit{binding\text{-}generalisation\text{-}extension}}\\\mathop{\mathit{template\text{-}haskell\text{-}extension}}\\\mathop{\mathit{bang\text{-}strict\text{-}extension}}\\\mathop{\mathit{parallel\text{-}concurrent\text{-}extension}}\\\mathop{\mathit{unboxed\text{-}primitive\text{-}extension}}\\\mathop{\mathit{foreign\text{-}extension}}\\\mathop{\mathit{safe\text{-}extension}}\\\mathop{\mathit{miscellaneous\text{-}extension}}\\\mathop{\mathit{bugs\text{-}extension}}\\\mathop{\mathit{ungrouped\text{-}extension}}\end{gathered} \right\}
.. _ghc-unknown-extension:

unknown-extension
Any token for any unknown extension is acceptable.

.. math::
\mathsf{\color{red}{TODO}}
.. _ghc-interactive-extension:

interactive-extension
Expand Down

0 comments on commit 0c993a5

Please sign in to comment.