1 {-# LANGUAGE OverloadedStrings #-}
3 module Data.Gargantext.Parsers.Occurrences where
5 import Data.Attoparsec.Text
6 import Data.Text (Text)
9 import Data.Either.Extra(Either(..))
10 import qualified Data.Text as T
11 import Control.Applicative
13 occurrenceParser :: Text -> Parser Bool
14 occurrenceParser txt = manyTill anyChar (string txt) >> pure True
16 occurrencesParser :: Text -> Parser Int
17 occurrencesParser txt = case txt of
19 _ -> many (occurrenceParser txt') >>= \matches -> pure (length matches)
23 parseOccurrences :: Text -> Text -> Either String Int
24 parseOccurrences x = parseOnly (occurrencesParser x)