-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Simple monadic DOM parser
--   
--   Simple monadic DOM parser
@package dom-parser
@version 3.0.0

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 <tt>inFilteredTrav</tt> 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.Types

-- | Arbitrary element matcher
data ElemMatcher
ElemMatcher :: (Element -> Bool) -> Text -> ElemMatcher
[_emMatch] :: ElemMatcher -> Element -> Bool

-- | Field for <a>Show</a> 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 <a>Name</a>
[_nmMatch] :: NameMatcher -> Name -> Bool

-- | Field for <a>Show</a> instance and bulding usefull errors
[_nmShow] :: NameMatcher -> Text
nmMatch :: Lens' NameMatcher (Name -> Bool)
nmShow :: Lens' NameMatcher Text

-- | Makes matcher which match name by <a>Eq</a> 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 <tt>Identity</tt> or <tt>[]</tt>.
--   
--   If functor is <tt>Identity</tt> then parser expects exactly ONE
--   current element. This is common behavior for content parsers, or
--   parsers expecting strict XML structure.
--   
--   If functor is <tt>[]</tt> then parser expects arbitrary current
--   elements count. This is the case when you use combinators
--   <tt>divePath</tt> or <tt>diveElem</tt> (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 <tt>Identity</tt>
--   or <tt>[]</tt>
[_pdElements] :: ParserData f -> f Element

-- | Path for error reporting
[_pdPath] :: ParserData f -> DomPath
pdElements :: forall f_aq5h f_aqbI. Lens (ParserData f_aq5h) (ParserData f_aqbI) (f_aq5h Element) (f_aqbI Element)
pdPath :: forall f_aq5h. Lens' (ParserData f_aq5h) 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
--   <a>PENotFound</a> 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 <a>Nothing</a> then resulting function returns 'Left
--   "error message"'. <a>Typeable</a> 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 <a>Read</a>. Useful to use
--   with <a>parseContent</a> and <tt>parseAttribute</tt>. 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.FromDom

-- | Class of types which can be parsed from single XML element. The method
--   <a>fromDom</a> is convenient default to use with <tt>inElem</tt>
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
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 <tt>()</tt>
unitFromDom :: (Monad m) => DomParserT Identity m ()

-- | Never parses successfully. It is just <a>empty</a>
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 Text.XML.Element

module Text.XML.DOM.Parser.FromAttribute

-- | Class of types which can be get from attribute value. Method
--   <a>fromAttribute</a> is a convenient default parameter for
--   <tt>parseAttribute</tt>
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.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 <a>Buildable</a> instance of
--   <tt>f</tt>. For example if <tt>f</tt> becomes <a>NonEmpty</a> then
--   <a>inElemTrav</a> finds <tt>one or more</tt> elements matched by given
--   <a>ElemMatcher</a> and run parser in each found element, then returns
--   <tt>NonEmpty a</tt> 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
--   <tt>divePath ["a", "b"]</tt> differs from <tt>inElem "a" $ inElem
--   "b"</tt>. 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
--   
--   <pre>
--   inElem "a" $ inElem "b" $ inElemAll "c" fromDom
--   </pre>
--   
--   which translates to pseudo-CSS query like: <tt>a:nth(1) &gt; b:nth(1)
--   &gt; c &gt; fromDom</tt>
--   
--   <pre>
--   divePath ["a", "b"] $ inElemAll "c" fromDom
--   </pre>
--   
--   which translates like: <tt>a &gt; b &gt; c &gt; fromDom</tt>
--   
--   As you can see, inElem always takes first element and runs inner
--   parser in this single element, unlike <a>divePath</a> which runs inner
--   parser <tt>in all</tt> descendants in given path.
--   
--   Note also that <a>divePath</a> takes parser parameterized by
--   <tt>[]</tt> not by <a>Identity</a>. This because when you dive using
--   some path you will get a list of found elements and all these elements
--   will be <tt>current</tt> 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 <a>inElem</a> 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 <a>Nothing</a>
getCurrentAttribute :: (Monad m) => NameMatcher -> DomParserT Identity m (Maybe Text)

module Text.XML.DOM.Parser
