diff --git a/haskell/src/Web/UAParser.hs b/haskell/src/Web/UAParser.hs index caccf1a5..58b618b1 100644 --- a/haskell/src/Web/UAParser.hs +++ b/haskell/src/Web/UAParser.hs @@ -19,17 +19,7 @@ module Web.UAParser ------------------------------------------------------------------------------- -import Control.Applicative -import Control.Monad -import Data.Aeson -import Data.ByteString.Char8 (ByteString) -import qualified Data.ByteString.Char8 as B -import Data.Text (Text) -import qualified Data.Text as T -import qualified Data.Text.Encoding as T -import Data.Yaml import System.FilePath.Posix -import Text.Regex.PCRE.Light ------------------------------------------------------------------------------- import Paths_ua_parser import Web.UAParser.Core diff --git a/haskell/src/Web/UAParser/Core.hs b/haskell/src/Web/UAParser/Core.hs index 42f8ac6c..18d303ec 100644 --- a/haskell/src/Web/UAParser/Core.hs +++ b/haskell/src/Web/UAParser/Core.hs @@ -56,9 +56,10 @@ test = ------------------------------------------------------------------------------- +-- | Parse a given User-Agent string parseUA :: UAConfig - -- ^ Loaded parser data + -- ^ Loaded parser configuration data -> ByteString -- ^ User-Agent string to be parsed -> Maybe UAResult @@ -80,6 +81,7 @@ parseUA UAConfig{..} bs = foldr mplus Nothing $ map go uaParsers ------------------------------------------------------------------------------- +-- | Results datatype for the parsed User-Agent data UAResult = UAResult { uarFamily :: Text , uarV1 :: Maybe Text @@ -89,7 +91,7 @@ data UAResult = UAResult { ------------------------------------------------------------------------------- --- | Construct a browser versionstring from 'UAResult' +-- | Construct a browser version-string from 'UAResult' uarVersion :: UAResult -> Text uarVersion UAResult{..} = T.intercalate "." . catMaybes . takeWhile isJust $ [uarV1, uarV2, uarV3] @@ -107,6 +109,7 @@ instance Default UAResult where ------------------------------------------------------------------------------- +-- | Parse OS from given User-Agent string parseOS :: UAConfig -- ^ Loaded parser data @@ -161,6 +164,7 @@ loadConfig fp = either error id `fmap` decodeFile' fp ------------------------------------------------------------------------------- +decodeFile' :: FromJSON a => FilePath -> IO (Either String a) decodeFile' fp = decodeEither `fmap` B.readFile fp @@ -197,6 +201,7 @@ data DevParser = DevParser { ------------------------------------------------------------------------------- +parseRegex :: Object -> Parser Regex parseRegex v = flip compile [] `liftM` (v .: "regex") diff --git a/haskell/ua-parser.cabal b/haskell/ua-parser.cabal index 9e99cbef..d3d04e27 100644 --- a/haskell/ua-parser.cabal +++ b/haskell/ua-parser.cabal @@ -12,7 +12,6 @@ Cabal-version: >=1.6 data-files: ./*.yaml - test/test_resources/*.yaml Library hs-source-dirs: src