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