module Data.OrgMode.Parse.Attoparsec.Util
( skipOnlySpace
, nonHeadline
)
where
import Control.Applicative ((<|>))
import qualified Data.Attoparsec.Text as Attoparsec.Text
import Data.Attoparsec.Types (Parser)
import Data.Text (Text)
import qualified Data.Text as Text
import Data.Functor (($>))
skipOnlySpace :: Parser Text ()
skipOnlySpace = Attoparsec.Text.skipWhile spacePred
where
spacePred s = s == ' ' || s == '\t'
nonHeadline :: Parser Text Text
nonHeadline = nonHeadline0 <|> nonHeadline1
where
nonHeadline0 = Attoparsec.Text.endOfLine $> Text.pack ""
nonHeadline1 = Text.pack <$> do
h <- Attoparsec.Text.notChar '*'
t <- Attoparsec.Text.manyTill Attoparsec.Text.anyChar Attoparsec.Text.endOfLine
pure (h:t)