module Curry.Syntax.Extension
(
Extension (..), KnownExtension (..), classifyExtension, kielExtensions
, Tool (..), classifyTool
) where
import Data.Char (toUpper)
import Curry.Base.Ident (Ident (..))
import Curry.Base.Position
data Extension
= KnownExtension Position KnownExtension
| UnknownExtension Position String
deriving (Eq, Read, Show)
instance HasPosition Extension where
getPosition (KnownExtension p _) = p
getPosition (UnknownExtension p _) = p
setPosition p (KnownExtension _ e) = KnownExtension p e
setPosition p (UnknownExtension _ e) = UnknownExtension p e
data KnownExtension
= AnonFreeVars
| CPP
| FunctionalPatterns
| NegativeLiterals
| NoImplicitPrelude
deriving (Eq, Read, Show, Enum, Bounded)
classifyExtension :: Ident -> Extension
classifyExtension i = case reads extName of
[(e, "")] -> KnownExtension (getPosition i) e
_ -> UnknownExtension (getPosition i) extName
where extName = idName i
kielExtensions :: [KnownExtension]
kielExtensions = [AnonFreeVars, FunctionalPatterns]
data Tool = KICS2 | PAKCS | CYMAKE | FRONTEND | UnknownTool String
deriving (Eq, Read, Show)
classifyTool :: String -> Tool
classifyTool str = case reads (map toUpper str) of
[(t, "")] -> t
_ -> UnknownTool str