module Data.OrgMode.Parse.Attoparsec.Drawer.Property
( parseProperties
, property
, PropertyKey
, PropertyVal
)
where
import Control.Applicative ((*>), (<*))
import Data.Attoparsec.Text as T
import Data.Attoparsec.Types as Attoparsec
import Data.HashMap.Strict (fromList)
import Data.Text (Text)
import qualified Data.Text as Text
import Prelude hiding (concat,
null, takeWhile)
import Data.OrgMode.Parse.Attoparsec.Drawer.Generic as Drawer.Generic
import Data.OrgMode.Types
type PropertyKey = Text
type PropertyVal = Text
parseProperties :: Attoparsec.Parser Text Properties
parseProperties = Properties . fromList <$> (drawerBegin *> manyTill property Drawer.Generic.drawerEnd)
where
drawerBegin = Drawer.Generic.parseDrawerDelim "PROPERTIES"
property :: Attoparsec.Parser Text (PropertyKey, PropertyVal)
property = (,) <$> parseKey <*> parseVal
where
parseKey = skipSpace *> skip (== ':') *> takeWhile1 (/= ':') <* skip (== ':')
parseVal = Text.strip <$> (skipSpace *> takeValue)
takeValue = takeWhile1 (not . isEndOfLine)