-- | Generalized cursors to be applied to different nodes.moduleText.XML.Cursor.Generic(-- * CoreCursor,Axis,toCursor,node-- * Axes,child,parent,precedingSibling,followingSibling,ancestor,descendant,orSelf,preceding,following-- * Operators,(&|),(&/),(&//),(&.//),($|),($/),($//),($.//),(>=>))whereimportData.Maybe(maybeToList)importData.List(foldl')importControl.Monad((>=>))typeDiffCursornode=[Cursornode]->[Cursornode]typeAxisnode=Cursornode->[Cursornode]-- | A cursor: contains an XML 'Node' and pointers to its children, ancestors and siblings.dataCursornode=Cursor{parent'::Maybe(Cursornode),precedingSibling'::DiffCursornode,followingSibling'::DiffCursornode-- | The child axis. XPath:-- /the child axis contains the children of the context node/.,child::[Cursornode]-- | The current node.,node::node}instanceShownode=>Show(Cursornode)whereshowCursor{node=n}="Cursor @ "++showntoCursor::(node->[node])-- ^ get children->node->CursornodetoCursorcs=toCursor'csNothingididtoCursor'::(node->[node])->Maybe(Cursornode)->DiffCursornode->DiffCursornode->node->CursornodetoCursor'csparprefoln=mewhereme=Cursorparprefolchinchi'=csnchi=goidchi'[]go_[]=idgopre'(n':ns')=(:)me'.fol'whereme'=toCursor'cs(Justme)pre'fol'n'fol'=go(pre'.(:)me')ns'-- | The parent axis. As described in XPath:-- /the parent axis contains the parent of the context node, if there is one/.---- Every node but the root element of the document has a parent. Parent nodes-- will always be 'NodeElement's.parent::Axisnodeparent=maybeToList.parent'-- | The preceding-sibling axis. XPath:-- /the preceding-sibling axis contains all the preceding siblings of the context node [...]/.precedingSibling::AxisnodeprecedingSibling=($[]).precedingSibling'-- | The following-sibling axis. XPath:-- /the following-sibling axis contains all the following siblings of the context node [...]/.followingSibling::AxisnodefollowingSibling=($[]).followingSibling'-- | The preceding axis. XPath:-- /the preceding axis contains all nodes in the same document as the context node that are before the context node in document order, excluding any ancestors and excluding attribute nodes and namespace nodes/.preceding::Axisnodeprecedingc=go(precedingSibling'c[])(parentc>>=preceding)wheregoxy=foldl'(flipgo')yxgo'xrest=foldl'(flipgo')(x:rest)(childx)-- | The following axis. XPath:-- /the following axis contains all nodes in the same document as the context node that are after the context node in document order, excluding any descendants and excluding attribute nodes and namespace nodes/.following::Axisnodefollowingc=go(followingSibling'c)(parentc>>=following)wheregoxz=foldrgo'z(x[])go'xrest=x:foldrgo'rest(childx)-- | The ancestor axis. XPath:-- /the ancestor axis contains the ancestors of the context node; the ancestors of the context node consist of the parent of context node and the parent's parent and so on; thus, the ancestor axis will always include the root node, unless the context node is the root node/.ancestor::Axisnodeancestor=parent>=>(\p->p:ancestorp)-- | The descendant axis. XPath:-- /the descendant axis contains the descendants of the context node; a descendant is a child or a child of a child and so on; thus the descendant axis never contains attribute or namespace nodes/.descendant::Axisnodedescendant=child>=>(\c->c:descendantc)-- | Modify an axis by adding the context node itself as the first element of the result list.orSelf::Axisnode->AxisnodeorSelfaxc=c:axcinfixr1&|infixr1&/infixr1&//infixr1&.//infixr1$|infixr1$/infixr1$//infixr1$.//-- | Apply a function to the result of an axis.(&|)::(Cursornode->[a])->(a->b)->(Cursornode->[b])f&|g=mapg.f-- | Combine two axes so that the second works on the children of the results-- of the first.(&/)::Axisnode->(Cursornode->[a])->(Cursornode->[a])f&/g=f>=>child>=>g-- | Combine two axes so that the second works on the descendants of the results-- of the first.(&//)::Axisnode->(Cursornode->[a])->(Cursornode->[a])f&//g=f>=>descendant>=>g-- | Combine two axes so that the second works on both the result nodes, and their-- descendants.(&.//)::Axisnode->(Cursornode->[a])->(Cursornode->[a])f&.//g=f>=>orSelfdescendant>=>g-- | Apply an axis to a 'Cursor node'.($|)::Cursornode->(Cursornode->a)->av$|f=fv-- | Apply an axis to the children of a 'Cursor node'.($/)::Cursornode->(Cursornode->[a])->[a]v$/f=childv>>=f-- | Apply an axis to the descendants of a 'Cursor node'.($//)::Cursornode->(Cursornode->[a])->[a]v$//f=descendantv>>=f-- | Apply an axis to a 'Cursor node' as well as its descendants.($.//)::Cursornode->(Cursornode->[a])->[a]v$.//f=orSelfdescendantv>>=f