Initial Commit
[packages] / xemacs-packages / jde / lisp / jde-sregex.el
1 ;;; sregex.el --- symbolic regular expressions
2
3 ;; Copyright (C) 1997, 1998, 2000, 2004 Free Software Foundation, Inc.
4
5 ;; Author: Bob Glickstein <bobg+sregex@zanshin.com>
6 ;; Maintainer: Bob Glickstein <bobg+sregex@zanshin.com>
7 ;; Keywords: extensions
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; This version of sregex is provided with the JDEE to support
29 ;; users of XEmacs, which does not include sregex in its 
30 ;; distribution.
31
32 ;; This package allows you to write regular expressions using a
33 ;; totally new, Lisp-like syntax.
34
35 ;; A "symbolic regular expression" (sregex for short) is a Lisp form
36 ;; that, when evaluated, produces the string form of the specified
37 ;; regular expression.  Here's a simple example:
38
39 ;;   (sregexq (or "Bob" "Robert"))  =>  "Bob\\|Robert"
40
41 ;; As you can see, an sregex is specified by placing one or more
42 ;; special clauses in a call to `sregexq'.  The clause in this case is
43 ;; the `or' of two strings (not to be confused with the Lisp function
44 ;; `or').  The list of allowable clauses appears below.
45
46 ;; With sregex, it is never necessary to "escape" magic characters
47 ;; that are meant to be taken literally; that happens automatically.
48 ;; For example:
49
50 ;;   (sregexq "M*A*S*H")  =>  "M\\*A\\*S\\*H"
51
52 ;; It is also unnecessary to "group" parts of the expression together
53 ;; to overcome operator precedence; that also happens automatically.
54 ;; For example:
55
56 ;;   (sregexq (opt (or "Bob" "Robert")))  =>  "\\(?:Bob\\|Robert\\)?"
57
58 ;; It *is* possible to group parts of the expression in order to refer
59 ;; to them with numbered backreferences:
60
61 ;;   (sregexq (group (or "Go" "Run"))
62 ;;            ", Spot, "
63 ;;            (backref 1))             =>  "\\(Go\\|Run\\), Spot, \\1"
64
65 ;; `sregexq' is a macro.  Each time it is used, it constructs a simple
66 ;; Lisp expression that then invokes a moderately complex engine to
67 ;; interpret the sregex and render the string form.  Because of this,
68 ;; I don't recommend sprinkling calls to `sregexq' throughout your
69 ;; code, the way one normally does with string regexes (which are
70 ;; cheap to evaluate).  Instead, it's wiser to precompute the regexes
71 ;; you need wherever possible instead of repeatedly constructing the
72 ;; same ones over and over.  Example:
73
74 ;;    (let ((field-regex (sregexq (opt "resent-")
75 ;;                                (or "to" "cc" "bcc"))))
76 ;;      ...
77 ;;      (while ...
78 ;;        ...
79 ;;        (re-search-forward field-regex ...)
80 ;;        ...))
81
82 ;; The arguments to `sregexq' are automatically quoted, but the
83 ;; flipside of this is that it is not straightforward to include
84 ;; computed (i.e., non-constant) values in `sregexq' expressions.  So
85 ;; `sregex' is a function that is like `sregexq' but which does not
86 ;; automatically quote its values.  Literal sregex clauses must be
87 ;; explicitly quoted like so:
88
89 ;;   (sregex '(or "Bob" "Robert"))  =>  "Bob\\|Robert"
90
91 ;; but computed clauses can be included easily, allowing for the reuse
92 ;; of common clauses:
93
94 ;;  (let ((dotstar '(0+ any))
95 ;;        (whitespace '(1+ (syntax ?-)))
96 ;;        (digits '(1+ (char (?0 . ?9)))))
97 ;;    (sregex 'bol dotstar ":" whitespace digits))  =>  "^.*:\\s-+[0-9]+"
98
99 ;; To use this package in a Lisp program, simply (require 'sregex).
100
101 ;; Here are the clauses allowed in an `sregex' or `sregexq'
102 ;; expression:
103
104 ;; - a string
105 ;;   This stands for the literal string.  If it contains
106 ;;   metacharacters, they will be escaped in the resulting regex
107 ;;   (using `regexp-quote').
108
109 ;; - the symbol `any'
110 ;;   This stands for ".", a regex matching any character except
111 ;;   newline.
112
113 ;; - the symbol `bol'
114 ;;   Stands for "^", matching the empty string at the beginning of a line
115
116 ;; - the symbol `eol'
117 ;;   Stands for "$", matching the empty string at the end of a line
118
119 ;; - (group CLAUSE ...)
120 ;;   Groups the given CLAUSEs using "\\(" and "\\)".
121
122 ;; - (sequence CLAUSE ...)
123
124 ;;   Groups the given CLAUSEs; may or may not use "\\(?:" and "\\)".
125 ;;   Clauses grouped by `sequence' do not count for purposes of
126 ;;   numbering backreferences.  Use `sequence' in situations like
127 ;;   this:
128
129 ;;     (sregexq (or "dog" "cat"
130 ;;                  (sequence (opt "sea ") "monkey")))
131 ;;                                  =>  "dog\\|cat\\|\\(?:sea \\)?monkey"
132
133 ;;   where a single `or' alternate needs to contain multiple
134 ;;   subclauses.
135
136 ;; - (backref N)
137 ;;   Matches the same string previously matched by the Nth "group" in
138 ;;   the same sregex.  N is a positive integer.
139
140 ;; - (or CLAUSE ...)
141 ;;   Matches any one of the CLAUSEs by separating them with "\\|".
142
143 ;; - (0+ CLAUSE ...)
144 ;;   Concatenates the given CLAUSEs and matches zero or more
145 ;;   occurrences by appending "*".
146
147 ;; - (1+ CLAUSE ...)
148 ;;   Concatenates the given CLAUSEs and matches one or more
149 ;;   occurrences by appending "+".
150
151 ;; - (opt CLAUSE ...)
152 ;;   Concatenates the given CLAUSEs and matches zero or one occurrence
153 ;;   by appending "?".
154
155 ;; - (repeat MIN MAX CLAUSE ...)
156 ;;   Concatenates the given CLAUSEs and constructs a regex matching at
157 ;;   least MIN occurrences and at most MAX occurrences.  MIN must be a
158 ;;   non-negative integer.  MAX must be a non-negative integer greater
159 ;;   than or equal to MIN; or MAX can be nil to mean "infinity."
160
161 ;; - (char CHAR-CLAUSE ...)
162 ;;   Creates a "character class" matching one character from the given
163 ;;   set.  See below for how to construct a CHAR-CLAUSE.
164
165 ;; - (not-char CHAR-CLAUSE ...)
166 ;;   Creates a "character class" matching any one character not in the
167 ;;   given set.  See below for how to construct a CHAR-CLAUSE.
168
169 ;; - the symbol `bot'
170 ;;   Stands for "\\`", matching the empty string at the beginning of
171 ;;   text (beginning of a string or of a buffer).
172
173 ;; - the symbol `eot'
174 ;;   Stands for "\\'", matching the empty string at the end of text.
175
176 ;; - the symbol `point'
177 ;;   Stands for "\\=", matching the empty string at point.
178
179 ;; - the symbol `word-boundary'
180 ;;   Stands for "\\b", matching the empty string at the beginning or
181 ;;   end of a word.
182
183 ;; - the symbol `not-word-boundary'
184 ;;   Stands for "\\B", matching the empty string not at the beginning
185 ;;   or end of a word.
186
187 ;; - the symbol `bow'
188 ;;   Stands for "\\<", matching the empty string at the beginning of a
189 ;;   word.
190
191 ;; - the symbol `eow'
192 ;;   Stands for "\\>", matching the empty string at the end of a word.
193
194 ;; - the symbol `wordchar'
195 ;;   Stands for the regex "\\w", matching a word-constituent character
196 ;;   (as determined by the current syntax table)
197
198 ;; - the symbol `not-wordchar'
199 ;;   Stands for the regex "\\W", matching a non-word-constituent
200 ;;   character.
201
202 ;; - (syntax CODE)
203 ;;   Stands for the regex "\\sCODE", where CODE is a syntax table code
204 ;;   (a single character).  Matches any character with the requested
205 ;;   syntax.
206
207 ;; - (not-syntax CODE)
208 ;;   Stands for the regex "\\SCODE", where CODE is a syntax table code
209 ;;   (a single character).  Matches any character without the
210 ;;   requested syntax.
211
212 ;; - (regex REGEX)
213 ;;   This is a "trapdoor" for including ordinary regular expression
214 ;;   strings in the result.  Some regular expressions are clearer when
215 ;;   written the old way: "[a-z]" vs. (sregexq (char (?a . ?z))), for
216 ;;   instance.  However, see the note under "Bugs," below.
217
218 ;; Each CHAR-CLAUSE that is passed to (char ...) and (not-char ...)
219 ;; has one of the following forms:
220
221 ;; - a character
222 ;;   Adds that character to the set.
223
224 ;; - a string
225 ;;   Adds all the characters in the string to the set.
226
227 ;; - A pair (MIN . MAX)
228 ;;   Where MIN and MAX are characters, adds the range of characters
229 ;;   from MIN through MAX to the set.
230
231 ;;; To do:
232
233 ;; An earlier version of this package could optionally translate the
234 ;; symbolic regex into other languages' syntaxes, e.g. Perl.  For
235 ;; instance, with Perl syntax selected, (sregexq (or "ab" "cd")) would
236 ;; yield "ab|cd" instead of "ab\\|cd".  It might be useful to restore
237 ;; such a facility.
238
239 ;; - handle multibyte chars in sregex--char-aux
240 ;; - add support for character classes ([:blank:], ...)
241 ;; - add support for non-greedy operators *? and +?
242 ;; - bug: (sregexq (opt (opt ?a))) returns "a??" which is a non-greedy "a?"
243
244 ;;; Bugs:
245
246 ;;; Code:
247
248 (eval-when-compile (require 'cl))
249
250 ;; XEmacs does not hava make-bool-vector.
251 (unless (fboundp 'make-bool-vector)
252   (defalias 'make-bool-vector 'make-vector))
253
254
255 ;; Compatibility code for when we didn't have shy-groups
256 (defvar sregex--current-sregex nil)
257 (defun sregex-info () nil)
258 (defmacro sregex-save-match-data (&rest forms) (cons 'save-match-data forms))
259 (defun sregex-replace-match (r &optional f l str subexp x)
260   (replace-match r f l str subexp))
261 (defun sregex-match-string (c &optional i x) (match-string c i))
262 (defun sregex-match-string-no-properties (count &optional in-string sregex)
263   (match-string-no-properties count in-string))
264 (defun sregex-match-beginning (count &optional sregex) (match-beginning count))
265 (defun sregex-match-end (count &optional sregex) (match-end count))
266 (defun sregex-match-data (&optional sregex) (match-data))
267 (defun sregex-backref-num (n &optional sregex) n)
268
269
270 (defun sregex (&rest exps)
271   "Symbolic regular expression interpreter.
272 This is exactly like `sregexq' (q.v.) except that it evaluates all its
273 arguments, so literal sregex clauses must be quoted.  For example:
274
275   (sregex '(or \"Bob\" \"Robert\"))  =>  \"Bob\\\\|Robert\"
276
277 An argument-evaluating sregex interpreter lets you reuse sregex
278 subexpressions:
279
280   (let ((dotstar '(0+ any))
281         (whitespace '(1+ (syntax ?-)))
282         (digits '(1+ (char (?0 . ?9)))))
283     (sregex 'bol dotstar \":\" whitespace digits))  =>  \"^.*:\\\\s-+[0-9]+\""
284   (sregex--sequence exps nil))
285
286 (defmacro sregexq (&rest exps)
287   "Symbolic regular expression interpreter.
288 This macro allows you to specify a regular expression (regexp) in
289 symbolic form, and converts it into the string form required by Emacs's
290 regex functions such as `re-search-forward' and `looking-at'.  Here is
291 a simple example:
292
293   (sregexq (or \"Bob\" \"Robert\"))  =>  \"Bob\\\\|Robert\"
294
295 As you can see, an sregex is specified by placing one or more special
296 clauses in a call to `sregexq'.  The clause in this case is the `or'
297 of two strings (not to be confused with the Lisp function `or').  The
298 list of allowable clauses appears below.
299
300 With `sregex', it is never necessary to \"escape\" magic characters
301 that are meant to be taken literally; that happens automatically.
302 For example:
303
304   (sregexq \"M*A*S*H\")  =>  \"M\\\\*A\\\\*S\\\\*H\"
305
306 It is also unnecessary to \"group\" parts of the expression together
307 to overcome operator precedence; that also happens automatically.
308 For example:
309
310   (sregexq (opt (or \"Bob\" \"Robert\")))  =>  \"\\\\(Bob\\\\|Robert\\\\)?\"
311
312 It *is* possible to group parts of the expression in order to refer
313 to them with numbered backreferences:
314
315   (sregexq (group (or \"Go\" \"Run\"))
316            \", Spot, \"
317            (backref 1))             =>  \"\\\\(Go\\\\|Run\\\\), Spot, \\\\1\"
318
319 If `sregexq' needs to introduce its own grouping parentheses, it will
320 automatically renumber your backreferences:
321
322   (sregexq (opt \"resent-\")
323            (group (or \"to\" \"cc\" \"bcc\"))
324            \": \"
325            (backref 1))  =>  \"\\\\(resent-\\\\)?\\\\(to\\\\|cc\\\\|bcc\\\\): \\\\2\"
326
327 `sregexq' is a macro.  Each time it is used, it constructs a simple
328 Lisp expression that then invokes a moderately complex engine to
329 interpret the sregex and render the string form.  Because of this, I
330 don't recommend sprinkling calls to `sregexq' throughout your code,
331 the way one normally does with string regexes (which are cheap to
332 evaluate).  Instead, it's wiser to precompute the regexes you need
333 wherever possible instead of repeatedly constructing the same ones
334 over and over.  Example:
335
336    (let ((field-regex (sregexq (opt \"resent-\")
337                                (or \"to\" \"cc\" \"bcc\"))))
338      ...
339      (while ...
340        ...
341        (re-search-forward field-regex ...)
342        ...))
343
344 The arguments to `sregexq' are automatically quoted, but the
345 flipside of this is that it is not straightforward to include
346 computed (i.e., non-constant) values in `sregexq' expressions.  So
347 `sregex' is a function that is like `sregexq' but which does not
348 automatically quote its values.  Literal sregex clauses must be
349 explicitly quoted like so:
350
351   (sregex '(or \"Bob\" \"Robert\"))  =>  \"Bob\\\\|Robert\"
352
353 but computed clauses can be included easily, allowing for the reuse
354 of common clauses:
355
356   (let ((dotstar '(0+ any))
357         (whitespace '(1+ (syntax ?-)))
358         (digits '(1+ (char (?0 . ?9)))))
359     (sregex 'bol dotstar \":\" whitespace digits))  =>  \"^.*:\\\\s-+[0-9]+\"
360
361 Here are the clauses allowed in an `sregex' or `sregexq' expression:
362
363 - a string
364   This stands for the literal string.  If it contains
365   metacharacters, they will be escaped in the resulting regex
366   (using `regexp-quote').
367
368 - the symbol `any'
369   This stands for \".\", a regex matching any character except
370   newline.
371
372 - the symbol `bol'
373   Stands for \"^\", matching the empty string at the beginning of a line
374
375 - the symbol `eol'
376   Stands for \"$\", matching the empty string at the end of a line
377
378 - (group CLAUSE ...)
379   Groups the given CLAUSEs using \"\\\\(\" and \"\\\\)\".
380
381 - (sequence CLAUSE ...)
382
383   Groups the given CLAUSEs; may or may not use \"\\\\(\" and \"\\\\)\".
384   Clauses grouped by `sequence' do not count for purposes of
385   numbering backreferences.  Use `sequence' in situations like
386   this:
387
388     (sregexq (or \"dog\" \"cat\"
389                  (sequence (opt \"sea \") \"monkey\")))
390                                  =>  \"dog\\\\|cat\\\\|\\\\(?:sea \\\\)?monkey\"
391
392   where a single `or' alternate needs to contain multiple
393   subclauses.
394
395 - (backref N)
396   Matches the same string previously matched by the Nth \"group\" in
397   the same sregex.  N is a positive integer.
398
399 - (or CLAUSE ...)
400   Matches any one of the CLAUSEs by separating them with \"\\\\|\".
401
402 - (0+ CLAUSE ...)
403   Concatenates the given CLAUSEs and matches zero or more
404   occurrences by appending \"*\".
405
406 - (1+ CLAUSE ...)
407   Concatenates the given CLAUSEs and matches one or more
408   occurrences by appending \"+\".
409
410 - (opt CLAUSE ...)
411   Concatenates the given CLAUSEs and matches zero or one occurrence
412   by appending \"?\".
413
414 - (repeat MIN MAX CLAUSE ...)
415   Concatenates the given CLAUSEs and constructs a regex matching at
416   least MIN occurrences and at most MAX occurrences.  MIN must be a
417   non-negative integer.  MAX must be a non-negative integer greater
418   than or equal to MIN; or MAX can be nil to mean \"infinity.\"
419
420 - (char CHAR-CLAUSE ...)
421   Creates a \"character class\" matching one character from the given
422   set.  See below for how to construct a CHAR-CLAUSE.
423
424 - (not-char CHAR-CLAUSE ...)
425   Creates a \"character class\" matching any one character not in the
426   given set.  See below for how to construct a CHAR-CLAUSE.
427
428 - the symbol `bot'
429   Stands for \"\\\\`\", matching the empty string at the beginning of
430   text (beginning of a string or of a buffer).
431
432 - the symbol `eot'
433   Stands for \"\\\\'\", matching the empty string at the end of text.
434
435 - the symbol `point'
436   Stands for \"\\\\=\", matching the empty string at point.
437
438 - the symbol `word-boundary'
439   Stands for \"\\\\b\", matching the empty string at the beginning or
440   end of a word.
441
442 - the symbol `not-word-boundary'
443   Stands for \"\\\\B\", matching the empty string not at the beginning
444   or end of a word.
445
446 - the symbol `bow'
447   Stands for \"\\\\\\=<\", matching the empty string at the beginning of a
448   word.
449
450 - the symbol `eow'
451   Stands for \"\\\\\\=>\", matching the empty string at the end of a word.
452
453 - the symbol `wordchar'
454   Stands for the regex \"\\\\w\", matching a word-constituent character
455   (as determined by the current syntax table)
456
457 - the symbol `not-wordchar'
458   Stands for the regex \"\\\\W\", matching a non-word-constituent
459   character.
460
461 - (syntax CODE)
462   Stands for the regex \"\\\\sCODE\", where CODE is a syntax table code
463   (a single character).  Matches any character with the requested
464   syntax.
465
466 - (not-syntax CODE)
467   Stands for the regex \"\\\\SCODE\", where CODE is a syntax table code
468   (a single character).  Matches any character without the
469   requested syntax.
470
471 - (regex REGEX)
472   This is a \"trapdoor\" for including ordinary regular expression
473   strings in the result.  Some regular expressions are clearer when
474   written the old way: \"[a-z]\" vs. (sregexq (char (?a . ?z))), for
475   instance.
476
477 Each CHAR-CLAUSE that is passed to (char ...) and (not-char ...)
478 has one of the following forms:
479
480 - a character
481   Adds that character to the set.
482
483 - a string
484   Adds all the characters in the string to the set.
485
486 - A pair (MIN . MAX)
487   Where MIN and MAX are characters, adds the range of characters
488   from MIN through MAX to the set."
489   `(apply 'sregex ',exps))
490
491 (defun sregex--engine (exp combine)
492   (cond
493    ((stringp exp)
494     (if (and combine
495              (eq combine 'suffix)
496              (/= (length exp) 1))
497         (concat "\\(?:" (regexp-quote exp) "\\)")
498       (regexp-quote exp)))
499    ((symbolp exp)
500     (ecase exp
501       (any ".")
502       (bol "^")
503       (eol "$")
504       (wordchar "\\w")
505       (not-wordchar "\\W")
506       (bot "\\`")
507       (eot "\\'")
508       (point "\\=")
509       (word-boundary "\\b")
510       (not-word-boundary "\\B")
511       (bow "\\<")
512       (eow "\\>")))
513    ((consp exp)
514     (funcall (intern (concat "sregex--"
515                              (symbol-name (car exp))))
516              (cdr exp)
517              combine))
518    (t (error "Invalid expression: %s" exp))))
519
520 (defun sregex--sequence (exps combine)
521   (if (= (length exps) 1) (sregex--engine (car exps) combine)
522     (let ((re (mapconcat
523                (lambda (e) (sregex--engine e 'concat))
524                exps "")))
525       (if (eq combine 'suffix)
526           (concat "\\(?:" re "\\)")
527         re))))
528
529 (defun sregex--or (exps combine)
530   (if (= (length exps) 1) (sregex--engine (car exps) combine)
531     (let ((re (mapconcat
532                (lambda (e) (sregex--engine e 'or))
533                exps "\\|")))
534       (if (not (eq combine 'or))
535           (concat "\\(?:" re "\\)")
536         re))))
537
538 (defun sregex--group (exps combine) (concat "\\(" (sregex--sequence exps nil) "\\)"))
539
540 (defun sregex--backref (exps combine) (concat "\\" (int-to-string (car exps))))
541 (defun sregex--opt (exps combine) (concat (sregex--sequence exps 'suffix) "?"))
542 (defun sregex--0+ (exps combine) (concat (sregex--sequence exps 'suffix) "*"))
543 (defun sregex--1+ (exps combine) (concat (sregex--sequence exps 'suffix) "+"))
544
545 (defun sregex--char (exps combine) (sregex--char-aux nil exps))
546 (defun sregex--not-char (exps combine) (sregex--char-aux t exps))
547
548 (defun sregex--syntax (exps combine) (format "\\s%c" (car exps)))
549 (defun sregex--not-syntax (exps combine) (format "\\S%c" (car exps)))
550
551 (defun sregex--regex (exps combine)
552   (if combine (concat "\\(?:" (car exps) "\\)") (car exps)))
553
554 (defun sregex--repeat (exps combine)
555   (let* ((min (or (pop exps) 0))
556          (minstr (number-to-string min))
557          (max (pop exps)))
558     (concat (sregex--sequence exps 'suffix)
559             (concat "\\{" minstr ","
560                     (when max (number-to-string max)) "\\}"))))
561
562 (defun sregex--char-range (start end)
563   (let ((startc (char-to-string start))
564         (endc (char-to-string end)))
565     (cond
566      ((> end (+ start 2)) (concat startc "-" endc))
567      ((> end (+ start 1)) (concat startc (char-to-string (1+ start)) endc))
568      ((> end start) (concat startc endc))
569      (t startc))))
570
571 (defun sregex--char-aux (complement args)
572   ;; regex-opt does the same, we should join effort.
573   (let ((chars (make-bool-vector 256 nil))) ; Yeah, right!
574     (dolist (arg args)
575       (cond ((integerp arg) (aset chars arg t))
576             ((stringp arg) (mapcar (lambda (c) (aset chars c t)) arg))
577             ((consp arg)
578              (let ((start (car arg))
579                    (end (cdr arg)))
580                (when (> start end)
581                  (let ((tmp start)) (setq start end) (setq end tmp)))
582                ;; now start <= end
583                (let ((i start))
584                  (while (<= i end)
585                    (aset chars i t)
586                    (setq i (1+ i))))))))
587     ;; now chars is a map of the characters in the class
588     (let ((caret (aref chars ?^))
589           (dash (aref chars ?-))
590           (class (if (aref chars ?\]) "]" "")))
591       (aset chars ?^ nil)
592       (aset chars ?- nil)
593       (aset chars ?\] nil)
594
595       (let (start end)
596         (dotimes (i 256)
597           (if (aref chars i)
598               (progn
599                 (unless start (setq start i))
600                 (setq end i)
601                 (aset chars i nil))
602             (when start
603               (setq class (concat class (sregex--char-range start end)))
604               (setq start nil))))
605         (if start
606             (setq class (concat class (sregex--char-range start end)))))
607
608       (if (> (length class) 0)
609           (setq class (concat class (if caret "^") (if dash "-")))
610         (setq class (concat class (if dash "-") (if caret "^"))))
611       (if (and (not complement) (= (length class) 1))
612           (regexp-quote class)
613         (concat "[" (if complement "^") class "]")))))
614
615 (provide 'sregex)
616
617 ;;; sregex.el ends here