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