1 ;;; Copyright (c) 2007 David Lichteblau. All rights reserved.
3 ;;; Redistribution and use in source and binary forms, with or without
4 ;;; modification, are permitted provided that the following conditions
7 ;;; * Redistributions of source code must retain the above copyright
8 ;;; notice, this list of conditions and the following disclaimer.
10 ;;; * Redistributions in binary form must reproduce the above
11 ;;; copyright notice, this list of conditions and the following
12 ;;; disclaimer in the documentation and/or other materials
13 ;;; provided with the distribution.
15 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
16 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19 ;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 ;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21 ;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 ;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 ;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24 ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 (in-package :cxml-rng
)
30 (declaim (optimize (debug 2)))
35 (define-condition rng-error
(simple-error) ())
37 (defun rng-error (source fmt
&rest args
)
38 (let ((s (make-string-output-stream)))
39 (apply #'format s fmt args
)
43 (format s
"~& [ Error at line ~D, column ~D in ~S ]"
44 (klacks:current-line-number source
)
45 (klacks:current-column-number source
)
46 (klacks:current-system-id source
)))
48 (format s
"~& [ Error at line ~D, column ~D in ~S ]"
49 (sax:line-number source
)
50 (sax:column-number source
)
51 (sax:system-id source
))) ))
54 :format-arguments
(list (get-output-stream-string s
)))))
59 (defvar *datatype-library
*)
60 (defvar *namespace-uri
*)
62 (defvar *entity-resolver
*)
63 (defvar *external-href-stack
*)
64 (defvar *include-uri-stack
*)
65 (defvar *include-body-p
* nil
)
70 (defstruct (parsed-grammar
71 (:constructor make-parsed-grammar
(pattern definitions
)))
72 (pattern (missing) :type pattern
)
73 (definitions (missing) :type list
)
74 (interned-start nil
:type
(or null pattern
))
75 (registratur nil
:type
(or null hash-table
)))
77 (defmethod print-object ((object parsed-grammar
) stream
)
78 (print-unreadable-object (object stream
:type t
:identity t
)))
80 (defun invoke-with-klacks-handler (fn source
)
85 (cxml:xml-parse-error
(c)
86 (rng-error source
"Cannot parse schema: ~A" c
)))))
88 (defvar *validate-grammar
* t
)
89 (defparameter *relax-ng-grammar
* nil
)
91 (defun make-validating-source (input)
92 (let ((upstream (cxml:make-source input
)))
93 (if *validate-grammar
*
94 (klacks:make-tapping-source upstream
95 (make-validator *relax-ng-grammar
*))
98 (defun parse-relax-ng (input &key entity-resolver
)
99 (when *validate-grammar
*
100 (unless *relax-ng-grammar
*
101 (setf *relax-ng-grammar
*
102 (let* ((*validate-grammar
* nil
)
103 (d (slot-value (asdf:find-system
:cxml-rng
)
104 'asdf
::relative-pathname
)))
105 (parse-relax-ng (merge-pathnames "rng.rng" d
))))))
106 (klacks:with-open-source
(source (make-validating-source input
))
107 (invoke-with-klacks-handler
109 (klacks:find-event source
:start-element
)
110 (let* ((*datatype-library
* "")
112 (*entity-resolver
* entity-resolver
)
113 (*external-href-stack
* '())
114 (*include-uri-stack
* '())
115 (*grammar
* (make-grammar nil
))
116 (start (p/pattern source
)))
118 (rng-error nil
"empty grammar"))
119 (setf (grammar-start *grammar
*)
120 (make-definition :name
:start
:child start
))
121 (check-pattern-definitions source
*grammar
*)
122 (check-recursion start
0)
123 (multiple-value-bind (new-start defns
)
124 (finalize-definitions start
)
125 (setf start
(fold-not-allowed new-start
))
127 (setf (defn-child defn
) (fold-not-allowed (defn-child defn
))))
128 (setf start
(fold-empty start
))
130 (setf (defn-child defn
) (fold-empty (defn-child defn
)))))
131 (multiple-value-bind (new-start defns
)
132 (finalize-definitions start
)
133 (check-start-restrictions new-start
)
135 (check-restrictions (defn-child defn
)))
136 (make-parsed-grammar new-start defns
))))
140 ;;;; pattern structures
144 (defmethod print-object :around
((object pattern
) stream
)
146 (let ((*print-circle
* t
))
148 (print-unreadable-object (object stream
:type t
:identity t
))))
150 (defstruct (%parent
(:include pattern
) (:conc-name
"PATTERN-"))
153 (defstruct (%named-pattern
(:include %parent
) (:conc-name
"PATTERN-"))
155 (defstruct (element (:include %named-pattern
) (:conc-name
"PATTERN-")))
156 (defstruct (attribute (:include %named-pattern
) (:conc-name
"PATTERN-")))
158 (defstruct (%combination
(:include pattern
) (:conc-name
"PATTERN-"))
161 (:include %combination
)
162 (:constructor make-group
(a b
))))
163 (defstruct (interleave
164 (:include %combination
)
165 (:constructor make-interleave
(a b
))))
167 (:include %combination
)
168 (:constructor make-choice
(a b
))))
170 (:include %combination
)
171 (:constructor make-after
(a b
))))
173 (defstruct (one-or-more
175 (:constructor make-one-or-more
(child))))
176 (defstruct (list-pattern
178 (:constructor make-list-pattern
(child))))
182 (:conc-name
"PATTERN-")
183 (:constructor make-ref
(target)))
187 (defstruct (%leaf
(:include pattern
)))
189 (defstruct (empty (:include %leaf
) (:conc-name
"PATTERN-")))
190 (defstruct (text (:include %leaf
) (:conc-name
"PATTERN-")))
192 (defstruct (%typed-pattern
(:include %leaf
) (:conc-name
"PATTERN-"))
195 (defstruct (value (:include %typed-pattern
) (:conc-name
"PATTERN-"))
200 (defstruct (data (:include %typed-pattern
) (:conc-name
"PATTERN-"))
204 (defstruct (not-allowed (:include %leaf
) (:conc-name
"PATTERN-")))
209 (defstruct (grammar (:constructor make-grammar
(parent)))
212 (definitions (make-hash-table :test
'equal
)))
218 ;; Clark calls this structure "RefPattern"
219 (defstruct (definition (:conc-name
"DEFN-"))
230 (error "missing arg"))
232 (defstruct name-class
)
234 (defstruct (any-name (:include name-class
)
235 (:constructor make-any-name
(except)))
236 (except (missing) :type
(or null name-class
)))
238 (defstruct (name (:include name-class
)
239 (:constructor make-name
(uri lname
)))
240 (uri (missing) :type string
)
241 (lname (missing) :type string
))
243 (defstruct (ns-name (:include name-class
)
244 (:constructor make-ns-name
(uri except
)))
245 (uri (missing) :type string
)
246 (except (missing) :type
(or null name-class
)))
248 (defstruct (name-class-choice (:include name-class
)
249 (:constructor make-name-class-choice
(a b
)))
250 (a (missing) :type name-class
)
251 (b (missing) :type name-class
))
253 (defun simplify-nc-choice (values)
254 (zip #'make-name-class-choice values
))
259 (defvar *rng-namespace
* "http://relaxng.org/ns/structure/1.0")
261 (defun skip-foreign* (source)
263 (case (klacks:peek-next source
)
264 (:start-element
(skip-foreign source
))
265 (:end-element
(return)))))
267 (defun skip-to-native (source)
269 (case (klacks:peek source
)
271 (when (equal (klacks:current-uri source
) *rng-namespace
*)
273 (klacks:serialize-element source nil
))
274 (:end-element
(return)))
275 (klacks:consume source
)))
277 (defun consume-and-skip-to-native (source)
278 (klacks:consume source
)
279 (skip-to-native source
))
281 (defun skip-foreign (source)
282 (when (equal (klacks:current-uri source
) *rng-namespace
*)
284 "invalid schema: ~A not allowed here"
285 (klacks:current-lname source
)))
286 (klacks:serialize-element source nil
))
288 (defun attribute (lname attrs
)
289 (let ((a (sax:find-attribute-ns
"" lname attrs
)))
291 (sax:attribute-value a
)
294 (defparameter *whitespace
*
295 (format nil
"~C~C~C~C"
301 (defun ntc (lname source-or-attrs
)
302 ;; used for (n)ame, (t)ype, and (c)ombine, this also strings whitespace
304 (if (listp source-or-attrs
)
306 (klacks:list-attributes source-or-attrs
)))
307 (a (sax:find-attribute-ns
"" lname attrs
)))
309 (string-trim *whitespace
* (sax:attribute-value a
))
312 (defmacro with-library-and-ns
(attrs &body body
)
313 `(invoke-with-library-and-ns (lambda () ,@body
) ,attrs
))
315 (defun invoke-with-library-and-ns (fn attrs
)
316 (let* ((dl (attribute "datatypeLibrary" attrs
))
317 (ns (attribute "ns" attrs
))
318 (*datatype-library
* (if dl
(escape-uri dl
) *datatype-library
*))
319 (*namespace-uri
* (or ns
*namespace-uri
*))
321 ;; FIXME: Ganz boese gehackt -- gerade so, dass wir die Relax NG
322 ;; Test-Suite bestehen.
324 (not (zerop (length *datatype-library
*)))
325 ;; scheme pruefen, und es muss was folgen
326 (or (not (cl-ppcre:all-matches
327 "^[a-zA-Z][a-zA-Z0-9+.-]*:.+"
329 ;; keine kaputten %te, keine #
330 (cl-ppcre:all-matches
331 "(%$|%.$|%[^0-9A-Fa-f][^0-9A-Fa-f]|#)"
332 *datatype-library
*)))
333 (rng-error nil
"malformed datatypeLibrary: ~A" *datatype-library
*))
336 (defun p/pattern
(source)
337 (let* ((lname (klacks:current-lname source
))
338 (attrs (klacks:list-attributes source
)))
339 (with-library-and-ns attrs
340 (case (find-symbol lname
:keyword
)
341 (:|element|
(p/element source
(ntc "name" attrs
)))
342 (:|attribute|
(p/attribute source
(ntc "name" attrs
)))
343 (:|group|
(p/combination
#'groupify source
))
344 (:|interleave|
(p/combination
#'interleave-ify source
))
345 (:|choice|
(p/combination
#'choice-ify source
))
346 (:|optional|
(p/optional source
))
347 (:|zeroOrMore|
(p/zero-or-more source
))
348 (:|oneOrMore|
(p/one-or-more source
))
349 (:|list|
(p/list source
))
350 (:|mixed|
(p/mixed source
))
351 (:|ref|
(p/ref source
))
352 (:|parentRef|
(p/parent-ref source
))
353 (:|empty|
(p/empty source
))
354 (:|text|
(p/text source
))
355 (:|value|
(p/value source
))
356 (:|data|
(p/data source
))
357 (:|notAllowed|
(p/not-allowed source
))
358 (:|externalRef|
(p/external-ref source
))
359 (:|grammar|
(p/grammar source
))
360 (t (skip-foreign source
))))))
362 (defun p/pattern
+ (source)
363 (let ((children nil
))
365 (case (klacks:peek source
)
367 (let ((p (p/pattern source
))) (when p
(push p children
))))
371 (klacks:consume source
))))
373 (rng-error source
"empty element"))
374 (nreverse children
)))
376 (defun p/pattern?
(source)
379 (skip-to-native source
)
380 (case (klacks:peek source
)
383 (rng-error source
"at most one pattern expected here"))
384 (setf result
(p/pattern source
)))
388 (klacks:consume source
))))
391 (defun p/element
(source name
)
392 (klacks:expecting-element
(source "element")
393 (let ((elt (make-element)))
394 (consume-and-skip-to-native source
)
396 (setf (pattern-name elt
) (destructure-name source name
))
397 (setf (pattern-name elt
) (p/name-class source
)))
398 (skip-to-native source
)
399 (setf (pattern-child elt
) (groupify (p/pattern
+ source
)))
400 (make-ref (make-definition :name
(gensym "ANONYMOUS") :child elt
)))))
402 (defvar *attribute-namespace-p
* nil
)
404 (defun p/attribute
(source name
)
405 (klacks:expecting-element
(source "attribute")
406 (let ((result (make-attribute)))
407 (consume-and-skip-to-native source
)
409 (setf (pattern-name result
)
410 (let ((*namespace-uri
* (or *ns
* ""))
411 (*attribute-namespace-p
* t
))
412 (destructure-name source name
)))
413 (setf (pattern-name result
)
414 (let ((*attribute-namespace-p
* t
))
415 (p/name-class source
))))
416 (skip-to-native source
)
417 (setf (pattern-child result
)
418 (or (p/pattern? source
) (make-text)))
421 (defun p/combination
(zipper source
)
422 (klacks:expecting-element
(source)
423 (consume-and-skip-to-native source
)
424 (funcall zipper
(p/pattern
+ source
))))
426 (defun p/one-or-more
(source)
427 (klacks:expecting-element
(source "oneOrMore")
428 (consume-and-skip-to-native source
)
429 (let ((children (p/pattern
+ source
)))
430 (make-one-or-more (groupify children
)))))
432 (defun p/zero-or-more
(source)
433 (klacks:expecting-element
(source "zeroOrMore")
434 (consume-and-skip-to-native source
)
435 (let ((children (p/pattern
+ source
)))
436 (make-choice (make-one-or-more (groupify children
))
439 (defun p/optional
(source)
440 (klacks:expecting-element
(source "optional")
441 (consume-and-skip-to-native source
)
442 (let ((children (p/pattern
+ source
)))
443 (make-choice (groupify children
) (make-empty)))))
445 (defun p/list
(source)
446 (klacks:expecting-element
(source "list")
447 (consume-and-skip-to-native source
)
448 (let ((children (p/pattern
+ source
)))
449 (make-list-pattern (groupify children
)))))
451 (defun p/mixed
(source)
452 (klacks:expecting-element
(source "mixed")
453 (consume-and-skip-to-native source
)
454 (let ((children (p/pattern
+ source
)))
455 (make-interleave (groupify children
) (make-text)))))
457 (defun p/ref
(source)
458 (klacks:expecting-element
(source "ref")
460 (let* ((name (ntc "name" source
))
462 (or (find-definition name
)
463 (setf (find-definition name
)
464 (make-definition :name name
:child nil
)))))
465 (make-ref pdefinition
))
466 (skip-foreign* source
))))
468 (defun p/parent-ref
(source)
469 (klacks:expecting-element
(source "parentRef")
471 (let* ((name (ntc "name" source
))
472 (grammar (grammar-parent *grammar
*))
474 (or (find-definition name grammar
)
475 (setf (find-definition name grammar
)
476 (make-definition :name name
:child nil
)))))
477 (make-ref pdefinition
))
478 (skip-foreign* source
))))
480 (defun p/empty
(source)
481 (klacks:expecting-element
(source "empty")
482 (skip-foreign* source
)
485 (defun p/text
(source)
486 (klacks:expecting-element
(source "text")
487 (skip-foreign* source
)
490 (defun consume-and-parse-characters (source)
494 (multiple-value-bind (key data
) (klacks:peek-next source
)
497 (setf tmp
(concatenate 'string tmp data
)))
498 (:end-element
(return)))))
501 (defun p/value
(source)
502 (klacks:expecting-element
(source "value")
503 (let* ((type (ntc "type" source
))
504 (string (consume-and-parse-characters source
))
506 (dl *datatype-library
*))
511 (cxml-types:find-type
(and dl
(find-symbol dl
:keyword
)) type
))
512 (vc (cxml-types:make-klacks-validation-context source
)))
514 (rng-error source
"type not found: ~A/~A" type dl
))
515 (make-value :string string
516 :value
(cxml-types:parse data-type string vc
)
520 (defun p/data
(source)
521 (klacks:expecting-element
(source "data")
522 (let* ((type (ntc "type" source
))
526 (multiple-value-bind (key uri lname
)
527 (klacks:peek-next source
)
531 (case (find-symbol lname
:keyword
)
532 (:|param|
(push (p/param source
) params
))
534 (setf except
(p/except-pattern source
))
535 (skip-to-native source
)
537 (t (skip-foreign source
))))
540 (setf params
(nreverse params
))
541 (let* ((dl *datatype-library
*)
542 (data-type (apply #'cxml-types
:find-type
543 (and dl
(find-symbol dl
:keyword
))
547 collect
(find-symbol (param-name p
)
549 collect
(param-string p
)))))
551 (rng-error source
"type not found: ~A/~A" type dl
))
557 (defun p/param
(source)
558 (klacks:expecting-element
(source "param")
559 (let ((name (ntc "name" source
))
560 (string (consume-and-parse-characters source
)))
561 (make-param :name name
:string string
))))
563 (defun p/except-pattern
(source)
564 (klacks:expecting-element
(source "except")
565 (with-library-and-ns (klacks:list-attributes source
)
566 (klacks:consume source
)
567 (choice-ify (p/pattern
+ source
)))))
569 (defun p/not-allowed
(source)
570 (klacks:expecting-element
(source "notAllowed")
571 (consume-and-skip-to-native source
)
574 (defun safe-parse-uri (source str
&optional base
)
575 (when (zerop (length str
))
576 (rng-error source
"missing URI"))
580 (puri:merge-uris str base
)
581 (puri:parse-uri str
))
582 (puri:uri-parse-error
()
583 (rng-error source
"invalid URI: ~A" str
)))))
584 (when (and (eq (puri:uri-scheme uri
) :file
)
585 (puri:uri-fragment uri
))
586 (rng-error source
"Forbidden fragment in URI: ~A" str
))
589 (defun p/external-ref
(source)
590 (klacks:expecting-element
(source "externalRef")
592 (escape-uri (attribute "href" (klacks:list-attributes source
))))
593 (base (klacks:current-xml-base source
))
594 (uri (safe-parse-uri source href base
)))
595 (when (find uri
*include-uri-stack
* :test
#'puri
:uri
=)
596 (rng-error source
"looping include"))
598 (let* ((*include-uri-stack
* (cons uri
*include-uri-stack
*))
600 (cxml::xstream-open-extid
* *entity-resolver
* nil uri
)))
601 (klacks:with-open-source
(source (make-validating-source xstream
))
602 (invoke-with-klacks-handler
604 (klacks:find-event source
:start-element
)
605 (let ((*datatype-library
* ""))
608 (skip-foreign* source
)))))
610 (defun p/grammar
(source &optional grammar
)
611 (klacks:expecting-element
(source "grammar")
612 (consume-and-skip-to-native source
)
613 (let ((*grammar
* (or grammar
(make-grammar *grammar
*)))
615 (process-grammar-content* source
)
616 (unless (or includep
(grammar-start *grammar
*))
617 (rng-error source
"no <start> in grammar"))
619 (check-pattern-definitions source
*grammar
*)
620 (defn-child (grammar-start *grammar
*))))))
622 (defvar *include-start
*)
623 (defvar *include-definitions
*)
625 (defun process-grammar-content* (source &key disallow-include
)
627 (multiple-value-bind (key uri lname
) (klacks:peek source
)
631 (with-library-and-ns (klacks:list-attributes source
)
632 (case (find-symbol lname
:keyword
)
633 (:|start|
(process-start source
))
634 (:|define|
(process-define source
))
635 (:|div|
(process-div source
))
637 (when disallow-include
638 (rng-error source
"nested include not permitted"))
639 (process-include source
))
641 (skip-foreign source
)))))
644 (klacks:consume source
)))
646 (defun process-start (source)
647 (klacks:expecting-element
(source "start")
648 (let* ((combine0 (ntc "combine" source
))
651 (find-symbol (string-upcase combine0
) :keyword
)))
654 (consume-and-skip-to-native source
)
656 (pdefinition (grammar-start *grammar
*)))
657 (skip-foreign* source
)
658 ;; fixme: shared code with process-define
660 (setf pdefinition
(make-definition :name
:start
:child nil
))
661 (setf (grammar-start *grammar
*) pdefinition
))
662 (when *include-body-p
*
663 (setf *include-start
* pdefinition
))
665 ((defn-child pdefinition
)
666 (ecase (defn-redefinition pdefinition
)
667 (:not-being-redefined
669 (defn-combine-method pdefinition
)
671 (defn-combine-method pdefinition
))))
672 (rng-error source
"conflicting combine values for <start>"))
674 (when (defn-head-p pdefinition
)
675 (rng-error source
"multiple definitions for <start>"))
676 (setf (defn-head-p pdefinition
) t
))
677 (unless (defn-combine-method pdefinition
)
678 (setf (defn-combine-method pdefinition
) combine
))
679 (setf (defn-child pdefinition
)
680 (case (defn-combine-method pdefinition
)
682 (make-choice (defn-child pdefinition
) child
))
684 (make-interleave (defn-child pdefinition
) child
)))))
685 (:being-redefined-and-no-original
686 (setf (defn-redefinition pdefinition
)
687 :being-redefined-and-original
))
688 (:being-redefined-and-original
)))
690 (setf (defn-child pdefinition
) child
)
691 (setf (defn-combine-method pdefinition
) combine
)
692 (setf (defn-head-p pdefinition
) (null combine
))
693 (setf (defn-redefinition pdefinition
) :not-being-redefined
))))))
695 (defun zip (constructor children
)
698 (rng-error nil
"empty choice?"))
699 ((null (cdr children
))
702 (destructuring-bind (a b
&rest rest
)
704 (zip constructor
(cons (funcall constructor a b
) rest
))))))
706 (defun choice-ify (children) (zip #'make-choice children
))
707 (defun groupify (children) (zip #'make-group children
))
708 (defun interleave-ify (children) (zip #'make-interleave children
))
710 (defun find-definition (name &optional
(grammar *grammar
*))
711 (gethash name
(grammar-definitions grammar
)))
713 (defun (setf find-definition
) (newval name
&optional
(grammar *grammar
*))
714 (setf (gethash name
(grammar-definitions grammar
)) newval
))
716 (defun process-define (source)
717 (klacks:expecting-element
(source "define")
718 (let* ((name (ntc "name" source
))
719 (combine0 (ntc "combine" source
))
720 (combine (when combine0
721 (find-symbol (string-upcase combine0
) :keyword
)))
724 (consume-and-skip-to-native source
)
725 (p/pattern
+ source
))))
726 (pdefinition (find-definition name
)))
728 (setf pdefinition
(make-definition :name name
:child nil
))
729 (setf (find-definition name
) pdefinition
))
730 (when *include-body-p
*
731 (push pdefinition
*include-definitions
*))
733 ((defn-child pdefinition
)
734 (case (defn-redefinition pdefinition
)
735 (:not-being-redefined
737 (defn-combine-method pdefinition
)
739 (defn-combine-method pdefinition
))))
740 (rng-error source
"conflicting combine values for ~A" name
))
742 (when (defn-head-p pdefinition
)
743 (rng-error source
"multiple definitions for ~A" name
))
744 (setf (defn-head-p pdefinition
) t
))
745 (unless (defn-combine-method pdefinition
)
746 (setf (defn-combine-method pdefinition
) combine
))
747 (setf (defn-child pdefinition
)
748 (case (defn-combine-method pdefinition
)
750 (make-choice (defn-child pdefinition
) child
))
752 (make-interleave (defn-child pdefinition
) child
)))))
753 (:being-redefined-and-no-original
754 (setf (defn-redefinition pdefinition
)
755 :being-redefined-and-original
))
756 (:being-redefined-and-original
)))
758 (setf (defn-child pdefinition
) child
)
759 (setf (defn-combine-method pdefinition
) combine
)
760 (setf (defn-head-p pdefinition
) (null combine
))
761 (setf (defn-redefinition pdefinition
) :not-being-redefined
))))))
763 (defun process-div (source)
764 (klacks:expecting-element
(source "div")
765 (consume-and-skip-to-native source
)
766 (process-grammar-content* source
)))
768 (defun reset-definition-for-include (defn)
769 (setf (defn-combine-method defn
) nil
)
770 (setf (defn-redefinition defn
) :being-redefined-and-no-original
)
771 (setf (defn-head-p defn
) nil
))
773 (defun restore-definition (defn original
)
774 (setf (defn-combine-method defn
) (defn-combine-method original
))
775 (setf (defn-redefinition defn
) (defn-redefinition original
))
776 (setf (defn-head-p defn
) (defn-head-p original
)))
778 (defun process-include (source)
779 (klacks:expecting-element
(source "include")
781 (escape-uri (attribute "href" (klacks:list-attributes source
))))
782 (base (klacks:current-xml-base source
))
783 (uri (safe-parse-uri source href base
))
784 (*include-start
* nil
)
785 (*include-definitions
* '()))
786 (consume-and-skip-to-native source
)
787 (let ((*include-body-p
* t
))
788 (process-grammar-content* source
:disallow-include t
))
790 (when *include-start
*
792 (copy-structure *include-start
*)
793 (reset-definition-for-include *include-start
*))))
796 for defn in
*include-definitions
*
799 (copy-structure defn
)
800 (reset-definition-for-include defn
)))))
801 (when (find uri
*include-uri-stack
* :test
#'puri
:uri
=)
802 (rng-error source
"looping include"))
803 (let* ((*include-uri-stack
* (cons uri
*include-uri-stack
*))
804 (xstream (cxml::xstream-open-extid
* *entity-resolver
* nil uri
)))
805 (klacks:with-open-source
(source (make-validating-source xstream
))
806 (invoke-with-klacks-handler
808 (klacks:find-event source
:start-element
)
809 (let ((*datatype-library
* ""))
810 (p/grammar source
*grammar
*)))
813 (when (eq (defn-redefinition *include-start
*)
814 :being-redefined-and-no-original
)
815 (rng-error source
"start not found in redefinition of grammar"))
816 (restore-definition *include-start
* tmp-start
))
817 (dolist (copy tmp-defns
)
818 (let ((defn (gethash (defn-name copy
)
819 (grammar-definitions *grammar
*))))
820 (when (eq (defn-redefinition defn
)
821 :being-redefined-and-no-original
)
822 (rng-error source
"redefinition not found in grammar"))
823 (restore-definition defn copy
)))
826 (defun check-pattern-definitions (source grammar
)
827 (when (and (grammar-start grammar
)
828 (eq (defn-redefinition (grammar-start grammar
))
829 :being-redefined-and-no-original
))
830 (rng-error source
"start not found in redefinition of grammar"))
831 (loop for defn being each hash-value in
(grammar-definitions grammar
) do
832 (when (eq (defn-redefinition defn
) :being-redefined-and-no-original
)
833 (rng-error source
"redefinition not found in grammar"))
834 (unless (defn-child defn
)
835 (rng-error source
"unresolved reference to ~A" (defn-name defn
)))))
837 (defvar *any-name-allowed-p
* t
)
838 (defvar *ns-name-allowed-p
* t
)
840 (defun destructure-name (source qname
)
841 (multiple-value-bind (uri lname
)
842 (klacks:decode-qname qname source
)
843 (setf uri
(or uri
*namespace-uri
*))
844 (when (and *attribute-namespace-p
*
845 (or (and (equal lname
"xmlns") (equal uri
""))
846 (equal uri
"http://www.w3.org/2000/xmlns")))
847 (rng-error source
"namespace attribute not permitted"))
848 (make-name uri lname
)))
850 (defun p/name-class
(source)
851 (klacks:expecting-element
(source)
852 (with-library-and-ns (klacks:list-attributes source
)
853 (case (find-symbol (klacks:current-lname source
) :keyword
)
855 (let ((qname (string-trim *whitespace
*
856 (consume-and-parse-characters source
))))
857 (destructure-name source qname
)))
859 (unless *any-name-allowed-p
*
860 (rng-error source
"anyname now permitted in except"))
861 (klacks:consume source
)
863 (let ((*any-name-allowed-p
* nil
))
864 (make-any-name (p/except-name-class? source
)))
865 (skip-to-native source
)))
867 (unless *ns-name-allowed-p
*
868 (rng-error source
"nsname now permitted in except"))
869 (let ((uri *namespace-uri
*)
870 (*any-name-allowed-p
* nil
)
871 (*ns-name-allowed-p
* nil
))
872 (when (and *attribute-namespace-p
*
873 (equal uri
"http://www.w3.org/2000/xmlns"))
874 (rng-error source
"namespace attribute not permitted"))
875 (klacks:consume source
)
877 (make-ns-name uri
(p/except-name-class? source
))
878 (skip-to-native source
))))
880 (klacks:consume source
)
881 (simplify-nc-choice (p/name-class
* source
)))
883 (rng-error source
"invalid child in except"))))))
885 (defun p/name-class
* (source)
888 (skip-to-native source
)
889 (case (klacks:peek source
)
890 (:start-element
(push (p/name-class source
) results
))
891 (:end-element
(return)))
892 (klacks:consume source
))
895 (defun p/except-name-class?
(source)
896 (skip-to-native source
)
897 (multiple-value-bind (key uri lname
)
900 (if (and (eq key
:start-element
)
901 (string= (find-symbol lname
:keyword
) "except"))
902 (p/except-name-class source
)
905 (defun p/except-name-class
(source)
906 (klacks:expecting-element
(source "except")
907 (with-library-and-ns (klacks:list-attributes source
)
908 (klacks:consume source
)
909 (let ((x (p/name-class
* source
)))
911 (simplify-nc-choice x
)
914 (defun escape-uri (string)
915 (with-output-to-string (out)
916 (loop for c across
(cxml::rod-to-utf8-string string
) do
917 (let ((code (char-code c
)))
918 ;; http://www.w3.org/TR/xlink/#link-locators
919 (if (or (>= code
127) (<= code
32) (find c
"<>\"{}|\\^`"))
920 (format out
"%~2,'0X" code
)
921 (write-char c out
))))))
926 (defvar *definitions-to-names
*)
927 (defvar *seen-names
*)
929 (defun serialization-name (defn)
930 (or (gethash defn
*definitions-to-names
*)
931 (setf (gethash defn
*definitions-to-names
*)
932 (let ((name (if (gethash (defn-name defn
) *seen-names
*)
935 (hash-table-count *seen-names
*))
937 (setf (gethash name
*seen-names
*) defn
)
940 (defun serialize-grammar (grammar sink
)
941 (cxml:with-xml-output sink
942 (let ((*definitions-to-names
* (make-hash-table))
943 (*seen-names
* (make-hash-table :test
'equal
)))
944 (cxml:with-element
"grammar"
945 (cxml:with-element
"start"
946 (serialize-pattern (parsed-grammar-pattern grammar
)))
947 (loop for defn being each hash-key in
*definitions-to-names
* do
948 (serialize-definition defn
))))))
950 (defun serialize-pattern (pattern)
953 (cxml:with-element
"element"
954 (serialize-name (pattern-name pattern
))
955 (serialize-pattern (pattern-child pattern
))))
957 (cxml:with-element
"attribute"
958 (serialize-name (pattern-name pattern
))
959 (serialize-pattern (pattern-child pattern
))))
964 (interleave "interleave")
966 (serialize-pattern (pattern-a pattern
))
967 (serialize-pattern (pattern-b pattern
))))
969 (cxml:with-element
"oneOrMore"
970 (serialize-pattern (pattern-child pattern
))))
972 (cxml:with-element
"list"
973 (serialize-pattern (pattern-child pattern
))))
975 (cxml:with-element
"ref"
976 (cxml:attribute
"name" (serialization-name (pattern-target pattern
)))))
978 (cxml:with-element
"empty"))
980 (cxml:with-element
"notAllowed"))
982 (cxml:with-element
"text"))
984 (cxml:with-element
"value"
985 (let ((type (pattern-type pattern
)))
986 (cxml:attribute
"datatype-library"
987 (symbol-name (cxml-types:type-library type
)))
988 (cxml:attribute
"type" (cxml-types:type-name type
)))
989 (cxml:attribute
"ns" (pattern-ns pattern
))
990 (cxml:text
(pattern-string pattern
))))
992 (cxml:with-element
"value"
993 (let ((type (pattern-type pattern
)))
994 (cxml:attribute
"datatype-library"
995 (symbol-name (cxml-types:type-library type
)))
996 (cxml:attribute
"type" (cxml-types:type-name type
)))
997 (dolist (param (pattern-params pattern
))
998 (cxml:with-element
"param"
999 (cxml:attribute
"name" (param-name param
))
1000 (cxml:text
(param-string param
))))
1001 (when (pattern-except pattern
)
1002 (cxml:with-element
"except"
1003 (serialize-pattern (pattern-except pattern
))))))))
1005 (defun serialize-definition (defn)
1006 (cxml:with-element
"define"
1007 (cxml:attribute
"name" (serialization-name defn
))
1008 (serialize-pattern (defn-child defn
))))
1010 (defun serialize-name (name)
1013 (cxml:with-element
"name"
1014 (cxml:attribute
"ns" (name-uri name
))
1015 (cxml:text
(name-lname name
))))
1017 (cxml:with-element
"anyName"
1018 (when (any-name-except name
)
1019 (serialize-except-name (any-name-except name
)))))
1021 (cxml:with-element
"anyName"
1022 (cxml:attribute
"ns" (ns-name-uri name
))
1023 (when (ns-name-except name
)
1024 (serialize-except-name (ns-name-except name
)))))
1026 (cxml:with-element
"choice"
1027 (serialize-name (name-class-choice-a name
))
1028 (serialize-name (name-class-choice-b name
))))))
1030 (defun serialize-except-name (spec)
1031 (cxml:with-element
"except"
1032 (serialize-name spec
)))
1038 ;;; Foreign attributes and elements are removed implicitly while parsing.
1041 ;;; All character data is discarded while parsing (which can only be
1042 ;;; whitespace after validation).
1044 ;;; Whitespace in name, type, and combine attributes is stripped while
1045 ;;; parsing. Ditto for <name/>.
1047 ;;; 4.3. datatypeLibrary attribute
1048 ;;; Escaping is done by p/pattern.
1049 ;;; Attribute value defaulting is done using *datatype-library*; only
1050 ;;; p/data and p/value record the computed value.
1052 ;;; 4.4. type attribute of value element
1053 ;;; Done by p/value.
1055 ;;; 4.5. href attribute
1056 ;;; Escaping is done by process-include and p/external-ref.
1058 ;;; FIXME: Mime-type handling should be the job of the entity resolver,
1059 ;;; but that requires xstream hacking.
1061 ;;; 4.6. externalRef element
1062 ;;; Done by p/external-ref.
1064 ;;; 4.7. include element
1065 ;;; Done by process-include.
1067 ;;; 4.8. name attribute of element and attribute elements
1068 ;;; `name' is stored as a slot, not a child. Done by p/element and
1071 ;;; 4.9. ns attribute
1072 ;;; done by p/name-class, p/value, p/element, p/attribute
1075 ;;; done by p/name-class
1077 ;;; 4.11. div element
1078 ;;; Legen wir gar nicht erst an.
1080 ;;; 4.12. 4.13 4.14 4.15
1085 ;;; -- ausser der sache mit den datentypen
1087 ;;; 4.17, 4.18, 4.19
1088 ;;; Ueber die Grammar-und Definition Objekte, wie von James Clark
1091 ;;; Dabei werden keine Umbenennungen vorgenommen, weil Referenzierung
1092 ;;; durch Aufbei der Graphenstruktur zwischen ref und Definition
1093 ;;; erfolgt und Namen dann bereits aufgeloest sind. Wir benennen
1094 ;;; dafuer beim Serialisieren um.
1096 (defmethod check-recursion ((pattern element
) depth
)
1097 (check-recursion (pattern-child pattern
) (1+ depth
)))
1099 (defmethod check-recursion ((pattern ref
) depth
)
1100 (when (eql (pattern-crdepth pattern
) depth
)
1101 (rng-error nil
"infinite recursion in ~A"
1102 (defn-name (pattern-target pattern
))))
1103 (when (null (pattern-crdepth pattern
))
1104 (setf (pattern-crdepth pattern
) depth
)
1105 (check-recursion (defn-child (pattern-target pattern
)) depth
)
1106 (setf (pattern-crdepth pattern
) t
)))
1108 (defmethod check-recursion ((pattern %parent
) depth
)
1109 (check-recursion (pattern-child pattern
) depth
))
1111 (defmethod check-recursion ((pattern %combination
) depth
)
1112 (check-recursion (pattern-a pattern
) depth
)
1113 (check-recursion (pattern-b pattern
) depth
))
1115 (defmethod check-recursion ((pattern %leaf
) depth
)
1116 (declare (ignore depth
)))
1118 (defmethod check-recursion ((pattern data
) depth
)
1119 (when (pattern-except pattern
)
1120 (check-recursion (pattern-except pattern
) depth
)))
1127 (defmethod fold-not-allowed ((pattern element
))
1128 (setf (pattern-child pattern
) (fold-not-allowed (pattern-child pattern
)))
1131 (defmethod fold-not-allowed ((pattern %parent
))
1132 (setf (pattern-child pattern
) (fold-not-allowed (pattern-child pattern
)))
1133 (if (typep (pattern-child pattern
) 'not-allowed
)
1134 (pattern-child pattern
)
1139 (defmethod fold-not-allowed ((pattern %combination
))
1140 (setf (pattern-a pattern
) (fold-not-allowed (pattern-a pattern
)))
1141 (setf (pattern-b pattern
) (fold-not-allowed (pattern-b pattern
)))
1144 (defmethod fold-not-allowed ((pattern group
))
1147 ;; remove if any child is not allowed
1148 ((typep (pattern-a pattern
) 'not-allowed
) (pattern-a pattern
))
1149 ((typep (pattern-b pattern
) 'not-allowed
) (pattern-b pattern
))
1152 (defmethod fold-not-allowed ((pattern interleave
))
1155 ;; remove if any child is not allowed
1156 ((typep (pattern-a pattern
) 'not-allowed
) (pattern-a pattern
))
1157 ((typep (pattern-b pattern
) 'not-allowed
) (pattern-b pattern
))
1160 (defmethod fold-not-allowed ((pattern choice
))
1163 ;; if any child is not allowed, choose the other
1164 ((typep (pattern-a pattern
) 'not-allowed
) (pattern-b pattern
))
1165 ((typep (pattern-b pattern
) 'not-allowed
) (pattern-a pattern
))
1170 (defmethod fold-not-allowed ((pattern %leaf
))
1173 (defmethod fold-not-allowed ((pattern data
))
1174 (when (pattern-except pattern
)
1175 (setf (pattern-except pattern
) (fold-not-allowed (pattern-except pattern
)))
1176 (when (typep (pattern-except pattern
) 'not-allowed
)
1177 (setf (pattern-except pattern
) nil
)))
1182 (defmethod fold-not-allowed ((pattern ref
))
1190 (defmethod fold-empty ((pattern one-or-more
))
1192 (if (typep (pattern-child pattern
) 'empty
)
1193 (pattern-child pattern
)
1196 (defmethod fold-empty ((pattern %parent
))
1197 (setf (pattern-child pattern
) (fold-empty (pattern-child pattern
)))
1202 (defmethod fold-empty ((pattern %combination
))
1203 (setf (pattern-a pattern
) (fold-empty (pattern-a pattern
)))
1204 (setf (pattern-b pattern
) (fold-empty (pattern-b pattern
)))
1207 (defmethod fold-empty ((pattern group
))
1210 ;; if any child is empty, choose the other
1211 ((typep (pattern-a pattern
) 'empty
) (pattern-b pattern
))
1212 ((typep (pattern-b pattern
) 'empty
) (pattern-a pattern
))
1215 (defmethod fold-empty ((pattern interleave
))
1218 ;; if any child is empty, choose the other
1219 ((typep (pattern-a pattern
) 'empty
) (pattern-b pattern
))
1220 ((typep (pattern-b pattern
) 'empty
) (pattern-a pattern
))
1223 (defmethod fold-empty ((pattern choice
))
1225 (if (typep (pattern-b pattern
) 'empty
)
1227 ((typep (pattern-a pattern
) 'empty
)
1228 (pattern-a pattern
))
1230 (rotatef (pattern-a pattern
) (pattern-b pattern
))
1236 (defmethod fold-empty ((pattern %leaf
))
1239 (defmethod fold-empty ((pattern data
))
1240 (when (pattern-except pattern
)
1241 (setf (pattern-except pattern
) (fold-empty (pattern-except pattern
))))
1246 (defmethod fold-empty ((pattern ref
))
1250 ;;;; name class overlap
1252 ;;; fixme: memorize this stuff?
1254 (defparameter !uri
(string (code-char 1)))
1255 (defparameter !lname
"")
1257 (defun classes-overlap-p (nc1 nc2
)
1258 (flet ((both-contain (x)
1259 (and (contains nc1
(car x
) (cdr x
))
1260 (contains nc2
(car x
) (cdr x
)))))
1261 (or (some #'both-contain
(representatives nc1
))
1262 (some #'both-contain
(representatives nc2
)))))
1264 (defmethod representatives ((nc any-name
))
1265 (cons (cons !uri
!lname
)
1266 (if (any-name-except nc
)
1267 (representatives (any-name-except nc
))
1270 (defmethod representatives ((nc ns-name
))
1271 (cons (cons (ns-name-uri nc
) !lname
)
1272 (if (ns-name-except nc
)
1273 (representatives (ns-name-except nc
))
1276 (defmethod representatives ((nc name
))
1277 (list (cons (name-uri nc
) (name-lname nc
))))
1279 (defmethod representatives ((nc name-class-choice
))
1280 (nconc (representatives (name-class-choice-a nc
))
1281 (representatives (name-class-choice-b nc
))))
1286 (defun finalize-definitions (pattern)
1287 (let ((defns (make-hash-table)))
1288 (labels ((recurse (p)
1291 (let ((target (pattern-target p
)))
1292 (unless (gethash target defns
)
1293 (setf (gethash target defns
) t
)
1294 (setf (defn-child target
) (recurse (defn-child target
))))
1295 (if (typep (defn-child target
) 'element
)
1297 (copy-pattern-tree (defn-child target
)))))
1301 (when (pattern-except p
)
1302 (setf (pattern-except p
) (recurse (pattern-except p
)))))
1304 (setf (pattern-child p
) (recurse (pattern-child p
))))
1306 (setf (pattern-a p
) (recurse (pattern-a p
)))
1307 (setf (pattern-b p
) (recurse (pattern-b p
))))
1313 for defn being each hash-key in defns
1316 (defun copy-pattern-tree (pattern)
1317 (labels ((recurse (p)
1318 (let ((q (copy-structure p
)))
1321 (when (pattern-except p
)
1322 (setf (pattern-except q
) (recurse (pattern-except p
)))))
1324 (setf (pattern-child q
) (recurse (pattern-child p
))))
1326 (setf (pattern-a q
) (recurse (pattern-a p
)))
1327 (setf (pattern-b q
) (recurse (pattern-b p
))))
1332 (defparameter *in-attribute-p
* nil
)
1333 (defparameter *in-one-or-more-p
* nil
)
1334 (defparameter *in-one-or-more
//group-or-interleave-p
* nil
)
1335 (defparameter *in-list-p
* nil
)
1336 (defparameter *in-data-except-p
* nil
)
1337 (defparameter *in-start-p
* nil
)
1339 (defun check-start-restrictions (pattern)
1340 (let ((*in-start-p
* t
))
1341 (check-restrictions pattern
)))
1343 (defun content-type-max (a b
)
1352 (defun groupable-max (a b
)
1353 (if (or (eq a
:empty
)
1355 (and (eq a
:complex
)
1357 (content-type-max a b
)
1360 (defun assert-name-class-finite (nc)
1362 ((or any-name ns-name
)
1363 (rng-error nil
"infinite attribute name class outside of one-or-more"))
1366 (assert-name-class-finite (name-class-choice-a nc
))
1367 (assert-name-class-finite (name-class-choice-b nc
)))))
1369 (defmethod check-restrictions ((pattern attribute
))
1370 (when *in-attribute-p
*
1371 (rng-error nil
"nested attribute not allowed"))
1372 (when *in-one-or-more
//group-or-interleave-p
*
1373 (rng-error nil
"attribute not allowed in oneOrMore//group, oneOrMore//interleave"))
1375 (rng-error nil
"attribute in list not allowed"))
1376 (when *in-data-except-p
*
1377 (rng-error nil
"attribute in data/except not allowed"))
1379 (rng-error nil
"attribute in start not allowed"))
1380 (let ((*in-attribute-p
* t
))
1381 (unless *in-one-or-more-p
*
1382 (assert-name-class-finite (pattern-name pattern
)))
1383 (values (if (check-restrictions (pattern-child pattern
))
1386 (list (pattern-name pattern
))
1389 (defmethod check-restrictions ((pattern ref
))
1390 (when *in-attribute-p
*
1391 (rng-error nil
"ref in attribute not allowed"))
1393 (rng-error nil
"ref in list not allowed"))
1394 (when *in-data-except-p
*
1395 (rng-error nil
"ref in data/except not allowed"))
1398 (list (pattern-name (defn-child (pattern-target pattern
))))
1401 (defmethod check-restrictions ((pattern one-or-more
))
1402 (when *in-data-except-p
*
1403 (rng-error nil
"oneOrMore in data/except not allowed"))
1405 (rng-error nil
"one-or-more in start not allowed"))
1406 (let* ((*in-one-or-more-p
* t
))
1407 (multiple-value-bind (x a e textp
)
1408 (check-restrictions (pattern-child pattern
))
1409 (values (groupable-max x x
) a e textp
))))
1411 (defmethod check-restrictions ((pattern group
))
1412 (when *in-data-except-p
*
1413 (rng-error nil
"group in data/except not allowed"))
1415 (rng-error nil
"group in start not allowed"))
1416 (let ((*in-one-or-more
//group-or-interleave-p
*
1417 *in-one-or-more-p
*))
1418 (multiple-value-bind (x a e tp
) (check-restrictions (pattern-a pattern
))
1419 (multiple-value-bind (y b f tq
) (check-restrictions (pattern-b pattern
))
1422 (when (classes-overlap-p nc1 nc2
)
1423 (rng-error nil
"attribute name overlap in group: ~A ~A"
1425 (values (groupable-max x y
)
1430 (defmethod check-restrictions ((pattern interleave
))
1432 (rng-error nil
"interleave in list not allowed"))
1433 (when *in-data-except-p
*
1434 (rng-error nil
"interleave in data/except not allowed"))
1436 (rng-error nil
"interleave in start not allowed"))
1437 (let ((*in-one-or-more
//group-or-interleave-p
*
1438 *in-one-or-more-p
*))
1439 (multiple-value-bind (x a e tp
) (check-restrictions (pattern-a pattern
))
1440 (multiple-value-bind (y b f tq
) (check-restrictions (pattern-b pattern
))
1443 (when (classes-overlap-p nc1 nc2
)
1444 (rng-error nil
"attribute name overlap in interleave: ~A ~A"
1448 (when (classes-overlap-p nc1 nc2
)
1449 (rng-error nil
"element name overlap in interleave: ~A ~A"
1452 (rng-error nil
"multiple text permitted by interleave"))
1453 (values (groupable-max x y
)
1458 (defmethod check-restrictions ((pattern choice
))
1459 (multiple-value-bind (x a e tp
) (check-restrictions (pattern-a pattern
))
1460 (multiple-value-bind (y b f tq
) (check-restrictions (pattern-b pattern
))
1461 (values (content-type-max x y
)
1466 (defmethod check-restrictions ((pattern list-pattern
))
1468 (rng-error nil
"nested list not allowed"))
1469 (when *in-data-except-p
*
1470 (rng-error nil
"list in data/except not allowed"))
1471 (let ((*in-list-p
* t
))
1472 (check-restrictions (pattern-child pattern
)))
1474 (rng-error nil
"list in start not allowed"))
1477 (defmethod check-restrictions ((pattern text
))
1479 (rng-error nil
"text in list not allowed"))
1480 (when *in-data-except-p
*
1481 (rng-error nil
"text in data/except not allowed"))
1483 (rng-error nil
"text in start not allowed"))
1484 (values :complex nil nil t
))
1486 (defmethod check-restrictions ((pattern data
))
1488 (rng-error nil
"data in start not allowed"))
1489 (when (pattern-except pattern
)
1490 (let ((*in-data-except-p
* t
))
1491 (check-restrictions (pattern-except pattern
))))
1494 (defmethod check-restrictions ((pattern value
))
1496 (rng-error nil
"value in start not allowed"))
1499 (defmethod check-restrictions ((pattern empty
))
1500 (when *in-data-except-p
*
1501 (rng-error nil
"empty in data/except not allowed"))
1503 (rng-error nil
"empty in start not allowed"))
1506 (defmethod check-restrictions ((pattern element
))
1507 (unless (check-restrictions (pattern-child pattern
))
1508 (rng-error nil
"restrictions on string sequences violated")))
1510 (defmethod check-restrictions ((pattern not-allowed
))