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