1 ;;; rng-pttrn.el --- RELAX NG patterns
3 ;; Copyright (C) 2003, 2007-2013 Free Software Foundation, Inc.
6 ;; Keywords: XML, RelaxNG
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; (ref <pattern> <local-name>)
27 ;; | (choice <pattern> <pattern> ...)
28 ;; | (group <pattern> <pattern> ...)
29 ;; | (interleave <pattern> <pattern> ...)
30 ;; | (zero-or-more <pattern>)
31 ;; | (one-or-more <pattern>)
32 ;; | (optional <pattern>)
33 ;; | (mixed <pattern>)
34 ;; | (value <datatype> <string> <context>)
35 ;; | (data <datatype> <params>)
36 ;; | (data-except <datatype> <params> <pattern>)
38 ;; | (element <name-class> <pattern>)
39 ;; | (attribute <name-class> <pattern>)
45 ;; ((<param-name> . <param-value> ) ...)
46 ;; param-name ::= <symbol>
47 ;; param-value ::= <string>
52 ;; | (any-name-except <name-class>)
54 ;; | (ns-name-except <ns> <name-class>)
55 ;; | (choice <name-class> <name-class> ...)
57 ;; name ::= (<ns> . <local-name>)
58 ;; ns ::= nil | <symbol>
59 ;; local-name ::= <string>
60 ;; datatype ::= (<datatype-uri> . <datatype-local-name>)
61 ;; datatype-uri ::= nil | <symbol>
62 ;; datatype-local-name ::= <symbol>
66 (defvar rng-schema-change-hook nil
67 "Hook to be run after `rng-current-schema' changes.")
69 (defvar rng-current-schema nil
70 "Pattern to be used as schema for the current buffer.")
71 (make-variable-buffer-local 'rng-current-schema
)
73 (defun rng-make-ref (name)
76 (defun rng-ref-set (ref pattern
)
77 (setcar (cdr ref
) pattern
))
79 (defun rng-ref-get (ref) (cadr ref
))
81 (defun rng-make-choice (patterns)
82 (cons 'choice patterns
))
84 (defun rng-make-group (patterns)
85 (cons 'group patterns
))
87 (defun rng-make-interleave (patterns)
88 (cons 'interleave patterns
))
90 (defun rng-make-zero-or-more (pattern)
91 (list 'zero-or-more pattern
))
93 (defun rng-make-one-or-more (pattern)
94 (list 'one-or-more pattern
))
96 (defun rng-make-optional (pattern)
97 (list 'optional pattern
))
99 (defun rng-make-mixed (pattern)
100 (list 'mixed pattern
))
102 (defun rng-make-value (datatype str context
)
103 (list 'value datatype str context
))
105 (defun rng-make-data (name params
)
106 (list 'data name params
))
108 (defun rng-make-data-except (name params pattern
)
109 (list 'data-except name params pattern
))
111 (defun rng-make-list (pattern)
112 (list 'list pattern
))
114 (defun rng-make-element (name-class pattern
)
115 (list 'element name-class pattern
))
117 (defun rng-make-attribute (name-class pattern
)
118 (list 'attribute name-class pattern
))
120 (defun rng-make-text ()
123 (defun rng-make-empty ()
126 (defun rng-make-not-allowed ()
129 (defun rng-make-any-name-name-class ()
132 (defun rng-make-any-name-except-name-class (name-class)
133 (list 'any-name-except name-class
))
135 (defun rng-make-ns-name-name-class (ns)
138 (defun rng-make-ns-name-except-name-class (ns name-class
)
139 (list 'ns-name-except ns name-class
))
141 (defun rng-make-name-name-class (name)
144 (defun rng-make-choice-name-class (name-classes)
145 (cons 'choice name-classes
))
147 (defconst rng-any-content
148 (let* ((ref (rng-make-ref "any-content"))
149 (pattern (rng-make-zero-or-more
153 (rng-make-attribute (rng-make-any-name-name-class)
155 (rng-make-element (rng-make-any-name-name-class)
157 (rng-ref-set ref pattern
)
159 "A pattern that matches the attributes and content of any element.")
161 (defconst rng-any-element
162 (let* ((ref (rng-make-ref "any-element"))
165 (rng-make-any-name-name-class)
166 (rng-make-zero-or-more
170 (rng-make-attribute (rng-make-any-name-name-class)
173 (rng-ref-set ref pattern
)
175 "A pattern that matches any element.")
179 (defun rng-make-name (ns local-name
)
180 (cons ns local-name
))
184 (defun rng-make-datatype (uri local-name
)
185 (cons uri
(intern local-name
)))
189 ;;; rng-pttrn.el ends here