-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Simple monadic DOM parser -- -- Simple monadic DOM parser @package dom-parser @version 2.0.0 module Text.XML.DOM.Parser.Types -- | Arbitrary element matcher data ElemMatcher ElemMatcher :: (Element -> Bool) -> Text -> ElemMatcher [_emMatch] :: ElemMatcher -> Element -> Bool -- | Field for Show instance and bulding usefull errors [_emShow] :: ElemMatcher -> Text emMatch :: Lens' ElemMatcher (Element -> Bool) emShow :: Lens' ElemMatcher Text -- | Match element by name matchElemName :: NameMatcher -> ElemMatcher -- | Match over elements elMatch :: ElemMatcher -> Traversal' Element Element -- | Arbitrary name matcher. Match name any way you want, but considered to -- be used as comparator with some name with some rules data NameMatcher NameMatcher :: (Name -> Bool) -> Text -> NameMatcher -- | Name matching function, usually should be simple comparsion function -- takin in account only local name or other components of Name [_nmMatch] :: NameMatcher -> Name -> Bool -- | Field for Show instance and bulding usefull errors [_nmShow] :: NameMatcher -> Text nmMatch :: Lens' NameMatcher (Name -> Bool) nmShow :: Lens' NameMatcher Text -- | Makes matcher which match name by Eq with given matchName :: Name -> NameMatcher -- | Makes matcher which matches only local part of name igoring namespace -- and prefix. Local name matching is case sensitive. matchLocalName :: Text -> NameMatcher -- | Makes matcher which matches only local part of name igoring namespace -- and prefix. Local name matching is case insensitive. This is the most -- common case. matchCILocalName :: Text -> NameMatcher -- | Path some element should be found at. Path starts from the root -- element of the document. Errors are much more usefull with path. newtype DomPath DomPath :: [Text] -> DomPath [unDomPath] :: DomPath -> [Text] -- | DOM parser error description. data ParserError -- | Tag not found which should be. PENotFound :: DomPath -> ParserError -- | Path of element error occured in [_pePath] :: ParserError -> DomPath -- | Expected attribute but not found PEAttributeNotFound :: NameMatcher -> DomPath -> ParserError [_peAttributeName] :: ParserError -> NameMatcher -- | Path of element error occured in [_pePath] :: ParserError -> DomPath -- | Could not parse attribute PEAttributeWrongFormat :: NameMatcher -> Text -> DomPath -> ParserError [_peAttributeName] :: ParserError -> NameMatcher [_peDetails] :: ParserError -> Text -- | Path of element error occured in [_pePath] :: ParserError -> DomPath -- | Node should have text content, but it does not. PEContentNotFound :: DomPath -> ParserError -- | Path of element error occured in [_pePath] :: ParserError -> DomPath -- | Tag contents has wrong format, (could not read text to value) PEContentWrongFormat :: Text -> DomPath -> ParserError [_peDetails] :: ParserError -> Text -- | Path of element error occured in [_pePath] :: ParserError -> DomPath -- | Some other error PEOther :: Text -> DomPath -> ParserError [_peDetails] :: ParserError -> Text -- | Path of element error occured in [_pePath] :: ParserError -> DomPath pePath :: Lens' ParserError DomPath peDetails :: Traversal' ParserError Text peAttributeName :: Traversal' ParserError NameMatcher newtype ParserErrors ParserErrors :: [ParserError] -> ParserErrors [unParserErrors] :: ParserErrors -> [ParserError] _ParserErrors :: Iso' ParserErrors [ParserError] -- | Parser scope. -- -- 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 -> DomPath -> 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 -> DomPath pdElements :: forall f_aebQ f_aefF. Lens (ParserData f_aebQ) (ParserData f_aefF) (f_aebQ Element) (f_aefF Element) pdPath :: forall f_aebQ. Lens' (ParserData f_aebQ) DomPath 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 throwParserError :: (MonadError ParserErrors m, MonadReader (ParserData f) m) => (DomPath -> ParserError) -> m a 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.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.Base.Monoid Text.XML.DOM.Parser.Types.DomPath instance GHC.Show.Show Text.XML.DOM.Parser.Types.DomPath instance GHC.Classes.Ord Text.XML.DOM.Parser.Types.DomPath instance GHC.Classes.Eq Text.XML.DOM.Parser.Types.DomPath instance Data.String.IsString Text.XML.DOM.Parser.Types.NameMatcher instance GHC.Show.Show Text.XML.DOM.Parser.Types.NameMatcher instance Data.String.IsString Text.XML.DOM.Parser.Types.ElemMatcher instance GHC.Show.Show Text.XML.DOM.Parser.Types.ElemMatcher module Text.XML.DOM.Parser.Content -- | Parses content inside current tag. It expects current element set -- consists of exactly ONE element. parseContent :: (Monad m) => (Text -> Either Text a) -> DomParserT Identity m a -- | Returns name of current element. getCurrentName :: (Monad m) => DomParserT Identity m Name -- | Get current content. If current element contains no content or have -- inner elements then Nothing returned getCurrentContent :: (Monad m) => DomParserT Identity m (Maybe Text) -- | If name of current tag differs from first argument throws -- PENotFound with tag name replaced in last path's segment. -- Useful for checking root document's element name. checkCurrentName :: (Monad m) => NameMatcher -> DomParserT Identity m () -- | If reader returns Nothing then resulting function returns 'Left -- "error message"'. Typeable is used for generating usefull error -- message. maybeReadContent :: forall a. (Typeable a) => (Text -> Maybe a) -> Text -> Either Text a -- | Tries to read given text to value using Read. Useful to use -- with parseContent and parseAttribute. Content is -- stripped before reading. readContent :: (Read a, Typeable a) => Text -> Either Text a readBool :: Text -> Either Text Bool -- | Expects text to be single character readChar :: Text -> Either Text Char module Text.XML.DOM.Parser.FromAttribute -- | Class of types which can be get from attribute value. Method -- fromAttribute is a convenient default parameter for -- parseAttribute class FromAttribute a fromAttribute :: FromAttribute a => Text -> Either Text a proxyFromAttribute :: FromAttribute a => Proxy a -> Text -> Either Text a textFromAttribute :: Text -> Either Text Text stringFromAttribute :: Text -> Either Text String charFromAttribute :: Text -> Either Text Char intFromAttribute :: Text -> Either Text Int integerFromAttribute :: Text -> Either Text Integer doubleFromAttribute :: Text -> Either Text Double fixedFromAttribute :: (HasResolution a, Typeable a) => Text -> Either Text (Fixed a) boolFromAttribute :: Text -> Either Text Bool unitFromAttribute :: Text -> Either Text () voidFromAttribute :: Text -> Either Text Void scientificFromAttribute :: Text -> Either Text Scientific instance Text.XML.DOM.Parser.FromAttribute.FromAttribute () instance Text.XML.DOM.Parser.FromAttribute.FromAttribute Data.Void.Void instance Text.XML.DOM.Parser.FromAttribute.FromAttribute Data.Text.Internal.Text instance Text.XML.DOM.Parser.FromAttribute.FromAttribute GHC.Base.String instance Text.XML.DOM.Parser.FromAttribute.FromAttribute GHC.Types.Char instance Text.XML.DOM.Parser.FromAttribute.FromAttribute GHC.Types.Int instance Text.XML.DOM.Parser.FromAttribute.FromAttribute GHC.Integer.Type.Integer instance Text.XML.DOM.Parser.FromAttribute.FromAttribute GHC.Types.Double instance (Data.Typeable.Internal.Typeable a, Data.Fixed.HasResolution a) => Text.XML.DOM.Parser.FromAttribute.FromAttribute (Data.Fixed.Fixed a) instance Text.XML.DOM.Parser.FromAttribute.FromAttribute GHC.Types.Bool instance Text.XML.DOM.Parser.FromAttribute.FromAttribute Data.Scientific.Scientific module Text.XML.DOM.Parser.FromDom -- | Class of types which can be parsed from single XML element. The method -- fromDom is convenient default to use with inElem 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 Values n, no, f, -- false or 0 for False. 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 empty voidFromDom :: (Monad m) => DomParserT Identity m Void scientificFromDom :: Monad m => DomParserT Identity m Scientific instance Text.XML.DOM.Parser.FromDom.FromDom () instance Text.XML.DOM.Parser.FromDom.FromDom Data.Void.Void instance Text.XML.DOM.Parser.FromDom.FromDom Data.Text.Internal.Text instance Text.XML.DOM.Parser.FromDom.FromDom GHC.Base.String instance Text.XML.DOM.Parser.FromDom.FromDom GHC.Types.Char instance Text.XML.DOM.Parser.FromDom.FromDom GHC.Types.Int instance Text.XML.DOM.Parser.FromDom.FromDom GHC.Integer.Type.Integer instance Text.XML.DOM.Parser.FromDom.FromDom GHC.Types.Double instance (Data.Fixed.HasResolution a, Data.Typeable.Internal.Typeable a) => Text.XML.DOM.Parser.FromDom.FromDom (Data.Fixed.Fixed a) instance Text.XML.DOM.Parser.FromDom.FromDom Data.Scientific.Scientific instance Text.XML.DOM.Parser.FromDom.FromDom GHC.Types.Bool instance Text.XML.DOM.Parser.FromDom.FromDom (Data.OpenUnion.Internal.Union '[]) instance (Data.Typeable.Internal.Typeable a, Text.XML.DOM.Parser.FromDom.FromDom a, Text.XML.DOM.Parser.FromDom.FromDom (Data.OpenUnion.Internal.Union as), TypeFun.Data.List.SubList as (a : as)) => Text.XML.DOM.Parser.FromDom.FromDom (Data.OpenUnion.Internal.Union (a : as)) instance Text.XML.DOM.Parser.FromDom.FromDom Text.XML.Element module Text.XML.DOM.Parser.Buildable -- | Class of traversable functors which may be constructed from list class Traversable f => Buildable f -- | If method return Nothing this means we can not build traversable from -- given list. In this case inFilteredTrav should fail -- traversing. build :: Buildable f => [a] -> Maybe (f a) instance Text.XML.DOM.Parser.Buildable.Buildable Data.Functor.Identity.Identity instance Text.XML.DOM.Parser.Buildable.Buildable [] instance Text.XML.DOM.Parser.Buildable.Buildable GHC.Base.Maybe instance Text.XML.DOM.Parser.Buildable.Buildable Data.List.NonEmpty.NonEmpty module Text.XML.DOM.Parser.Combinators -- | Generic function to traverse arbitrary inner elements. traverseElems :: (Monad m, Foldable g, Traversable f) => ([Element] -> DomParserT g m (f (DomPath, Element))) -> DomParserT Identity m a -> DomParserT g m (f a) -- | Traverses elements located in same path using filtering function inFilteredTrav :: (Monad m, Foldable g, Buildable f) => ([Element] -> (DomPath, [Element])) -> DomParserT Identity m a -> DomParserT g m (f a) -- | Runs parser arbitrary times, depending on Buildable instance of -- f. For example if f becomes NonEmpty then -- inElemTrav finds one or more elements matched by given -- ElemMatcher and run parser in each found element, then returns -- NonEmpty a of results. inElemTrav :: (Monad m, Foldable g, Buildable f) => ElemMatcher -> DomParserT Identity m a -> DomParserT g m (f a) -- | Runs parser inside first children element matched by macher inElem :: (Monad m, Foldable g) => ElemMatcher -> DomParserT Identity m a -> DomParserT g m a inElemAll :: (Monad m, Foldable g) => ElemMatcher -> DomParserT Identity m a -> DomParserT g m [a] inElemMay :: (Monad m, Foldable g) => ElemMatcher -> DomParserT Identity m a -> DomParserT g m (Maybe a) inElemNe :: (Monad m, Foldable g) => ElemMatcher -> 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 located 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. -- -- Note also that divePath takes parser parameterized by -- [] not by Identity. This because when you dive using -- some path you will get a list of found elements and all these elements -- will be current for parser. divePath :: forall m g a. (Monad m, Foldable g) => [ElemMatcher] -> DomParserT [] m a -> DomParserT g m a diveElem :: (Monad m, Foldable g) => ElemMatcher -> 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. Useful -- 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) module Text.XML.DOM.Parser.Attributes -- | Parses attribute with given name, throws error if attribute is not -- found. parseAttribute :: (Monad m) => NameMatcher -> (Text -> Either Text a) -> DomParserT Identity m a -- | Parses attribute with given name. Returns Nothing if attribute is not -- found. parseAttributeMaybe :: (Monad m) => NameMatcher -> (Text -> Either Text a) -> DomParserT Identity m (Maybe a) -- | Retuns map of attributes of current element getCurrentAttributes :: (Monad m) => DomParserT Identity m (Map Name Text) -- | Returns element with given name or Nothing getCurrentAttribute :: (Monad m) => NameMatcher -> DomParserT Identity m (Maybe Text) module Text.XML.DOM.Parser