Extensions.Types

extensions-0.1.0.2: Parse Haskell Language Extensions

Copyright | (c) 2020-2022 Kowainik
License | MPL-2.0
Maintainer | Kowainik <xrom.xkov@gmail.com>
Safe Haskell | None
Language | Haskell2010

Extensions.Types

Contents

- Errors
  - Defaults / empty data types
- Enabled/Disabled Haskell2010 Extensions
- Safe Haskell Extensions
- Orphan instances

Description

Data types and functions to work with different types of `Extension`s.

`extensions` library supports the following types of extensions:

`Haskell2010` Default Enabled Extensions | `On` of `OnOffExtension`s
`Haskell2010` Default Disabled Extensions | `Off` of `OnOffExtension`s
`SafeHaskell` Extensions | `SafeHaskellExtension`s

Synopsis

- data Extensions = Extensions {
  - extensionsAll :: !(Set OnOffExtension)
  - extensionsSafe :: !(Maybe SafeHaskellExtension)
  }
- data ParsedExtensions = ParsedExtensions {
  - parsedExtensionsAll :: ![OnOffExtension]
  - parsedExtensionsSafe :: !(Maybe SafeHaskellExtension)
  }
- data CabalAndModuleExtensions = CabalAndModuleExtensions {
  - cabalExtensions :: !ParsedExtensions
  - moduleExtensions :: !ParsedExtensions
  }
- type ExtensionsResult = Either ExtensionsError Extensions
- data ExtensionsError
  - = ModuleParseError FilePath ModuleParseError
  - | CabalError CabalException
  - | SourceNotFound FilePath
  - | NotCabalModule FilePath
  - | SafeHaskellConflict (NonEmpty SafeHaskellExtension)
- data CabalException
  - = CabalFileNotFound FilePath
  - | CabalParseError Text
  - | CabalSafeExtensionsConflict (NonEmpty SafeHaskellExtension)
- data ModuleParseError
  - = ParsecError ParseError
  - | UnknownExtensions (NonEmpty String)
  - | ModuleSafeHaskellConflict (NonEmpty SafeHaskellExtension)
  - | FileNotFound FilePath
- emptyExtensions :: Extensions
- emptyParsedExtensions :: ParsedExtensions
- data OnOffExtension
  - = On Extension
  - | Off Extension
- showOnOffExtension :: OnOffExtension -> Text
- readOnOffExtension :: String -> Maybe OnOffExtension
- readExtension :: String -> Maybe Extension
- mergeExtensions :: [OnOffExtension] -> Set OnOffExtension
- mergeAnyExtensions :: ParsedExtensions -> ParsedExtensions -> ExtensionsResult
- default2010Extensions :: [Extension]
- data SafeHaskellExtension
  - = Unsafe
  - | Trustworthy
  - | Safe

# Documentation

data Extensions #

Main returned data type that includes merged `OnOffExtension`s and possibly one `SafeHaskellExtension`.

Constructors

Extensions |
Fields extensionsAll :: !(Set OnOffExtension) extensionsSafe :: !(Maybe SafeHaskellExtension)

#### Instances

Instances details

Show Extensions # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> Extensions -> ShowS # show :: Extensions -> String # showList :: [Extensions] -> ShowS #
Eq Extensions # |
Instance details Defined in Extensions.Types Methods (==) :: Extensions -> Extensions -> Bool # (/=) :: Extensions -> Extensions -> Bool #

data ParsedExtensions #

Extensions that are collected in the result of parsing `.cabal` file or Haskell module (both `OnOffExtension` and possibly one `SafeHaskellExtension`).

`OnOffExtension`s are not necessary unique. They reflect exactly the extensions found during parsing.

Constructors

ParsedExtensions |
Fields parsedExtensionsAll :: ![OnOffExtension] parsedExtensionsSafe :: !(Maybe SafeHaskellExtension)

#### Instances

Instances details

Show ParsedExtensions # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> ParsedExtensions -> ShowS # show :: ParsedExtensions -> String # showList :: [ParsedExtensions] -> ShowS #
Eq ParsedExtensions # |
Instance details Defined in Extensions.Types Methods (==) :: ParsedExtensions -> ParsedExtensions -> Bool # (/=) :: ParsedExtensions -> ParsedExtensions -> Bool #

data CabalAndModuleExtensions #

Stores extensions from `.cabal` file and module separately.

Constructors

CabalAndModuleExtensions |
Fields cabalExtensions :: !ParsedExtensions moduleExtensions :: !ParsedExtensions

#### Instances

Instances details

Show CabalAndModuleExtensions # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> CabalAndModuleExtensions -> ShowS # show :: CabalAndModuleExtensions -> String # showList :: [CabalAndModuleExtensions] -> ShowS #
Eq CabalAndModuleExtensions # |
Instance details Defined in Extensions.Types Methods (==) :: CabalAndModuleExtensions -> CabalAndModuleExtensions -> Bool # (/=) :: CabalAndModuleExtensions -> CabalAndModuleExtensions -> Bool #

type ExtensionsResult = Either ExtensionsError Extensions #

Type alias for the result of extensions analysis.

# Errors

data ExtensionsError #

Represents possible errors during the work of extensions analyser.

Constructors

ModuleParseError FilePath ModuleParseError | Parse error during module extensions parsing.
CabalError CabalException | Error during `.cabal` file reading/parsing.
SourceNotFound FilePath | File is in cabal file, but the source file is not provided where requested.
NotCabalModule FilePath | Source file is provided, but module is not in cabal file.
SafeHaskellConflict (NonEmpty SafeHaskellExtension) | Conflicting `SafeHaskellExtension`s in one scope.

#### Instances

Instances details

Show ExtensionsError # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> ExtensionsError -> ShowS # show :: ExtensionsError -> String # showList :: [ExtensionsError] -> ShowS #
Eq ExtensionsError # |
Instance details Defined in Extensions.Types Methods (==) :: ExtensionsError -> ExtensionsError -> Bool # (/=) :: ExtensionsError -> ExtensionsError -> Bool #

data CabalException #

Exception that gets thrown when working with `.cabal` files.

Constructors

CabalFileNotFound FilePath | The `.cabal` file is not found.
CabalParseError Text | Parsing errors in the `.cabal` file.
CabalSafeExtensionsConflict (NonEmpty SafeHaskellExtension) | Conflicting `SafeHaskellExtension`s in one scope.

#### Instances

Instances details

Exception CabalException # |
Instance details Defined in Extensions.Types Methods toException :: CabalException -> SomeException # fromException :: SomeException -> Maybe CabalException # displayException :: CabalException -> String # backtraceDesired :: CabalException -> Bool #
Show CabalException # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> CabalException -> ShowS # show :: CabalException -> String # showList :: [CabalException] -> ShowS #
Eq CabalException # |
Instance details Defined in Extensions.Types Methods (==) :: CabalException -> CabalException -> Bool # (/=) :: CabalException -> CabalException -> Bool #

data ModuleParseError #

Error while parsing Haskell source file.

Constructors

ParsecError ParseError | File parsing error.
UnknownExtensions (NonEmpty String) | Uknown extensions were used in the module.
ModuleSafeHaskellConflict (NonEmpty SafeHaskellExtension) | Conflicting `SafeHaskellExtension`s in one scope.
FileNotFound FilePath | Module file not found.

#### Instances

Instances details

Show ModuleParseError # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> ModuleParseError -> ShowS # show :: ModuleParseError -> String # showList :: [ModuleParseError] -> ShowS #
Eq ModuleParseError # |
Instance details Defined in Extensions.Types Methods (==) :: ModuleParseError -> ModuleParseError -> Bool # (/=) :: ModuleParseError -> ModuleParseError -> Bool #

## Defaults / empty data types

emptyExtensions :: Extensions #

Empty `Extensions` with no specified `SafeHaskellExtension`.

emptyParsedExtensions :: ParsedExtensions #

Empty `ParsedExtensions` with no specified `SafeHaskellExtension`.

# Enabled/Disabled Haskell2010 Extensions

data OnOffExtension #

Represents enabled/disabled extensions.

Constructors

On Extension |
Off Extension |

#### Instances

Instances details

Show OnOffExtension # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> OnOffExtension -> ShowS # show :: OnOffExtension -> String # showList :: [OnOffExtension] -> ShowS #
Eq OnOffExtension # |
Instance details Defined in Extensions.Types Methods (==) :: OnOffExtension -> OnOffExtension -> Bool # (/=) :: OnOffExtension -> OnOffExtension -> Bool #
Ord OnOffExtension # |
Instance details Defined in Extensions.Types Methods compare :: OnOffExtension -> OnOffExtension -> Ordering # (<) :: OnOffExtension -> OnOffExtension -> Bool # (<=) :: OnOffExtension -> OnOffExtension -> Bool # (>) :: OnOffExtension -> OnOffExtension -> Bool # (>=) :: OnOffExtension -> OnOffExtension -> Bool # max :: OnOffExtension -> OnOffExtension -> OnOffExtension # min :: OnOffExtension -> OnOffExtension -> OnOffExtension #

showOnOffExtension :: OnOffExtension -> Text #

Display `OnOffExtension` as GHC recognizes it.

readOnOffExtension :: String -> Maybe OnOffExtension #

Parse `OnOffExtension` from a string that specifies extension.

readExtension :: String -> Maybe Extension #

Parse `Extension` from a string. `Read` instance for `Extension` doesn't always work since some extensions are named differently.

mergeExtensions :: [OnOffExtension] -> Set OnOffExtension #

Take accumulated `OnOffExtension`s, and merge them into one `Set`, excluding enabling of `default2010Extensions`.

If the default extension is enabled manually it still won't count as it doesn't affect real behaviour. However, disabling of default extension will be included in the list.

So, basically, this set will only have `On` extensions that are not defaults, and `Off` extensions of defaults.

'foldl'' is used in order to process them in the right order: first all cabal extensions and then extensions from the module in the order of appearance.

mergeAnyExtensions #

Arguments

:: ParsedExtensions | Cabal parsed extensions.
-> ParsedExtensions | Module parsed extensions.
-> ExtensionsResult |

Similar to `mergeExtensions`, but also merge `SafeHaskellExtension`s. In case of conflicting `SafeHaskellExtension` returns `Left` with the pair of conflicting extension constructors under `SafeHaskellConflict` error.

default2010Extensions :: [Extension] #

Default enabled extensions for `Haskell2010`

# Safe Haskell Extensions

data SafeHaskellExtension #

Language extensions that are used by Safe Haskell to indicate safety of the code.

To find out more, checkout the official documentation on `SafeHaskell`:

- Safe Language Pragmas

Constructors

Unsafe |
Trustworthy |
Safe |

#### Instances

Instances details

Bounded SafeHaskellExtension # |
Instance details Defined in Extensions.Types Methods minBound :: SafeHaskellExtension # maxBound :: SafeHaskellExtension #
Enum SafeHaskellExtension # |
Instance details Defined in Extensions.Types Methods succ :: SafeHaskellExtension -> SafeHaskellExtension # pred :: SafeHaskellExtension -> SafeHaskellExtension # toEnum :: Int -> SafeHaskellExtension # fromEnum :: SafeHaskellExtension -> Int # enumFrom :: SafeHaskellExtension -> [SafeHaskellExtension] # enumFromThen :: SafeHaskellExtension -> SafeHaskellExtension -> [SafeHaskellExtension] # enumFromTo :: SafeHaskellExtension -> SafeHaskellExtension -> [SafeHaskellExtension] # enumFromThenTo :: SafeHaskellExtension -> SafeHaskellExtension -> SafeHaskellExtension -> [SafeHaskellExtension] #
Read SafeHaskellExtension # |
Instance details Defined in Extensions.Types Methods readsPrec :: Int -> ReadS SafeHaskellExtension # readList :: ReadS [SafeHaskellExtension] # readPrec :: ReadPrec SafeHaskellExtension # readListPrec :: ReadPrec [SafeHaskellExtension] #
Show SafeHaskellExtension # |
Instance details Defined in Extensions.Types Methods showsPrec :: Int -> SafeHaskellExtension -> ShowS # show :: SafeHaskellExtension -> String # showList :: [SafeHaskellExtension] -> ShowS #
Eq SafeHaskellExtension # |
Instance details Defined in Extensions.Types Methods (==) :: SafeHaskellExtension -> SafeHaskellExtension -> Bool # (/=) :: SafeHaskellExtension -> SafeHaskellExtension -> Bool #
Ord SafeHaskellExtension # |
Instance details Defined in Extensions.Types Methods compare :: SafeHaskellExtension -> SafeHaskellExtension -> Ordering # (<) :: SafeHaskellExtension -> SafeHaskellExtension -> Bool # (<=) :: SafeHaskellExtension -> SafeHaskellExtension -> Bool # (>) :: SafeHaskellExtension -> SafeHaskellExtension -> Bool # (>=) :: SafeHaskellExtension -> SafeHaskellExtension -> Bool # max :: SafeHaskellExtension -> SafeHaskellExtension -> SafeHaskellExtension # min :: SafeHaskellExtension -> SafeHaskellExtension -> SafeHaskellExtension #

# Orphan instances

Read Extension # |
Instance details Methods readsPrec :: Int -> ReadS Extension # readList :: ReadS [Extension] # readPrec :: ReadPrec Extension # readListPrec :: ReadPrec [Extension] #