annotate src/ur/feed.urs @ 8:a4e5d053daed

Preparation for first release
author Adam Chlipala <adam@chlipala.net>
date Sat, 19 Mar 2011 14:35:11 -0400
parents 05a28a77f6fe
children f19beef42ceb
rev   line source
adam@8 1 (* This module implements imperative processing of XML feeds.
adam@8 2 *
adam@8 3 * Module author: Adam Chlipala
adam@8 4 *)
adam@8 5
adam@1 6 con pattern :: Type -> Type -> Type
adam@8 7 (* A pattern describes a set of XML subtrees, mapping each element of the set to
adam@8 8 * a data value. A value of type [pattern internal result] uses values of type
adam@8 9 * [internal] internally, but this API exposes no details of that usage. The
adam@8 10 * type [result] gives the type used in mappings of matched subtrees. *)
adam@8 11
adam@8 12 val null : pattern unit (variant [])
adam@8 13 (* A null pattern matches nothing, returning a value of the impossible empty
adam@8 14 * type if it ever does match. *)
adam@1 15
adam@1 16 con tagInternal :: {Unit} -> Type
adam@1 17
adam@1 18 val tag : attrs ::: {Unit} -> folder attrs -> string -> $(mapU string attrs)
adam@1 19 -> pattern (tagInternal attrs) {Attrs : $(mapU string attrs), Cdata : option string}
adam@8 20 (* A basic [tag] pattern matches a single tag with a number of required
adam@8 21 * attributes. A result value gives the attribute values and an optional
adam@8 22 * CDATA value for the text content of the tag. The [string] argument is the
adam@8 23 * tag name, and the following argument gives attribute names. *)
adam@1 24
adam@3 25 val tagA : attrs ::: {Unit} -> folder attrs -> string -> $(mapU string attrs)
adam@3 26 -> pattern (tagInternal attrs) $(mapU string attrs)
adam@8 27 (* A version of [tag] that ignores CDATA *)
adam@8 28
adam@6 29 val tagAO : attrs ::: {Unit} -> folder attrs -> string -> $(mapU string attrs)
adam@6 30 -> pattern (tagInternal attrs) $(mapU (option string) attrs)
adam@8 31 (* A version of [tagA] that makes each attribute optional *)
adam@6 32
adam@3 33 val tagC : string -> pattern (tagInternal []) string
adam@8 34 (* A version of [tag] that only matches tags with nonempty CDATA and returns
adam@8 35 * only that text *)
adam@3 36
adam@1 37 con childrenInternal :: Type -> {Type} -> Type
adam@1 38
adam@1 39 val children : parentI ::: Type -> parent ::: Type -> children ::: {(Type * Type)}
adam@1 40 -> pattern parentI parent -> $(map (fn (i, d) => pattern i d) children) -> folder children
adam@1 41 -> pattern (childrenInternal parentI (map fst children)) (parent * $(map snd children))
adam@8 42 (* A combinator that takes in a pattern for a parent node and a set of patterns
adam@8 43 * that must be matched against children of the parent. This combinator will
adam@8 44 * find at most one match per matching parent node. *)
adam@8 45
adam@6 46 val childrenO : parentI ::: Type -> parent ::: Type -> children ::: {(Type * Type)}
adam@6 47 -> pattern parentI parent -> $(map (fn (i, d) => pattern i d) children) -> folder children
adam@6 48 -> pattern (childrenInternal parentI (map fst children)) (parent * $(map (fn (i, d) => option d) children))
adam@8 49 (* A version of [children] where each child pattern need not be matched *)
adam@1 50
adam@4 51 con treeInternal :: Type -> Type -> Type
adam@4 52
adam@4 53 val tree : parentI ::: Type -> parent ::: Type -> childI ::: Type -> child ::: Type
adam@4 54 -> pattern parentI parent -> pattern childI child
adam@4 55 -> pattern (treeInternal parentI childI) (parent * child)
adam@8 56 (* A combinator that takes in a pattern for a parent node and another pattern to
adam@8 57 * be matched at any depth within the parent's subtree. Unlike [children],
adam@8 58 * [tree] finds as many subtree matches per parent node as possible. *)
adam@4 59
adam@5 60 type document
adam@7 61 val show_document : show document
adam@8 62 (* Type of uninterpreted XML documents *)
adam@5 63
adam@8 64 val fetch : string -> transaction document
adam@8 65 (* Retrieve a document by URL. *)
adam@8 66
adam@5 67 val app : internal ::: Type -> data ::: Type -> pattern internal data -> (data -> transaction {}) -> document -> transaction {}
adam@8 68 (* Find all matches of a pattern in a document, running an imperative function
adam@8 69 * on the data returned by each match. *)