-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple monadic DOM parser -- -- Simple monadic DOM parser @package dom-parser @version 0.1.1 module Text.XML.DOM.Parser.Types -- | DOM parser error description. data ParserError -- | Tag not found which should be. PENotFound :: [Text] -> ParserError -- | path of element [_pePath] :: ParserError -> [Text] -- | Tag contents has wrong format, (could not read text to value) PEWrongFormat :: Text -> [Text] -> ParserError [_peDetails] :: ParserError -> Text -- | path of element [_pePath] :: ParserError -> [Text] -- | Node should have text content, but it does not. PEContentNotFound :: [Text] -> ParserError -- | path of element [_pePath] :: ParserError -> [Text] -- | Some other error PEOther :: Text -> [Text] -> ParserError [_peDetails] :: ParserError -> Text -- | path of element [_pePath] :: ParserError -> [Text] pePath :: Lens' ParserError [Text] peDetails :: Traversal' ParserError Text newtype ParserErrors ParserErrors :: [ParserError] -> ParserErrors [unParserErrors] :: ParserErrors -> [ParserError] _ParserErrors :: Iso' ParserErrors [ParserError] -- | Parser scope parser runs in. Functor argument is usually -- Identity or []. -- -- If functor is Identity then parser expects exactly ONE -- current element. This is common behavior for content parsers, or -- parsers expecting strict XML structure. -- -- If functor is [] then parser expects arbitrary current -- elements count. This is the case when you use combinators -- divePath or diveElem (posible other variants of -- similar combinators). This kind of combinators performs search for -- elements somewhere in descendants and result have arbitrary length in -- common case. data ParserData f ParserData :: f Element -> [Text] -> ParserData f -- | Current element(s). Functor is intended to be either Identity -- or [] [_pdElements] :: ParserData f -> f Element -- | Path for error reporting [_pdPath] :: ParserData f -> [Text] pdElements :: forall f_aecI f_aegA. Lens (ParserData f_aecI) (ParserData f_aegA) (f_aecI Element) (f_aegA Element) pdPath :: forall f_aecI. Lens' (ParserData f_aecI) [Text] type DomParserT f m = ReaderT (ParserData f) (ExceptT ParserErrors m) type DomParser f = DomParserT f Identity -- | Run parser on root element of Document. runDomParserT :: (Monad m) => Document -> DomParserT Identity m a -> m (Either ParserErrors a) runDomParser :: Document -> DomParser Identity a -> Either ParserErrors a -- | Class of traversable functors which may be constructed from list. Or -- may not. class Traversable f => DomTraversable f -- | If method return Nothing this means we can not build traversable from -- given list. In this case combinator should fail traversing. buildDomTraversable :: DomTraversable f => [a] -> Maybe (f a) throwParserError :: (MonadError ParserErrors m, MonadReader (ParserData f) m) => ([Text] -> ParserError) -> m a -- | Throw PEWrongFormat as very common case throwWrongFormat :: (MonadError ParserErrors m, MonadReader (ParserData f) m) => Text -> m a instance Text.XML.DOM.Parser.Types.DomTraversable Data.Functor.Identity.Identity instance Text.XML.DOM.Parser.Types.DomTraversable [] instance Text.XML.DOM.Parser.Types.DomTraversable GHC.Base.Maybe instance Text.XML.DOM.Parser.Types.DomTraversable Data.List.NonEmpty.NonEmpty instance GHC.Exception.Exception Text.XML.DOM.Parser.Types.ParserErrors instance GHC.Generics.Generic Text.XML.DOM.Parser.Types.ParserErrors instance GHC.Base.Monoid Text.XML.DOM.Parser.Types.ParserErrors instance GHC.Show.Show Text.XML.DOM.Parser.Types.ParserErrors instance GHC.Classes.Eq Text.XML.DOM.Parser.Types.ParserErrors instance GHC.Classes.Ord Text.XML.DOM.Parser.Types.ParserErrors instance GHC.Exception.Exception Text.XML.DOM.Parser.Types.ParserError instance GHC.Generics.Generic Text.XML.DOM.Parser.Types.ParserError instance GHC.Show.Show Text.XML.DOM.Parser.Types.ParserError instance GHC.Classes.Ord Text.XML.DOM.Parser.Types.ParserError instance GHC.Classes.Eq Text.XML.DOM.Parser.Types.ParserError module Text.XML.DOM.Parser.Combinators -- | Generic function to traverse arbitrary inner cursors. traverseElems :: (Monad m, Foldable g, Traversable f) => ([Element] -> DomParserT g m (f ([Text], Element))) -> DomParserT Identity m a -> DomParserT g m (f a) -- | Takes function filtering inFilteredTrav :: (Monad m, Foldable g, DomTraversable f) => ([Element] -> ([Text], [Element])) -> DomParserT Identity m a -> DomParserT g m (f a) inElemTrav :: (Monad m, Foldable g, DomTraversable f) => Text -> DomParserT Identity m a -> DomParserT g m (f a) -- | Runs parser inside first children element with given name inElem :: (Monad m, Foldable g) => Text -> DomParserT Identity m a -> DomParserT g m a inElemAll :: (Monad m, Foldable g) => Text -> DomParserT Identity m a -> DomParserT g m [a] inElemMay :: (Monad m, Foldable g) => Text -> DomParserT Identity m a -> DomParserT g m (Maybe a) inElemNe :: (Monad m, Foldable g) => Text -> DomParserT Identity m a -> DomParserT g m (NonEmpty a) -- | Dive given parser's current tags set into the given path. The -- divePath ["a", "b"] differs from inElem "a" . inElem -- "b". Namely the first variant will not fail if occured tag "a" -- which does not contains tag "b". This behaviour is desireable when you -- dont want to parse whole XML and just want to pull tags in some path. -- The other difference is in traversing inner elements. Consider this -- code -- --
--   inElem "a" $ inElem "b" $ inElemAll "c" fromDom
--   
-- -- which translates to pseudo-CSS query like: a:nth(1) > b:nth(1) -- > c > fromDom -- --
--   divePath ["a", "b"] $ inElemAll "c" fromDom
--   
-- -- which translates like: a > b > c > fromDom -- -- As you can see, inElem always takes first element and runs inner -- parser in this single element, unlike divePath which runs inner -- parser in all descendants in given path. divePath :: forall m g a. (Monad m, Foldable g) => [Text] -> DomParserT [] m a -> DomParserT g m a diveElem :: (Monad m, Foldable g) => Text -> DomParserT [] m a -> DomParserT g m a -- | Ignore arbitrary current element if it conforms to predicate. ignoreElem :: (Monad m) => (Element -> Bool) -> DomParserT Identity m a -> DomParserT Identity m (Maybe a) -- | If current element has no children nodes does not run parser and -- returns Nothing. Otherwise runs parser inside current element. Usefull -- when you got XML with strange empty elements which must be just -- ignored, but inElem runs parser inside of this elements which -- causes to parser error. ignoreEmpty :: (Monad m) => DomParserT Identity m a -> DomParserT Identity m (Maybe a) -- | If all current elements contains blank content, or contains nothing at -- all , then returns Nothing, else runs parser. ignoreBlank :: (Monad m) => DomParserT Identity m a -> DomParserT Identity m (Maybe a) -- | If name of current tag differs from first argument throws -- PENotFound with tag name replaced in last path's segment. -- Usefull for checking root document's element name. checkCurrentName :: (Monad m) => Text -> DomParserT Identity m () -- | Parses content inside current tag. It expects current element set -- consists of exactly ONE element. Throws error if current elements set -- contains multiple of them. parseContent :: (Monad m) => (Text -> DomParserT Identity m a) -> DomParserT Identity m a readContent :: forall m g a. (Read a, Typeable a, Monad m) => Text -> DomParserT g m a module Text.XML.DOM.Parser.Class -- | Class of types which can be parsed from single XML element. class FromDom a fromDom :: (FromDom a, Monad m) => DomParserT Identity m a proxyFromDom :: forall proxy m a. (FromDom a, Monad m) => proxy a -> DomParserT Identity m a elementFromDom :: (Monad m) => DomParserT Identity m Element unionFromDom :: (Monad m, FromDom (Union as)) => proxy as -> DomParserT Identity m (Union as) textFromDom :: (Monad m) => DomParserT Identity m Text stringFromDom :: (Monad m) => DomParserT Identity m String charFromDom :: (Monad m) => DomParserT Identity m Char intFromDom :: (Monad m) => DomParserT Identity m Int integerFromDom :: (Monad m) => DomParserT Identity m Integer doubleFromDom :: (Monad m) => DomParserT Identity m Double fixedFromDom :: (Monad m, Typeable a, HasResolution a) => DomParserT Identity m (Fixed a) -- | Expects content to be y, yes, t, true or 1 for True value. n, no, f, -- false or 0 for False value. Case is not significant, blank characters -- are striped. boolFromDom :: (Monad m) => DomParserT Identity m Bool -- | Always successfully parses any DOM to () unitFromDom :: (Monad m) => DomParserT Identity m () -- | Never parses successfully. It is just mzero voidFromDom :: (Monad m) => DomParserT Identity m Void instance Text.XML.DOM.Parser.Class.FromDom () instance Text.XML.DOM.Parser.Class.FromDom Data.Void.Void instance Text.XML.DOM.Parser.Class.FromDom Data.Text.Internal.Text instance Text.XML.DOM.Parser.Class.FromDom GHC.Base.String instance Text.XML.DOM.Parser.Class.FromDom GHC.Types.Char instance Text.XML.DOM.Parser.Class.FromDom GHC.Types.Int instance Text.XML.DOM.Parser.Class.FromDom GHC.Integer.Type.Integer instance Text.XML.DOM.Parser.Class.FromDom GHC.Types.Double instance (Data.Fixed.HasResolution a, Data.Typeable.Internal.Typeable a) => Text.XML.DOM.Parser.Class.FromDom (Data.Fixed.Fixed a) instance Text.XML.DOM.Parser.Class.FromDom GHC.Types.Bool instance Text.XML.DOM.Parser.Class.FromDom (Data.OpenUnion.Internal.Union '[]) instance (Data.Typeable.Internal.Typeable a, Text.XML.DOM.Parser.Class.FromDom a, Text.XML.DOM.Parser.Class.FromDom (Data.OpenUnion.Internal.Union as), TypeFun.Data.List.SubList as (a : as)) => Text.XML.DOM.Parser.Class.FromDom (Data.OpenUnion.Internal.Union (a : as)) instance Text.XML.DOM.Parser.Class.FromDom Text.XML.Element module Text.XML.DOM.Parser