extensions: Parse Haskell Language Extensions

[ ghc, haskell, library, mpl, parsing ] [ Propose Tags ] [ Report a vulnerability ]

Parse Haskell Language Extensions. See README.md for more details.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
executable

Build the extensions executable

Enabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.0.0.0, 0.0.0.1, 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.1.0.3
Change log CHANGELOG.md
Dependencies base (>=4.13.0.0 && <4.22), bytestring (>=0.10 && <0.13), Cabal (>=3.14 && <3.15), colourista (>=0.1 && <0.3), containers (>=0.6 && <0.8), directory (>=1.3 && <1.4), extensions, filepath (>=1.4 && <1.6), ghc-boot-th (>=8.8.1 && <9.13), optparse-applicative (>=0.15 && <0.19), parsec (>=3.1 && <3.2), text (>=1.2.3 && <2.2) [details]
Tested with ghc ==8.8.4, ghc ==8.10.7, ghc ==9.0.2, ghc ==9.2.4, ghc ==9.4.2, ghc ==9.6.3, ghc ==9.8.1, ghc ==9.10.1
License MPL-2.0
Copyright 2020-2022 Kowainik
Author Veronika Romashkina, Dmitrii Kovanikov
Maintainer Kowainik <xrom.xkov@gmail.com>
Revised Revision 1 made by tomjaguarpaw at 2024-12-23T15:38:54Z
Category GHC, Parsing, Haskell
Home page https://github.com/kowainik/extensions
Bug tracker https://github.com/kowainik/extensions/issues
Source repo head: git clone https://github.com/kowainik/extensions.git
Uploaded by tomjaguarpaw at 2024-09-28T17:03:03Z
Distributions NixOS:0.1.0.1
Reverse Dependencies 1 direct, 2 indirect [details]
Executables extensions
Downloads 3757 total (186 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for extensions-0.1.0.3

[back to package description]

extensions

Logo

GitHub CI Hackage MPL-2.0 license

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.

Goals

The extensions library provides a lightweight way to get Haskell LANGUAGE pragmas for Haskell modules. It has the following goals:

  1. Be lightweight. Dependency footprint is extremely small, and using extensions either as a library or as a tool is straightforward.
  2. Support both default-extensions in Cabal and {-# LANGUAGE #-} pragmas in Haskell modules.
  3. Should work on common and real cases. 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.

How to use

You can use extensions either as a library or as a CLI tool.

Library

Usage with Cabal

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:

  1. 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
    
  2. In the module where you wish to extract extensions, you should add the import:

    import Extensions (getPackageExtensions)
    
  3. Now you can use the types and functions from the library:

    main :: IO ()
    main = getPackageExtensions "extensions.cabal" >>= print
    

Usage with Stack

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

CLI tool

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:

  1. Get all extensions in all modules, combined with default-extensions from the .cabal file. All extensions
  2. Get all extensions for a specific module, combined with Cabal extensions. Module extensions
  3. Get extensions defined only in a module. Only module

Alternatives

Alternatively, you can extract Haskell Language extensions using the following ways:

  1. Using 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.
  2. Using 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.
  3. Using the haskell-src-exts library. This library parses Haskell source files, but it's not actively maintained anymore and doesn't support CPP.