;;; rng-match.el --- matching of RELAX NG patterns against XML events
-;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2003, 2007-2012 Free Software Foundation, Inc.
;; Author: James Clark
;; Keywords: XML, RelaxNG
;; This file is part of GNU Emacs.
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
(defvar rng-being-compiled nil
"Contains a list of ref patterns currently being compiled.
-Used to detect illegal recursive references.")
+Used to detect invalid recursive references.")
(defvar rng-ipattern-table nil)
(defun rng-ipattern-slot-accessor-name (slot-name)
(intern (concat "rng-ipattern-get-"
(symbol-name slot-name))))
-
+
(defun rng-ipattern-slot-setter-name (slot-name)
(intern (concat "rng-ipattern-set-"
(symbol-name slot-name)))))
"Associate KEY with VALUE in memo-map MM and return the new memo-map.
The new memo-map may or may not be a different object from MM.
-Alists are better for small maps. Hash tables are better for large
+Alists are better for small maps. Hash tables are better for large
maps. A memo-map therefore starts off as an alist and switches to a
-hash table for large memo-maps. A memo-map is always a list. An empty
-memo-map is represented by nil. A large memo-map is represented by a
+hash table for large memo-maps. A memo-map is always a list. An empty
+memo-map is represented by nil. A large memo-map is represented by a
list containing just a hash-table. A small memo map is represented by
a list whose cdr is an alist and whose car is the number of entries in
-the alist. The complete memo-map can be passed to assoc without
+the alist. The complete memo-map can be passed to `assoc' without
problems: assoc ignores any members that are not cons cells. There is
therefore minimal overhead in successful lookups on small lists
\(which is the most common case)."
(t (cons (1+ head)
(cons (cons key value)
(cdr mm))))))))
-
+
(defsubst rng-make-ipattern (type index name-class child nullable)
(vector type index name-class child nullable
;; 5 memo-text-typed
after
child
nil)))))
-
+
(defun rng-intern-attribute (name-class ipattern)
(if (eq ipattern rng-not-allowed-ipattern)
rng-not-allowed-ipattern
nil)))))
(defun rng-intern-group (ipatterns)
- "Return a ipattern for the list of group members in IPATTERNS."
+ "Return an ipattern for the list of group members in IPATTERNS."
(or (rng-intern-group-shortcut ipatterns)
(let* ((tem (rng-normalize-group-list ipatterns))
(normalized (cdr tem)))
(car tem))))))))
(defun rng-intern-group-shortcut (ipatterns)
- "Try to shortcut interning a group list. If successful, return the
-interned pattern. Otherwise return nil."
+ "Try to shortcut interning a group list.
+If successful, return the interned pattern. Otherwise return nil."
(while (and ipatterns
(eq (car ipatterns) rng-empty-ipattern))
(setq ipatterns (cdr ipatterns)))
nil
normalized
nullable))))
-
+
(defun rng-intern-choice-shortcut (ipatterns)
- "Try to shortcut interning a choice list. If successful, return the
-interned pattern. Otherwise return nil."
+ "Try to shortcut interning a choice list.
+If successful, return the interned pattern. Otherwise return nil."
(while (and ipatterns
(eq (car ipatterns)
rng-not-allowed-ipattern))
rng-not-allowed-ipattern))
(defun rng-normalize-choice-list (ipatterns)
- "Normalize a list of choices, expanding nested choices, removing
-not-allowed members, sorting by index and removing duplicates. Return
-a pair whose car says whether the list is nullable and whose cdr is
-the normalized list."
+ "Normalize a list of choices.
+Expands nested choices, removes not-allowed members, sorts by index
+and removes duplicates. Return a pair whose car says whether the
+list is nullable and whose cdr is the normalized list."
(let ((sorted t)
(nullable nil)
(head (cons nil ipatterns)))
Each possible name should be returned as a (NAMESPACE . LOCAL-NAME)
pair, where NAMESPACE is a symbol or nil and LOCAL-NAME is a string.
-nil for NAMESPACE matches the absent namespace. ACCUM is a list of
-names which should be appended to the returned list. The returned list
-may contain duplicates."
+NAMESPACE, if nil, matches the absent namespace. ACCUM is a list of
+names which should be appended to the returned list. The returned
+list may contain duplicates."
(if (consp nc)
(cons nc accum)
(when (eq (aref nc 0) 'choice)
(rng-compile pattern)
(setq rng-being-compiled
(cdr rng-being-compiled))))
-
+
(defun rng-compile-one-or-more (pattern)
(rng-intern-one-or-more (rng-compile pattern)))
(rng-compile-error "Value %s is not a valid instance of the datatype %s"
str
name))))
-
+
(defun rng-compile-name-class (nc)
(let ((type (car nc)))
(cond ((eq type 'name) (nth 1 nc))
((eq type 'after)
(rng-ipattern-text-typed-p (rng-ipattern-get-child ipattern)))
(t (and (memq type '(value list data data-except)) t)))))
-
+
(defun rng-start-tag-open-deriv (ipattern nm)
(or (rng-memo-map-get
nm
(rng-ipattern-get-memo-map-start-tag-open-deriv ipattern))
(rng-ipattern-memo-start-tag-open-deriv
ipattern
- nm
+ nm
(rng-compute-start-tag-open-deriv ipattern nm))))
-
+
(defun rng-ipattern-memo-start-tag-open-deriv (ipattern nm deriv)
(or (memq ipattern rng-const-ipatterns)
(rng-ipattern-set-memo-map-start-tag-open-deriv
((eq type 'group)
(rng-transform-group-nullable
`(lambda (p) (rng-start-tag-open-deriv p ',nm))
- 'rng-cons-group-after
+ 'rng-cons-group-after
ipattern))
((eq type 'interleave)
(rng-transform-interleave-single
(rng-ipattern-get-memo-map-start-attribute-deriv ipattern))
(rng-ipattern-memo-start-attribute-deriv
ipattern
- nm
+ nm
(rng-compute-start-attribute-deriv ipattern nm))))
-
+
(defun rng-ipattern-memo-start-attribute-deriv (ipattern nm deriv)
(or (memq ipattern rng-const-ipatterns)
(rng-ipattern-set-memo-map-start-attribute-deriv
((eq type 'group)
(rng-transform-interleave-single
`(lambda (p) (rng-start-attribute-deriv p ',nm))
- 'rng-subst-group-after
+ 'rng-subst-group-after
ipattern))
((eq type 'interleave)
(rng-transform-interleave-single
'rng-ignore-attributes-deriv
ipattern)
ipattern)))))
-
+
(defun rng-text-only-deriv (ipattern)
(or (rng-ipattern-get-memo-text-only-deriv ipattern)
(rng-ipattern-set-memo-text-only-deriv
(setq list1 (cdr list1))
(setq list2 (cdr list2)))
(and (null list1) (null list2)))
-
+
(defun rng-ipattern-after (ipattern)
(let ((type (rng-ipattern-get-type ipattern)))
(defsubst rng-set-match-state (state)
(setq rng-match-state state))
-
+
(defsubst rng-match-state-equal (state)
(eq state rng-match-state))
(defun rng-match-possible-namespace-uris ()
"Return a list of all the namespace URIs used in the current schema.
-The absent URI is not included, so the result is always list of symbols."
+The absent URI is not included, so the result is always a list of symbols."
(rng-map-element-attribute (lambda (pattern accum)
(rng-find-name-class-uris (nth 1 pattern)
accum))
Each possible name is returned as a (NAMESPACE . LOCAL-NAME) pair,
where NAMESPACE is a symbol or nil (meaning the absent namespace) and
-LOCAL-NAME is a string. The returned list may contain duplicates."
+LOCAL-NAME is a string. The returned list may contain duplicates."
(rng-ipattern-possible-start-tags rng-match-state nil))
;; This is no longer used. It might be useful so leave it in for now.
(defun rng-match-possible-value-strings ()
"Return a list of strings that would be valid as content.
-The list may contain duplicates. Typically, the list will not
+The list may contain duplicates. Typically, the list will not
be exhaustive."
(rng-ipattern-possible-values rng-match-state nil))
(def-edebug-spec rng-match-with-schema t)
(provide 'rng-match)
-
-;; arch-tag: c8c50733-edcf-49fb-85e2-0aac8749b7f8
+
;;; rng-match.el ends here