module Language.Haskell.Extension (
Extension(..),
knownExtensions
) where
import Distribution.Text (Text(..))
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
import qualified Data.Char as Char (isAlphaNum)
import Data.Array (Array, accumArray, bounds, Ix(inRange), (!))
data Extension
= OverlappingInstances
| UndecidableInstances
| IncoherentInstances
| RecursiveDo
| ParallelListComp
| MultiParamTypeClasses
| NoMonomorphismRestriction
| FunctionalDependencies
| Rank2Types
| RankNTypes
| PolymorphicComponents
| ExistentialQuantification
| ScopedTypeVariables
| ImplicitParams
| FlexibleContexts
| FlexibleInstances
| EmptyDataDecls
| CPP
| KindSignatures
| BangPatterns
| TypeSynonymInstances
| TemplateHaskell
| ForeignFunctionInterface
| Arrows
| Generics
| NoImplicitPrelude
| NamedFieldPuns
| PatternGuards
| GeneralizedNewtypeDeriving
| ExtensibleRecords
| RestrictedTypeSynonyms
| HereDocuments
| MagicHash
| TypeFamilies
| StandaloneDeriving
| UnicodeSyntax
| PatternSignatures
| UnliftedFFITypes
| LiberalTypeSynonyms
| TypeOperators
| RecordWildCards
| RecordPuns
| DisambiguateRecordFields
| OverloadedStrings
| GADTs
| NoMonoPatBinds
| RelaxedPolyRec
| ExtendedDefaultRules
| UnboxedTuples
| DeriveDataTypeable
| ConstrainedClassMethods
| PackageImports
| ImpredicativeTypes
| NewQualifiedOperators
| PostfixOperators
| QuasiQuotes
| TransformListComp
| ViewPatterns
| UnknownExtension String
deriving (Show, Read, Eq)
knownExtensions :: [Extension]
knownExtensions =
[ OverlappingInstances
, UndecidableInstances
, IncoherentInstances
, RecursiveDo
, ParallelListComp
, MultiParamTypeClasses
, NoMonomorphismRestriction
, FunctionalDependencies
, Rank2Types
, RankNTypes
, PolymorphicComponents
, ExistentialQuantification
, ScopedTypeVariables
, ImplicitParams
, FlexibleContexts
, FlexibleInstances
, EmptyDataDecls
, CPP
, KindSignatures
, BangPatterns
, TypeSynonymInstances
, TemplateHaskell
, ForeignFunctionInterface
, Arrows
, Generics
, NoImplicitPrelude
, NamedFieldPuns
, PatternGuards
, GeneralizedNewtypeDeriving
, ExtensibleRecords
, RestrictedTypeSynonyms
, HereDocuments
, MagicHash
, TypeFamilies
, StandaloneDeriving
, UnicodeSyntax
, PatternSignatures
, UnliftedFFITypes
, LiberalTypeSynonyms
, TypeOperators
, RecordWildCards
, RecordPuns
, DisambiguateRecordFields
, OverloadedStrings
, GADTs
, NoMonoPatBinds
, RelaxedPolyRec
, ExtendedDefaultRules
, UnboxedTuples
, DeriveDataTypeable
, ConstrainedClassMethods
, PackageImports
, ImpredicativeTypes
, NewQualifiedOperators
, PostfixOperators
, QuasiQuotes
, TransformListComp
, ViewPatterns
]
instance Text Extension where
disp (UnknownExtension other) = Disp.text other
disp other = Disp.text (show other)
parse = do
extension <- Parse.munch1 Char.isAlphaNum
return (classifyExtension extension)
classifyExtension :: String -> Extension
classifyExtension string@(c:_)
| inRange (bounds extensionTable) c
= case lookup string (extensionTable ! c) of
Just extension -> extension
Nothing -> UnknownExtension string
classifyExtension string = UnknownExtension string
extensionTable :: Array Char [(String, Extension)]
extensionTable =
accumArray (flip (:)) [] ('A', 'V')
[ (head str, (str, extension))
| extension <- knownExtensions
, let str = show extension ]