
Library and CLI tool to parse Haskell {-# LANGUAGE #-} extensions in
source files, extract default-extensions from .cabal files and
combine together default-extensions and per-module extensions.
The extensions library provides a lightweight way to get Haskell
LANGUAGE pragmas for Haskell modules. It has the following goals:
extensions either as a library or as a tool is
straightforward.default-extensions in Cabal and {-# LANGUAGE #-}
pragmas in Haskell modules.extensions strives to
support as many valid syntactic constructions as possible, but it
may not work on every possible combination of CPP, comments and
pragmas, where GHC would work. We encouragle you to
open issue if
you encounter any failures when using extensions.You can use extensions either as a library or as a CLI tool.
extensions is compatible with the latest GHC compiler
versions starting from 8.8.3.
In order to start using extensions in your project, you
will need to set it up with the three easy steps:
Add the dependency on extensions in your project's
.cabal file. For this, you should modify the build-depends
section by adding the name of this library. After the adjustment,
this section could look like this:
build-depends: base ^>= 4.14
, extensions ^>= 0.0
In the module where you wish to extract extensions, you should add the import:
import Extensions (getPackageExtensions)
Now you can use the types and functions from the library:
main :: IO ()
main = getPackageExtensions "extensions.cabal" >>= print
If extensions is not available on your current Stackage
resolver yet, fear not! You can still use it from Hackage by adding
the following to the extra-deps section of your stack.yaml file:
extra-deps:
- extensions-0.0.0.0
To use extensions as a CLI tool, you need to install it either with Cabal
cabal install extensions
Stack
stack install extensions
or the nix package manager which allows you to use it ad-hoc via nix-shell -p haskellPackages.extensions --run extensions or to install via
nix-env -iA nixpkgs.haskellPackages.extensions
The tool can be used to inspect language extensions in your Haskell project. Some common usages of the tool:
default-extensions from the .cabal file.



Alternatively, you can extract Haskell Language extensions using the following ways:
ghc as a library. This approach ties you to a specific GHC
version and requires more effort to support multiple GHCs. Also,
GHC API is more complicated than extensions API (especially if
you want to handle CPP). And even with CPP handling from ghc
you won't be able to get all extensions defined in a
module. However, this approach allows you to fully reproduce GHC
behaviour.ghc-lib-parser. Same as the previous approach, but does not
tie you to a specific GHC version. However, ghc-lib-parser is
rather big dependency.haskell-src-exts library. This library parses Haskell
source files, but it's not actively maintained anymore and doesn't
support CPP.Haskell
100.0%

Library and CLI tool to parse Haskell {-# LANGUAGE #-} extensions in
source files, extract default-extensions from .cabal files and
combine together default-extensions and per-module extensions.
The extensions library provides a lightweight way to get Haskell
LANGUAGE pragmas for Haskell modules. It has the following goals:
extensions either as a library or as a tool is
straightforward.default-extensions in Cabal and {-# LANGUAGE #-}
pragmas in Haskell modules.extensions strives to
support as many valid syntactic constructions as possible, but it
may not work on every possible combination of CPP, comments and
pragmas, where GHC would work. We encouragle you to
open issue if
you encounter any failures when using extensions.You can use extensions either as a library or as a CLI tool.
extensions is compatible with the latest GHC compiler
versions starting from 8.8.3.
In order to start using extensions in your project, you
will need to set it up with the three easy steps:
Add the dependency on extensions in your project's
.cabal file. For this, you should modify the build-depends
section by adding the name of this library. After the adjustment,
this section could look like this:
build-depends: base ^>= 4.14
, extensions ^>= 0.0
In the module where you wish to extract extensions, you should add the import:
import Extensions (getPackageExtensions)
Now you can use the types and functions from the library:
main :: IO ()
main = getPackageExtensions "extensions.cabal" >>= print
If extensions is not available on your current Stackage
resolver yet, fear not! You can still use it from Hackage by adding
the following to the extra-deps section of your stack.yaml file:
extra-deps:
- extensions-0.0.0.0
To use extensions as a CLI tool, you need to install it either with Cabal
cabal install extensions
Stack
stack install extensions
or the nix package manager which allows you to use it ad-hoc via nix-shell -p haskellPackages.extensions --run extensions or to install via
nix-env -iA nixpkgs.haskellPackages.extensions
The tool can be used to inspect language extensions in your Haskell project. Some common usages of the tool:
default-extensions from the .cabal file.



Alternatively, you can extract Haskell Language extensions using the following ways:
ghc as a library. This approach ties you to a specific GHC
version and requires more effort to support multiple GHCs. Also,
GHC API is more complicated than extensions API (especially if
you want to handle CPP). And even with CPP handling from ghc
you won't be able to get all extensions defined in a
module. However, this approach allows you to fully reproduce GHC
behaviour.ghc-lib-parser. Same as the previous approach, but does not
tie you to a specific GHC version. However, ghc-lib-parser is
rather big dependency.haskell-src-exts library. This library parses Haskell
source files, but it's not actively maintained anymore and doesn't
support CPP.Haskell
100.0%