Restrictions auf defaultValue pruefen.
[cxml-rng.git] / package.lisp
blob101c684efd943a38ce55136cdfebeb2b8de04608
1 (defpackage :cxml-rng
2 (:use :cl)
3 (:export #:rng-error
4 #:dtd-compatibility-error
5 #:rng-error-line-number
6 #:rng-error-column-number
7 #:rng-error-system-id
9 #:schema
10 #:schema-start
12 #:parse-schema
13 #:parse-compact
14 #:serialize-schema
15 #:make-validator
16 #:make-validating-source
18 #:pattern
19 #:element
20 #:attribute
21 #:group
22 #:interleave
23 #:choice
24 #:one-or-more
25 #:ref
26 #:empty
27 #:text
28 #:value
29 #:data
30 #:not-allowed
31 #:list-pattern
33 #:pattern-a
34 #:pattern-b
35 #:pattern-child
36 #:pattern-element
37 #:pattern-except
38 #:pattern-name
39 #:pattern-params
40 #:pattern-string
41 #:pattern-type
42 #:pattern-value
44 #:name-class
45 #:any-name
46 #:name
47 #:ns-name
48 #:name-class-choice
50 #:any-name-except
51 #:name-uri
52 #:name-lname
53 #:ns-name-uri
54 #:ns-name-except
55 #:name-class-choice-a
56 #:name-class-choice-b)
57 (:documentation
58 "@code{cxml-rng} implements @a[http://relaxng.org/spec-20011203.html]{
59 Relax NG} schema validation for Closure XML.
61 Support for @a[http://relaxng.org/compact-20021121.html]{Compact Syntax}
62 is included.
64 @begin[Example]{section}
65 @begin{pre}(cxml:parse-file \"test.xml\"
66 (cxml-rng:make-validator
67 (cxml-rng:parse-schema #p\"test.rng\")))
68 @end{pre}
69 @end{section}
70 @begin[Classes]{section}
71 @aboutclass{schema}
72 @aboutclass{rng-error}
73 @aboutclass{dtd-compatibility-error}
74 @end{section}
75 @begin[Parsing and validating]{section}
76 @aboutfun{parse-schema}
77 @aboutfun{parse-compact}
78 @aboutfun{make-validator}
79 @aboutfun{serialize-grammar}
80 @end{section}
81 @begin[Grammar introspection]{section}
82 The following classes and function are exported so that users can
83 take a peek at the internals of the parsed and simplified grammar.
85 @aboutfun{schema-start}
86 @aboutclass{attribute}
87 @aboutclass{choice}
88 @aboutclass{data}
89 @aboutclass{element}
90 @aboutclass{empty}
91 @aboutclass{group}
92 @aboutclass{interleave}
93 @aboutclass{list-pattern}
94 @aboutclass{not-allowed}
95 @aboutclass{one-or-more}
96 @aboutclass{pattern}
97 @aboutclass{ref}
98 @aboutclass{text}
99 @aboutclass{value}
100 @aboutfun{pattern-child}
101 @aboutfun{pattern-a}
102 @aboutfun{pattern-b}
103 @aboutfun{pattern-name}
104 @aboutfun{pattern-element}
105 @aboutfun{pattern-type}
106 @aboutfun{pattern-string}
107 @aboutfun{pattern-value}
108 @aboutfun{pattern-params}
109 @aboutfun{pattern-except}
110 @end{section}"))
112 (defpackage :cxml-types
113 (:use :cl)
114 (:export #:param
115 #:make-param
116 #:param-name
117 #:param-value
119 #:data-type
120 #:find-type
121 #:type-library
122 #:type-name
123 #:type-context-dependent-p
124 #:type-id-type
125 #:parse
126 #:equal-using-type
127 #:lessp-using-type
128 #:validp
129 #:validation-context
130 #:sax-validation-context-mixin
131 #:klacks-validation-context
132 #:make-klacks-validation-context
133 #:context-find-namespace-binding
134 #:context-find-unparsed-entity
135 #:rng-type
136 #:token-type
137 #:string-type
139 #:dtd-compatibility-type
140 #:id-type
141 #:idref-type
142 #:idrefs-type
144 #:xsd-type
145 #:patterns
146 #:min-exclusive
147 #:max-exclusive
148 #:min-inclusive
149 #:max-inclusive
150 #:min-length
151 #:max-length
152 #:exact-length
153 #:fraction-digits
154 #:total-digits
156 #:duration-type
157 #:date-time-type
158 #:time-type
159 #:date-type
160 #:year-month-type
161 #:year-type
162 #:month-day-type
163 #:day-type
164 #:month-type
165 #:boolean-type
166 #:base64-binary-type
167 #:hex-binary-type
168 #:float-type
169 #:decimal-type
170 #:double-type
171 #:any-uri-type
172 #:qname-type
173 #:notation-type
174 #:xsd-string-type
175 #:normalized-string-type
176 #:xsd-token-type
177 #:language-type
178 #:name-type
179 #:ncname-type
180 #:xsd-id-type
181 #:xsd-idref-type
182 #:xsd-idrefs-type
183 #:entity-type
184 #:entities-type
185 #:nmtoken-type
186 #:nmtokens-type
187 #:integer-type
188 #:non-positive-integer-type
189 #:negative-integer-type
190 #:long-type
191 #:int-type
192 #:short-type
193 #:byte-type
194 #:non-negative-integer-type
195 #:unsigned-long-type
196 #:unsigned-int-type
197 #:unsigned-short-type
198 #:unsigned-byte-type
199 #:positive-integer-type)
200 (:documentation
201 "@code{cxml-types} defines an extensible interface for XML-related
202 data types as required for use in Relax NG validation.
204 It includes Relax NG's minimal built-in type library, which is named
205 @code{:||} and defines the types \"string\" and \"token\".
207 In addition, it implements the built-in types of
208 @a[http://www.w3.org/TR/xmlschema-2/]{XML Schema Datatypes}
209 as specified in @a[http://relaxng.org/xsd-20010907.html]{Guidelines for
210 using W3C XML Schema Datatypes with RELAX NG}. The XSD type library
211 is named @code{:|http://www.w3.org/2001/XMLSchema-datatypes|}.
213 The types defined by @a[http://relaxng.org/compatibility-20011203.html]{
214 RELAX NG DTD Compatibility}
215 are available through the data type library named
216 @code{:|http://relaxng.org/ns/compatibility/datatypes/1.0|}.
218 @begin[Example]{section}
219 @begin{pre}
220 * (setf ttt (cxml-types:find-type :|| \"token\"))
221 #<CXML-TYPES:TOKEN-TYPE {1002D16B71@}>
222 * (cxml-types:parse ttt \"a b\")
223 \"a b\"
224 * (cxml-types:parse ttt \"a b\")
225 \"a b\"
226 * (cxml-types:equal-using-type ttt ** *)
228 @end{pre}
229 @end{section}
230 @begin[Type instances]{section}
231 Each type, together with its parameters, is represented by an
232 instance of @code{data-type}. The generic function @fun{find-type},
233 defined for each library, creates type instances. A type's properties
234 are accessible using @fun{type-name}, @fun{type-library}, and
235 @fun{type-context-dependent-p}.
237 @aboutclass{data-type}
238 @aboutclass{rng-type}
239 @aboutclass{xsd-type}
240 @aboutfun{find-type}
241 @aboutfun{type-name}
242 @aboutfun{type-library}
243 @aboutfun{type-context-dependent-p}
244 @end{section}
245 @begin[Using types]{section}
246 Types allow strings to be tested for validity and equality.
247 @fun{validp} checks whether a string can be parsed. If it is valid,
248 @fun{parse} will compute the string's @emph{value}, and return a
249 Lisp object of a type-specific class as a representation of that value.
250 Values returned by @fun{parse} can be compared for equality using
251 @fun{equal-using-type}. Some types also define a partial ordering,
252 which can be queried using @fun{lessp-using-type}.
254 @aboutfun{validp}
255 @aboutfun{parse}
256 @aboutfun{equal-using-type}
257 @aboutfun{lessp-using-type}
258 @end{section}
259 @begin[The validation context]{section}
260 Some types are context dependent, as indicated by
261 @fun{type-context-dependent-p}. Those types need access to state
262 computed by the XML parser implicitly, like namespace bindings or
263 the Base URI.
265 An abstract class @class{validation-context} is defined that
266 users of this API can implement a subclass of
267 to define methods for the generic functions listed below.
269 In addition, two pre-defined validation context implementations are
270 provided, one for use with SAX, the other based on Klacks.
272 @aboutclass{validation-context}
273 @aboutclass{sax-validation-context-mixin}
274 @aboutclass{klacks-validation-context}
275 @aboutfun{context-find-namespace-binding}
276 @aboutfun{context-find-unparsed-entity}
277 @end{section}
278 @begin[Relax NG built-in types]{section}
279 The following primitive types are defined by Relax NG:
281 @aboutclass{string-type}
282 @aboutclass{token-type}
283 @end{section}
284 @begin[DTD compatibility types]{section}
285 The following primitive types are defined by Relax NG DTD
286 Compatibility:
288 @aboutclass{id-type}
289 @aboutclass{idref-type}
290 @aboutclass{idrefs-type}
291 @end{section}
292 @begin[Primitive XSD built-in types]{section}
293 The following primitive types are part of the XSD built-in data type
294 library:
296 @aboutclass{duration-type}
297 @aboutclass{date-time-type}
298 @aboutclass{time-type}
299 @aboutclass{date-type}
300 @aboutclass{year-month-type}
301 @aboutclass{year-type}
302 @aboutclass{month-day-type}
303 @aboutclass{day-type}
304 @aboutclass{month-type}
305 @aboutclass{boolean-type}
306 @aboutclass{base64-binary-type}
307 @aboutclass{hex-binary-type}
308 @aboutclass{float-type}
309 @aboutclass{decimal-type}
310 @aboutclass{double-type}
311 @aboutclass{any-uri-type}
312 @aboutclass{qname-type}
313 @aboutclass{notation-type}
314 @aboutclass{xsd-string-type}
315 @end{section}
316 @begin[Enumerated XSD built-in types]{section}
317 The following types are part of the XSD built-in data type
318 library, and are defined as derived types through enumeration.
319 Relax NG does not implement the enumeration facet, so although these
320 types are described as \"derived\", they are implemented directly.
322 @aboutclass{xsd-idrefs-type}
323 @aboutclass{entities-type}
324 @aboutclass{nmtokens-type}
325 @end{section}
326 @begin[Derived XSD built-in types]{section}
327 The following types are part of the XSD built-in data type
328 library, and are defined as derived types through restriction.
330 @aboutclass{normalized-string-type}
331 @aboutclass{xsd-token-type}
332 @aboutclass{language-type}
333 @aboutclass{name-type}
334 @aboutclass{ncname-type}
335 @aboutclass{xsd-id-type}
336 @aboutclass{xsd-idref-type}
337 @aboutclass{entity-type}
338 @aboutclass{nmtoken-type}
339 @aboutclass{integer-type}
340 @aboutclass{non-positive-integer-type}
341 @aboutclass{negative-integer-type}
342 @aboutclass{long-type}
343 @aboutclass{int-type}
344 @aboutclass{short-type}
345 @aboutclass{byte-type}
346 @aboutclass{non-negative-integer-type}
347 @aboutclass{unsigned-long-type}
348 @aboutclass{unsigned-int-type}
349 @aboutclass{unsigned-short-type}
350 @aboutclass{unsigned-byte-type}
351 @aboutclass{positive-integer-type}
352 @end{section}"))