Function: xsdre-translate
xsdre-translate is a byte-compiled function defined in
xsd-regexp.el.gz.
Signature
(xsdre-translate REGEXP)
Documentation
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
regexp, signal an xsdre-invalid-regexp condition.
Source Code
;; Defined in /usr/src/emacs/lisp/nxml/xsd-regexp.el.gz
;;; xsd-regexp.el --- translate W3C XML Schema regexps to Emacs regexps -*- lexical-binding:t -*-
;; Copyright (C) 2003, 2007-2024 Free Software Foundation, Inc.
;; Author: James Clark
;; 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
;; it under the terms of the GNU General Public License as published by
;; 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
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; This handles the regular expressions in the syntax defined by:
;; W3C XML Schema Part 2: Datatypes
;; <https://www.w3.org/TR/xmlschema-2/#regexs>
;;
;; The main entry point is `xsdre-translate'.
;;
;; The features of XSD regexps that make this non-trivial are:
;;
;; - \p{PROP} escape for matching characters that have various
;; Unicode-defined properties
;; - character class subtraction:, e.g. [\p{L}-[abc]] matches
;; any character in the L category other than a, b and c.
;;
;; We compute the set of Unicode characters denoted by each XSD
;; char-class as a list of ranges. The regexp generated for a
;; single escape can be large (several thousand characters).
;;
;; XSD has non-traditional rules about when characters must be
;; and can be quoted with \. These are quite different from
;; the Emacs rules.
;;
;; The semantics of XSD regexps are defined in terms of Unicode.
;; Non-Unicode characters are not allowed in regular expressions and
;; will not match against the generated regular expressions. A
;; 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 translatable to such a character (i.e a character
;; for which `encode-char' will return non-nil).
;;
;; Unfortunately, this means that this package is currently useless
;; for CJK characters, since there's no mule-unicode charset for the
;; CJK ranges of Unicode. We should devise a workaround for this
;; until the fabled Unicode version of Emacs makes an appearance.
;;; Code:
(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
regexp, signal an `xsdre-invalid-regexp' condition."
(xsdre-from-symbolic
(xsdre-to-symbolic regexp)))