module Data.Languages
( languagesForPath
, languages
, languagesByExtension
, languagesByFileName
, LanguageKey
, Language(..)
) where
import Control.Applicative
import qualified Data.Map.Strict as Map
import Data.Maybe
import Data.Text (Text)
import qualified Data.Text as Text
import Gen_Languages
import System.FilePath.Posix
languagesForPath :: FilePath -> [Language]
languagesForPath path = languageForFileName <|> languageForExtension
where
languageForFileName = languageFor (takeFileName path) languagesByFileName
languageForExtension = languageFor (takeExtension path) languagesByExtension
languageFor :: String -> Map.Map Text [LanguageKey] -> [Language]
languageFor k
= foldMap (maybeToList . flip Map.lookup languages)
. fromMaybe []
. Map.lookup (Text.pack k)