]> code.delx.au - gnu-emacs/blobdiff - lisp/nxml/xsd-regexp.el
Update copyright year to 2015
[gnu-emacs] / lisp / nxml / xsd-regexp.el
index 185be58388d7679ce9e08e3296701bb311d7d17d..7b1e6165583da82686cab51df2d228202c9810aa 100644 (file)
@@ -1,16 +1,16 @@
 ;;; xsd-regexp.el --- translate W3C XML Schema regexps to Emacs regexps
 
-;; Copyright (C) 2003, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2003, 2007-2015 Free Software Foundation, Inc.
 
 ;; Author: James Clark
-;; Keywords: XML, regexp
+;; Keywords: wp, hypermedia, languages, XML, regexp
 
 ;; 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
@@ -18,9 +18,7 @@
 ;; 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:
 
@@ -51,7 +49,7 @@
 ;; Unicode character means a character in one of the Mule charsets
 ;; ascii, latin-iso8859-1, mule-unicode-0100-24ff,
 ;; mule-unicode-2500-33ff, mule-unicode-e000-ffff, eight-bit-control
-;; or a character translateable to such a character (i.e a character
+;; or a character translatable to such a character (i.e a character
 ;; for which `encode-char' will return non-nil).
 ;;
 ;; Using unify-8859-on-decoding-mode is probably a good idea here
@@ -66,7 +64,7 @@
 
 (defun xsdre-translate (regexp)
   "Translate a W3C XML Schema Datatypes regexp to an Emacs regexp.
-Returns a string.  REGEXP is a string. If REGEXP is not a valid XSD
+Returns a string.  REGEXP is a string.  If REGEXP is not a valid XSD
 regexp, signal an `xsdre-invalid-regexp' condition."
   (xsdre-from-symbolic
    (xsdre-to-symbolic regexp)))
@@ -119,7 +117,7 @@ A range-list represents a set of integers by a list of ranges in a
 canonical form, in which ranges are in increasing order, and adjacent
 ranges are merged wherever possible."
   (when list
-    (setq list 
+    (setq list
          (sort list 'xsdre-range-less-than))
     (let* ((next (cdr list))
           (tail list)
@@ -140,10 +138,10 @@ ranges are merged wherever possible."
       (setcar tail (xsdre-make-range first last))
       (setcdr tail nil)
       list)))
-    
+
 
 (defun xsdre-range-list-union (range-lists)
-  "Return a range-list the union of a list of range-lists."
+  "Return a range-list, the union of a list of range-lists."
   (xsdre-make-range-list (apply 'append range-lists)))
 
 (defun xsdre-range-list-difference (orig subtract)
@@ -162,7 +160,7 @@ ranges are merged wherever possible."
                    (<= (xsdre-range-first (car subtract)) last))
          (when (< first (xsdre-range-first (car subtract)))
            (setq new
-                 (cons (xsdre-make-range 
+                 (cons (xsdre-make-range
                         first
                         (1- (xsdre-range-first (car subtract))))
                        new)))
@@ -183,7 +181,7 @@ ranges are merged wherever possible."
           (< (xsdre-range-last r1) (xsdre-range-last r2)))))
 
 (defun xsdre-check-range-list (range-list)
-  "Check that range-list is a range-list.
+  "Check that RANGE-LIST is a range-list.
 Signal an error if it is not."
   (let ((last nil))
     (while range-list
@@ -201,7 +199,7 @@ Signal an error if it is not."
        (setq last (xsdre-range-last head)))
       (setq range-list (cdr range-list))))
   t)
-       
+
 ;;; Compiling symbolic regexps to Emacs regexps
 
 (defun xsdre-from-symbolic (re)
@@ -288,14 +286,14 @@ and whose tail is ACCUM."
                    (xsdre-range-first (car ranges))))
                  (t (xsdre-range-list-to-char-alternative ranges)))))
        accum))
-             
+
 (defun xsdre-compile-single-char (ch)
   (if (memq ch '(?. ?* ?+ ?? ?\[ ?\] ?^ ?$ ?\\))
       (string ?\\ ch)
     (string (decode-char 'ucs ch))))
-  
+
 (defun xsdre-char-class-to-range-list (cc)
-  "Return a range-list for a symbolic char-class."
+  "Return a range-list for a symbolic char-class CC."
   (cond ((integerp cc) (list cc))
        ((symbolp cc)
         (or (get cc 'xsdre-ranges)
@@ -419,11 +417,11 @@ consisting of a single char alternative delimited with []."
       (setq chars '(?- ?^ ?\])))
     (setq chars (cons ?\[ chars))
     (apply 'string chars)))
-      
+
 ;;; Parsing
 
 (defvar xsdre-current-regexp nil
-  "List of characters remaining to be parsed. Dynamically bound.")
+  "List of characters remaining to be parsed.  Dynamically bound.")
 
 (defun xsdre-to-symbolic (str)
   "Convert a W3C XML Schema datatypes regexp to a symbolic form.
@@ -468,13 +466,8 @@ whose value is a range-list."
                     (- (length str)
                        (length xsdre-current-regexp))))))))
 
-(put 'xsdre-invalid-regexp
-     'error-conditions
-     '(error xsdre-invalid-regexp))
-
-(put 'xsdre-invalid-regexp
-     'error-message
-     "Invalid W3C XML Schema Datatypes regular expression")
+(define-error 'xsdre-invalid-regexp
+  "Invalid W3C XML Schema Datatypes regular expression")
 
 (defun xsdre-parse-regexp ()
   (let ((branches nil))
@@ -526,7 +519,7 @@ whose value is a range-list."
                             (cons lower upper)))))
                   (t (xsdre-parse-error "Expected , or }")))))
          (t nil))))
-                       
+
 (defun xsdre-parse-bound ()
   (let ((n 0))
     (while (progn
@@ -539,7 +532,7 @@ whose value is a range-list."
             (xsdre-advance)
             (not (memq (car xsdre-current-regexp) '(?} ?,)))))
     n))
-       
+
 
 (defun xsdre-try-parse-atom ()
   (let ((ch (car xsdre-current-regexp)))
@@ -642,7 +635,7 @@ whose value is a range-list."
          (t (if ch
                 (xsdre-parse-error "Missing char after \\")
               (xsdre-parse-error "Bad escape %c" ch))))))
-       
+
 (defun xsdre-parse-prop ()
   (xsdre-expect ?{)
   (let ((name nil))
@@ -678,7 +671,7 @@ whose value is a range-list."
   (if (eq (car xsdre-current-regexp) ch)
       (xsdre-advance)
     (xsdre-parse-error "Expected %c" ch)))
-    
+
 (defun xsdre-advance ()
   (setq xsdre-current-regexp
        (cdr xsdre-current-regexp)))
@@ -688,14 +681,8 @@ whose value is a range-list."
 
 ;; This error condition is used only internally.
 
-(put 'xsdre-parse-error
-     'error-conditions
-     '(error xsdre-parse-error))
+(define-error 'xsdre-parse-error "Internal error in parsing XSD regexp")
 
-(put 'xsdre-parse-error
-     'error-message
-     "Internal error in parsing XSD regexp")
-     
 ;;; Character class data
 
 (put 'dot 'xsdre-char-class '(difference any (union #xA #xD)))
@@ -712,8 +699,7 @@ whose value is a range-list."
   "Use a UnicodeData file to generate code to initialize Unicode categories.
 Code is inserted into the current buffer."
   (interactive "fUnicodeData file: ")
-  (save-excursion
-    (set-buffer (find-file-noselect file))
+  (with-current-buffer (find-file-noselect file)
     (goto-char (point-min))
     (mapc (lambda (x) (put x 'xsdre-ranges nil)) xsdre-gen-categories)
     (while (re-search-forward "^\\([0-9A-Fa-f]*\\);[^;]*;\\([A-Z][a-z]\\);"
@@ -760,7 +746,7 @@ Code is inserted into the current buffer."
               (goto-char start)
               (down-list 2)
               (while (condition-case err
-                         (progn 
+                         (progn
                            (forward-sexp)
                            t)
                        (error nil))
@@ -1109,8 +1095,8 @@ Code is inserted into the current buffer."
 
 (xsdre-def-derived-category 'name-continue '(union name-initial
                                                   name-continue-not-initial))
-                         
-(xsdre-def-primitive-category 
+
+(xsdre-def-primitive-category
  'name-continue-not-initial
  '((#x002d . #x002e)
    (#x0030 . #x0039)
@@ -1394,7 +1380,7 @@ Code is inserted into the current buffer."
                                (976 . 977)
                                (981 . 983)
                                987 989 991 993 995 997 999 1001 1003 1005
-                             
+
                                (1007 . 1011)
                                1013
                                (1072 . 1119)
@@ -1422,7 +1408,7 @@ Code is inserted into the current buffer."
                                7877 7879 7881 7883 7885 7887 7889 7891 7893
                                7895 7897 7899 7901 7903 7905 7907 7909 7911
                                7913 7915 7917 7919 7921 7923 7925 7927 7929
-                             
+
                                (7936 . 7943)
                                (7952 . 7957)
                                (7968 . 7975)
@@ -2120,5 +2106,4 @@ Code is inserted into the current buffer."
 
 (provide 'xsd-regexp)
 
-;; arch-tag: bf990d61-a26c-4fd3-b578-56a5640729da
 ;;; xsd-regexp.el ends here