packages feed

xml 1.3.2 → 1.3.3

raw patch · 2 files changed

+24/−9 lines, 2 files

Files

Text/XML/Light/Cursor.hs view
@@ -6,10 +6,10 @@ -- -- Maintainer: Iavor S. Diatchki <diatchki@galois.com> -- Stability : provisional--- Portability:+-- Portability: portable -- -- XML cursors for working XML content withing the context of--- an XML document.  This implemntation is based on the general+-- an XML document.  This implementation is based on the general -- tree zipper written by Krasimir Angelov and Iavor S. Diatchki. -- @@ -32,11 +32,13 @@   , lastChild   , left   , right+  , nextDF    -- ** Searching   , findChild   , findLeft   , findRight+  , findRec    -- * Node classification   , isRoot@@ -69,6 +71,7 @@  import Text.XML.Light.Types import Data.Maybe(isNothing)+import Control.Monad(mplus)  data Tag = Tag { tagName    :: QName                , tagAttribs :: [Attr]@@ -167,6 +170,18 @@   do loc1 <- firstChild loc      if p loc1 then return loc1 else findRight p loc1 +-- | The next position in a left-to-right depth-first traversal of a document:+-- either the first child, right sibling, or the right sibling of a parent that+-- has one.+nextDF :: Cursor -> Maybe Cursor+nextDF c = firstChild c `mplus` up c+  where up x = right x `mplus` (up =<< parent x)++-- | Perform a depth first search for a descendant that satisfies the+-- given predicate.+findRec :: (Cursor -> Bool) -> Cursor -> Maybe Cursor+findRec p c = if p c then Just c else findRec p =<< nextDF c+ -- | The child with the given index (starting from 0). getChild :: Int -> Cursor -> Maybe Cursor getChild n loc =@@ -186,11 +201,11 @@  -- Conversions ----------------------------------------------------------------- --- | A cursor for the guven content.+-- | A cursor for the given content. fromContent :: Content -> Cursor fromContent t = Cur { current = t, lefts = [], rights = [], parents = [] } --- | A cursor for the guven element.+-- | A cursor for the given element. fromElement :: Element -> Cursor fromElement e = fromContent (Elem e) @@ -264,13 +279,13 @@ insertRight :: Content -> Cursor -> Cursor insertRight t loc = loc { rights = t : rights loc } --- | Remove the conent on the left of the current position, if any.+-- | Remove the content on the left of the current position, if any. removeLeft :: Cursor -> Maybe (Content,Cursor) removeLeft loc = case lefts loc of                    l : ls -> return (l,loc { lefts = ls })                    [] -> Nothing --- | Remove the conent on the right of the current position, if any.+-- | Remove the content on the right of the current position, if any. removeRight :: Cursor -> Maybe (Content,Cursor) removeRight loc = case rights loc of                     l : ls -> return (l,loc { rights = ls })@@ -314,7 +329,7 @@   -- | private: Gets the given element of a list.--- Also returns the preceeding elements (reversed) and the folloing elements.+-- Also returns the preceding elements (reversed) and the following elements. splitChildren :: [a] -> Int -> Maybe ([a],a,[a]) splitChildren _ n | n < 0 = Nothing splitChildren cs pos = loop [] cs pos
xml.cabal view
@@ -1,6 +1,6 @@ Name:            xml-Version:         1.3.2-Homepage:        http://galois.com+Version:         1.3.3+Homepage:        http://code.galois.com Synopsis:        A simple XML library. Description:     A simple XML library. Category:        Text, XML