annotate lisp/emacs-lisp/rx.el @ 112295:2108d829c749

* xfns.c (x_real_positions): Fix signedness of local var 'ign'. XGetGeometry wants unsigned int *, not int *, for its last 4 args, so change the type of 'ign' to unsigned int from int.
author Paul Eggert <eggert@cs.ucla.edu>
date Sun, 16 Jan 2011 23:45:28 -0800
parents a28fc1581b94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; rx.el --- sexp notation for regular expressions
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
68648
067115a6e738 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64751
diff changeset
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005,
112122
a28fc1581b94 * lisp/emacs-lisp/rx.el (rx-repeat): Replace CL function.
Glenn Morris <rgm@gnu.org>
parents: 112038
diff changeset
4 ;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Author: Gerd Moellmann <gerd@gnu.org>
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Maintainer: FSF
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Keywords: strings, regexps, extensions
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
14 ;; the Free Software Foundation, either version 3 of the License, or
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
15 ;; (at your option) any later version.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
94655
90a2847062be Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;; This is another implementation of sexp-form regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; It was unfortunately written without being aware of the Sregex
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; package coming with Emacs, but as things stand, Rx completely
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; covers all regexp features, which Sregex doesn't, doesn't suffer
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; from the bugs mentioned in the commentary section of Sregex, and
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; uses a nicer syntax (IMHO, of course :-).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
34 ;; This significantly extended version of the original, is almost
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
35 ;; compatible with Sregex. The only incompatibility I (fx) know of is
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
36 ;; that the `repeat' form can't have multiple regexp args.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
37
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
38 ;; Now alternative forms are provided for a degree of compatibility
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
39 ;; with Shivers' attempted definitive SRE notation
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
40 ;; <URL:http://www.ai.mit.edu/~/shivers/sre.txt>. SRE forms not
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
41 ;; catered for include: dsm, uncase, w/case, w/nocase, ,@<exp>,
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
42 ;; ,<exp>, (word ...), word+, posix-string, and character class forms.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
43 ;; Some forms are inconsistent with SRE, either for historical reasons
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
44 ;; or because of the implementation -- simple translation into Emacs
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
45 ;; regexp strings. These include: any, word. Also, case-sensitivity
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
46 ;; and greediness are controlled by variables external to the regexp,
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
47 ;; and you need to feed the forms to the `posix-' functions to get
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
48 ;; SRE's POSIX semantics. There are probably more difficulties.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
49
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; Rx translates a sexp notation for regular expressions into the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; usual string notation. The translation can be done at compile-time
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; by using the `rx' macro. It can be done at run-time by calling
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; function `rx-to-string'. See the documentation of `rx' for a
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; complete description of the sexp notation.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;; Some examples of string regexps and their sexp counterparts:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; "^[a-z]*"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; (rx (and line-start (0+ (in "a-z"))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; "\n[^ \t]"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; (rx (and "\n" (not blank))), or
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; (rx (and "\n" (not (any " \t"))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; "\\*\\*\\* EOOH \\*\\*\\*\n"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; (rx "*** EOOH ***\n")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;; "\\<\\(catch\\|finally\\)\\>[^_]"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; (rx (and word-start (submatch (or "catch" "finally")) word-end
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; (not (any ?_))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;; "[ \t\n]*:\\([^:]+\\|$\\)"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; (rx (and (zero-or-more (in " \t\n")) ":"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; (submatch (or line-end (one-or-more (not (any ?:)))))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;; "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; (rx (and line-start
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; "content-transfer-encoding:"
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
79 ;; (+ (? ?\n)) blank
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;; "quoted-printable"
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
81 ;; (+ (? ?\n)) blank))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;; (concat "^\\(?:" something-else "\\)")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; (rx (and line-start (eval something-else))), statically or
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;; (rx-to-string '(and line-start ,something-else)), dynamically.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;; (regexp-opt '(STRING1 STRING2 ...))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; (rx (or STRING1 STRING2 ...)), or in other words, `or' automatically
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; calls `regexp-opt' as needed.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;; "^;;\\s-*\n\\|^\n"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; (rx (or (and line-start ";;" (0+ space) ?\n)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;; (and line-start ?\n)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; "\\$[I]d: [^ ]+ \\([^ ]+\\) "
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
96 ;; (rx (and "$Id: "
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
97 ;; (1+ (not (in " ")))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;; " "
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 ;; (submatch (1+ (not (in " "))))
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
100 ;; " "))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 ;; "\\\\\\\\\\[\\w+"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 ;; (rx (and ?\\ ?\\ ?\[ (1+ word)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 ;; etc.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 ;;; History:
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
108 ;;
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 ;;; Code:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (defconst rx-constituents
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 '((and . (rx-and 1 nil))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
114 (seq . and) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
115 (: . and) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
116 (sequence . and) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (or . (rx-or 1 nil))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
118 (| . or) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (not-newline . ".")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
120 (nonl . not-newline) ; SRE
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
121 (anything . (rx-anything 0 nil))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
122 (any . (rx-any 1 nil rx-check-any)) ; inconsistent with SRE
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
123 (any . ".") ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (in . any)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
125 (char . any) ; sregex
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
126 (not-char . (rx-not-char 1 nil rx-check-any)) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (not . (rx-not 1 1 rx-check-not))
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
128 (repeat . (rx-repeat 2 nil))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
129 (= . (rx-= 2 nil)) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
130 (>= . (rx->= 2 nil)) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
131 (** . (rx-** 2 nil)) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
132 (submatch . (rx-submatch 1 nil)) ; SRE
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
133 (group . submatch) ; sregex
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
134 (zero-or-more . (rx-kleene 1 nil))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
135 (one-or-more . (rx-kleene 1 nil))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
136 (zero-or-one . (rx-kleene 1 nil))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
137 (\? . zero-or-one) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (\?? . zero-or-one)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
139 (* . zero-or-more) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (*? . zero-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (0+ . zero-or-more)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
142 (+ . one-or-more) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (+? . one-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (1+ . one-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (optional . zero-or-one)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
146 (opt . zero-or-one) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (minimal-match . (rx-greedy 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (maximal-match . (rx-greedy 1 1))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
149 (backref . (rx-backref 1 1 rx-check-backref))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (line-start . "^")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
151 (bol . line-start) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (line-end . "$")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
153 (eol . line-end) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (string-start . "\\`")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
155 (bos . string-start) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
156 (bot . string-start) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (string-end . "\\'")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
158 (eos . string-end) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
159 (eot . string-end) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (buffer-start . "\\`")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (buffer-end . "\\'")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (point . "\\=")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (word-start . "\\<")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
164 (bow . word-start) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (word-end . "\\>")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
166 (eow . word-end) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (word-boundary . "\\b")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
168 (not-word-boundary . "\\B") ; sregex
60930
a6ae354aa8ef (rx-constituents): Add symbol-start and symbol-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55103
diff changeset
169 (symbol-start . "\\_<")
a6ae354aa8ef (rx-constituents): Add symbol-start and symbol-end.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55103
diff changeset
170 (symbol-end . "\\_>")
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (syntax . (rx-syntax 1 1))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
172 (not-syntax . (rx-not-syntax 1 1)) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (category . (rx-category 1 1 rx-check-category))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (eval . (rx-eval 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (regexp . (rx-regexp 1 1 stringp))
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
176 (regex . regexp) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (digit . "[[:digit:]]")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
178 (numeric . digit) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
179 (num . digit) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
180 (control . "[[:cntrl:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
181 (cntrl . control) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
182 (hex-digit . "[[:xdigit:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
183 (hex . hex-digit) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
184 (xdigit . hex-digit) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
185 (blank . "[[:blank:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
186 (graphic . "[[:graph:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
187 (graph . graphic) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
188 (printing . "[[:print:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
189 (print . printing) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
190 (alphanumeric . "[[:alnum:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
191 (alnum . alphanumeric) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (letter . "[[:alpha:]]")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
193 (alphabetic . letter) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
194 (alpha . letter) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
195 (ascii . "[[:ascii:]]") ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (nonascii . "[[:nonascii:]]")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
197 (lower . "[[:lower:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
198 (lower-case . lower) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
199 (punctuation . "[[:punct:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
200 (punct . punctuation) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
201 (space . "[[:space:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
202 (whitespace . space) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
203 (white . space) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
204 (upper . "[[:upper:]]") ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
205 (upper-case . upper) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
206 (word . "[[:word:]]") ; inconsistent with SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
207 (wordchar . word) ; sregex
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
208 (not-wordchar . "\\W"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 "Alist of sexp form regexp constituents.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 Each element of the alist has the form (SYMBOL . DEFN).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 SYMBOL is a valid constituent of sexp regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 If DEFN is a string, SYMBOL is translated into DEFN.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 If DEFN is a symbol, use the definition of DEFN, recursively.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 Otherwise, DEFN must be a list (FUNCTION MIN-ARGS MAX-ARGS PREDICATE).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 FUNCTION is used to produce code for SYMBOL. MIN-ARGS and MAX-ARGS
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 are the minimum and maximum number of arguments the function-form
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 sexp constituent SYMBOL may have in sexp regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 MAX-ARGS nil means no limit. PREDICATE, if specified, means that
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 all arguments must satisfy PREDICATE.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (defconst rx-syntax
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 '((whitespace . ?-)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (punctuation . ?.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (word . ?w)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (symbol . ?_)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (open-parenthesis . ?\()
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (close-parenthesis . ?\))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (expression-prefix . ?\')
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (string-quote . ?\")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (paired-delimiter . ?$)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (escape . ?\\)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (character-quote . ?/)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (comment-start . ?<)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
235 (comment-end . ?>)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
236 (string-delimiter . ?|)
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
237 (comment-delimiter . ?!))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 "Alist mapping Rx syntax symbols to syntax characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 symbol in `(syntax SYMBOL)', and CHAR is the syntax character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 corresponding to SYMBOL, as it would be used with \\s or \\S in
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 regular expressions.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 (defconst rx-categories
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 '((consonant . ?0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (base-vowel . ?1)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (upper-diacritical-mark . ?2)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (lower-diacritical-mark . ?3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 (tone-mark . ?4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (symbol . ?5)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (digit . ?6)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (vowel-modifying-diacritical-mark . ?7)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (vowel-sign . ?8)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (semivowel-lower . ?9)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (not-at-end-of-line . ?<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (not-at-beginning-of-line . ?>)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (alpha-numeric-two-byte . ?A)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (chinse-two-byte . ?C)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (greek-two-byte . ?G)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (japanese-hiragana-two-byte . ?H)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (indian-two-byte . ?I)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (japanese-katakana-two-byte . ?K)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (korean-hangul-two-byte . ?N)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (cyrillic-two-byte . ?Y)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
266 (combining-diacritic . ?^)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (ascii . ?a)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (arabic . ?b)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (chinese . ?c)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (ethiopic . ?e)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (greek . ?g)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (korean . ?h)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (indian . ?i)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (japanese . ?j)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (japanese-katakana . ?k)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (latin . ?l)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (lao . ?o)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (tibetan . ?q)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 (japanese-roman . ?r)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (thai . ?t)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (vietnamese . ?v)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (hebrew . ?w)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (cyrillic . ?y)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (can-break . ?|))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 "Alist mapping symbols to category characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 symbol in `(category SYMBOL)', and CHAR is the category character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 corresponding to SYMBOL, as it would be used with `\\c' or `\\C' in
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 regular expression strings.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (defvar rx-greedy-flag t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 "Non-nil means produce greedy regular expressions for `zero-or-one',
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 `zero-or-more', and `one-or-more'. Dynamically bound.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
297 (defun rx-info (op head)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 "Return parsing/code generation info for OP.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 If OP is the space character ASCII 32, return info for the symbol `?'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 If OP is the character `?', return info for the symbol `??'.
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
301 See also `rx-constituents'.
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
302 If HEAD is non-nil, then OP is the head of a sexp, otherwise it's
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
303 a standalone symbol."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (cond ((eq op ? ) (setq op '\?))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ((eq op ??) (setq op '\??)))
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
306 (let (old-op)
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
307 (while (and (not (null op)) (symbolp op))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
308 (setq old-op op)
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
309 (setq op (cdr (assq op rx-constituents)))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
310 (when (if head (stringp op) (consp op))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
311 ;; We found something but of the wrong kind. Let's look for an
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
312 ;; alternate definition for the other case.
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
313 (let ((new-op
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
314 (cdr (assq old-op (cdr (memq (assq old-op rx-constituents)
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
315 rx-constituents))))))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
316 (if (and new-op (not (if head (stringp new-op) (consp new-op))))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
317 (setq op new-op))))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 op)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
319
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (defun rx-check (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 "Check FORM according to its car's parsing info."
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
323 (unless (listp form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
324 (error "rx `%s' needs argument(s)" form))
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
325 (let* ((rx (rx-info (car form) 'head))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (nargs (1- (length form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (min-args (nth 1 rx))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (max-args (nth 2 rx))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (type-pred (nth 3 rx)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (when (and (not (null min-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (< nargs min-args))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
332 (error "rx form `%s' requires at least %d args"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (car form) min-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (when (and (not (null max-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (> nargs max-args))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
336 (error "rx form `%s' accepts at most %d args"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (car form) max-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (when (not (null type-pred))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (dolist (sub-form (cdr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (unless (funcall type-pred sub-form)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
341 (error "rx form `%s' requires args satisfying `%s'"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (car form) type-pred))))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
345 (defun rx-group-if (regexp group)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
346 "Put shy groups around REGEXP if seemingly necessary when GROUP
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
347 is non-nil."
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
348 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
349 ;; for some repetition
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
350 ((eq group '*) (if (rx-atomic-p regexp) (setq group nil)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
351 ;; for concatenation
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
352 ((eq group ':)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
353 (if (rx-atomic-p
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
354 (if (string-match
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
355 "\\(?:[?*+]\\??\\|\\\\{[0-9]*,?[0-9]*\\\\}\\)\\'" regexp)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
356 (substring regexp 0 (match-beginning 0))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
357 regexp))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
358 (setq group nil)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
359 ;; for OR
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
360 ((eq group '|) (setq group nil))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
361 ;; do anyway
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
362 ((eq group t))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
363 ((rx-atomic-p regexp t) (setq group nil)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
364 (if group
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
365 (concat "\\(?:" regexp "\\)")
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
366 regexp))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
367
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
368
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
369 (defvar rx-parent)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
370 ;; dynamically bound in some functions.
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
371
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
372
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (defun rx-and (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 FORM is of the form `(and FORM1 ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (rx-check form)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
377 (rx-group-if
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
378 (mapconcat (lambda (x) (rx-form x ':)) (cdr form) nil)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
379 (and (memq rx-parent '(* t)) rx-parent)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (defun rx-or (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 "Parse and produce code from FORM, which is `(or FORM1 ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (rx-check form)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
385 (rx-group-if
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
386 (if (memq nil (mapcar 'stringp (cdr form)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
387 (mapconcat (lambda (x) (rx-form x '|)) (cdr form) "\\|")
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
388 (regexp-opt (cdr form)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
389 (and (memq rx-parent '(: * t)) rx-parent)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
390
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
391
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
392 (defun rx-anything (form)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
393 "Match any character."
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
394 (if (consp form)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
395 (error "rx `anythng' syntax error: %s" form))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
396 (rx-or (list 'or 'not-newline ?\n)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
399 (defun rx-any-delete-from-range (char ranges)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
400 "Delete by side effect character CHAR from RANGES.
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
401 Only both edges of each range is checked."
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
402 (let (m)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
403 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
404 ((memq char ranges) (setq ranges (delq char ranges)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
405 ((setq m (assq char ranges))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
406 (if (eq (1+ char) (cdr m))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
407 (setcar (memq m ranges) (1+ char))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
408 (setcar m (1+ char))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
409 ((setq m (rassq char ranges))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
410 (if (eq (1- char) (car m))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
411 (setcar (memq m ranges) (1- char))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
412 (setcdr m (1- char)))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
413 ranges))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
414
112122
a28fc1581b94 * lisp/emacs-lisp/rx.el (rx-repeat): Replace CL function.
Glenn Morris <rgm@gnu.org>
parents: 112038
diff changeset
415
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
416 (defun rx-any-condense-range (args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
417 "Condense by side effect ARGS as range for Rx `any'."
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
418 (let (str
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
419 l)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
420 ;; set STR list of all strings
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
421 ;; set L list of all ranges
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
422 (mapc (lambda (e) (cond ((stringp e) (push e str))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
423 ((numberp e) (push (cons e e) l))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
424 (t (push e l))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
425 args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
426 ;; condense overlapped ranges in L
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
427 (let ((tail (setq l (sort l #'car-less-than-car)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
428 d)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
429 (while (setq d (cdr tail))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
430 (if (>= (cdar tail) (1- (caar d)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
431 (progn
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
432 (setcdr (car tail) (max (cdar tail) (cdar d)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
433 (setcdr tail (cdr d)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
434 (setq tail d))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
435 ;; Separate small ranges to single number, and delete dups.
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
436 (nconc
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
437 (apply #'nconc
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
438 (mapcar (lambda (e)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
439 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
440 ((= (car e) (cdr e)) (list (car e)))
110231
6d4cb5e730cb * emacs-lisp/rx.el (rx-any): Don't explode ranges that end in - or ].
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109285
diff changeset
441 ((= (1+ (car e)) (cdr e)) (list (car e) (cdr e)))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
442 ((list e))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
443 l))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
444 (delete-dups str))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
445
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
446
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
447 (defun rx-check-any-string (str)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
448 "Check string argument STR for Rx `any'."
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
449 (let ((i 0)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
450 c1 c2 l)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
451 (if (= 0 (length str))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
452 (error "String arg for Rx `any' must not be empty"))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
453 (while (string-match ".-." str i)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
454 ;; string before range: convert it to characters
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
455 (if (< i (match-beginning 0))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
456 (setq l (nconc
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
457 l
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
458 (append (substring str i (match-beginning 0)) nil))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
459 ;; range
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
460 (setq i (match-end 0)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
461 c1 (aref str (match-beginning 0))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
462 c2 (aref str (1- i)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
463 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
464 ((< c1 c2) (setq l (nconc l (list (cons c1 c2)))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
465 ((= c1 c2) (setq l (nconc l (list c1))))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
466 ;; rest?
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
467 (if (< i (length str))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
468 (setq l (nconc l (append (substring str i) nil))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
469 l))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
470
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (defun rx-check-any (arg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 "Check arg ARG for Rx `any'."
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
474 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
475 ((integerp arg) (list arg))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
476 ((symbolp arg)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
477 (let ((translation (condition-case nil
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
478 (rx-form arg)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
479 (error nil))))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
480 (if (or (null translation)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
481 (null (string-match "\\`\\[\\[:[-a-z]+:\\]\\]\\'" translation)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
482 (error "Invalid char class `%s' in Rx `any'" arg))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
483 (list (substring translation 1 -1)))) ; strip outer brackets
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
484 ((and (integerp (car-safe arg)) (integerp (cdr-safe arg)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
485 (list arg))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
486 ((stringp arg) (rx-check-any-string arg))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
487 ((error
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
488 "rx `any' requires string, character, char pair or char class args"))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
489
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (defun rx-any (form)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
492 "Parse and produce code from FORM, which is `(any ARG ...)'.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
493 ARG is optional."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (rx-check form)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
495 (let* ((args (rx-any-condense-range
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
496 (apply
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
497 #'nconc
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
498 (mapcar #'rx-check-any (cdr form)))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
499 m
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
500 s)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
501 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
502 ;; single close bracket
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
503 ;; => "[]...-]" or "[]...--.]"
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
504 ((memq ?\] args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
505 ;; set ] at the beginning
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
506 (setq args (cons ?\] (delq ?\] args)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
507 ;; set - at the end
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
508 (if (or (memq ?- args) (assq ?- args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
509 (setq args (nconc (rx-any-delete-from-range ?- args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
510 (list ?-)))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
511 ;; close bracket starts a range
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
512 ;; => "[]-....-]" or "[]-.--....]"
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
513 ((setq m (assq ?\] args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
514 ;; bring it to the beginning
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
515 (setq args (cons m (delq m args)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
516 (cond ((memq ?- args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
517 ;; to the end
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
518 (setq args (nconc (delq ?- args) (list ?-))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
519 ((setq m (assq ?- args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
520 ;; next to the bracket's range, make the second range
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
521 (setcdr args (cons m (delq m args))))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
522 ;; bracket in the end range
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
523 ;; => "[]...-]"
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
524 ((setq m (rassq ?\] args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
525 ;; set ] at the beginning
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
526 (setq args (cons ?\] (rx-any-delete-from-range ?\] args)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
527 ;; set - at the end
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
528 (if (or (memq ?- args) (assq ?- args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
529 (setq args (nconc (rx-any-delete-from-range ?- args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
530 (list ?-)))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
531 ;; {no close bracket appears}
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
532 ;;
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
533 ;; bring single bar to the beginning
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
534 ((memq ?- args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
535 (setq args (cons ?- (delq ?- args))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
536 ;; bar start a range, bring it to the beginning
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
537 ((setq m (assq ?- args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
538 (setq args (cons m (delq m args))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
539 ;;
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
540 ;; hat at the beginning?
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
541 ((or (eq (car args) ?^) (eq (car-safe (car args)) ?^))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
542 (setq args (if (cdr args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
543 `(,(cadr args) ,(car args) ,@(cddr args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
544 (nconc (rx-any-delete-from-range ?^ args)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
545 (list ?^))))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
546 ;; some 1-char?
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
547 (if (and (null (cdr args)) (numberp (car args))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
548 (or (= 1 (length
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
549 (setq s (regexp-quote (string (car args))))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
550 (and (equal (car args) ?^) ;; unnecessary predicate?
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
551 (null (eq rx-parent '!)))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
552 s
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
553 (concat "["
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
554 (mapconcat
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
555 (lambda (e) (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
556 ((numberp e) (string e))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
557 ((consp e)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
558 (if (and (= (1+ (car e)) (cdr e))
110231
6d4cb5e730cb * emacs-lisp/rx.el (rx-any): Don't explode ranges that end in - or ].
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109285
diff changeset
559 ;; rx-any-condense-range should
6d4cb5e730cb * emacs-lisp/rx.el (rx-any): Don't explode ranges that end in - or ].
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109285
diff changeset
560 ;; prevent this case from happening.
6d4cb5e730cb * emacs-lisp/rx.el (rx-any): Don't explode ranges that end in - or ].
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109285
diff changeset
561 (null (memq (car e) '(?\] ?-)))
6d4cb5e730cb * emacs-lisp/rx.el (rx-any): Don't explode ranges that end in - or ].
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 109285
diff changeset
562 (null (memq (cdr e) '(?\] ?-))))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
563 (string (car e) (cdr e))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
564 (string (car e) ?- (cdr e))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
565 (e)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
566 args
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
567 nil)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
568 "]"))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
571 (defun rx-check-not (arg)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
572 "Check arg ARG for Rx `not'."
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
573 (unless (or (and (symbolp arg)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
574 (string-match "\\`\\[\\[:[-a-z]+:\\]\\]\\'"
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
575 (condition-case nil
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
576 (rx-form arg)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
577 (error ""))))
112122
a28fc1581b94 * lisp/emacs-lisp/rx.el (rx-repeat): Replace CL function.
Glenn Morris <rgm@gnu.org>
parents: 112038
diff changeset
578 (eq arg 'word-boundary)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
579 (and (consp arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
580 (memq (car arg) '(not any in syntax category))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
581 (error "rx `not' syntax error: %s" arg))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
582 t)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (defun rx-not (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 "Parse and produce code from FORM. FORM is `(not ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (rx-check form)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
588 (let ((result (rx-form (cadr form) '!))
53974
818e19ae4c5a (rx-not): Bind case-fold-search to nil.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52971
diff changeset
589 case-fold-search)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (cond ((string-match "\\`\\[^" result)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
591 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
592 ((equal result "[^]") "[^^]")
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
593 ((and (= (length result) 4) (null (eq rx-parent '!)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
594 (regexp-quote (substring result 2 3)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
595 ((concat "[" (substring result 2)))))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
596 ((eq ?\[ (aref result 0))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (concat "[^" (substring result 1)))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
598 ((string-match "\\`\\\\[scbw]" result)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
599 (concat (upcase (substring result 0 2))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
600 (substring result 2)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
601 ((string-match "\\`\\\\[SCBW]" result)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
602 (concat (downcase (substring result 0 2))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
603 (substring result 2)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 (t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 (concat "[^" result "]")))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
608 (defun rx-not-char (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
609 "Parse and produce code from FORM. FORM is `(not-char ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
610 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
611 (rx-not `(not (in ,@(cdr form)))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
612
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
613
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
614 (defun rx-not-syntax (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
615 "Parse and produce code from FORM. FORM is `(not-syntax SYNTAX)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
616 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
617 (rx-not `(not (syntax ,@(cdr form)))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
618
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
619
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
620 (defun rx-trans-forms (form &optional skip)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
621 "If FORM's length is greater than two, transform it to length two.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
622 A form (HEAD REST ...) becomes (HEAD (and REST ...)).
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
623 If SKIP is non-nil, allow that number of items after the head, i.e.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
624 `(= N REST ...)' becomes `(= N (and REST ...))' if SKIP is 1."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
625 (unless skip (setq skip 0))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
626 (let ((tail (nthcdr (1+ skip) form)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
627 (if (= (length tail) 1)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
628 form
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
629 (let ((form (copy-sequence form)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
630 (setcdr (nthcdr skip form) (list (cons 'and tail)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
631 form))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
632
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
633
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
634 (defun rx-= (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
635 "Parse and produce code from FORM `(= N ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
636 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
637 (setq form (rx-trans-forms form 1))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
638 (unless (and (integerp (nth 1 form))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
639 (> (nth 1 form) 0))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
640 (error "rx `=' requires positive integer first arg"))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
641 (format "%s\\{%d\\}" (rx-form (nth 2 form) '*) (nth 1 form)))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
642
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
643
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
644 (defun rx->= (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
645 "Parse and produce code from FORM `(>= N ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
646 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
647 (setq form (rx-trans-forms form 1))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
648 (unless (and (integerp (nth 1 form))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
649 (> (nth 1 form) 0))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
650 (error "rx `>=' requires positive integer first arg"))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
651 (format "%s\\{%d,\\}" (rx-form (nth 2 form) '*) (nth 1 form)))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
652
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
653
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
654 (defun rx-** (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
655 "Parse and produce code from FORM `(** N M ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
656 (rx-check form)
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
657 (rx-form (cons 'repeat (cdr (rx-trans-forms form 2))) '*))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
658
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
659
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 (defun rx-repeat (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 "Parse and produce code from FORM.
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
662 FORM is either `(repeat N FORM1)' or `(repeat N M FORMS...)'."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 (rx-check form)
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
664 (if (> (length form) 4)
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
665 (setq form (rx-trans-forms form 2)))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
666 (if (null (nth 2 form))
112122
a28fc1581b94 * lisp/emacs-lisp/rx.el (rx-repeat): Replace CL function.
Glenn Morris <rgm@gnu.org>
parents: 112038
diff changeset
667 (setq form (cons (nth 0 form) (cons (nth 1 form) (nthcdr 3 form)))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 (cond ((= (length form) 3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669 (unless (and (integerp (nth 1 form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 (> (nth 1 form) 0))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
671 (error "rx `repeat' requires positive integer first arg"))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
672 (format "%s\\{%d\\}" (rx-form (nth 2 form) '*) (nth 1 form)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673 ((or (not (integerp (nth 2 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 (< (nth 2 form) 0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 (not (integerp (nth 1 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676 (< (nth 1 form) 0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 (< (nth 2 form) (nth 1 form)))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
678 (error "rx `repeat' range error"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 (t
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
680 (format "%s\\{%d,%d\\}" (rx-form (nth 3 form) '*)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 (nth 1 form) (nth 2 form)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
683
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
684 (defun rx-submatch (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685 "Parse and produce code from FORM, which is `(submatch ...)'."
100293
bb1d2d686d04 (rx-submatch): Pass : to rx-form (bug#1518).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 98557
diff changeset
686 (concat "\\("
bb1d2d686d04 (rx-submatch): Pass : to rx-form (bug#1518).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 98557
diff changeset
687 (if (= 2 (length form))
bb1d2d686d04 (rx-submatch): Pass : to rx-form (bug#1518).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 98557
diff changeset
688 ;; Only one sub-form.
bb1d2d686d04 (rx-submatch): Pass : to rx-form (bug#1518).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 98557
diff changeset
689 (rx-form (cadr form))
bb1d2d686d04 (rx-submatch): Pass : to rx-form (bug#1518).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 98557
diff changeset
690 ;; Several sub-forms implicitly concatenated.
bb1d2d686d04 (rx-submatch): Pass : to rx-form (bug#1518).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 98557
diff changeset
691 (mapconcat (lambda (re) (rx-form re ':)) (cdr form) nil))
bb1d2d686d04 (rx-submatch): Pass : to rx-form (bug#1518).
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 98557
diff changeset
692 "\\)"))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
693
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
695 (defun rx-backref (form)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
696 "Parse and produce code from FORM, which is `(backref N)'."
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
697 (rx-check form)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
698 (format "\\%d" (nth 1 form)))
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
699
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
700 (defun rx-check-backref (arg)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
701 "Check arg ARG for Rx `backref'."
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
702 (or (and (integerp arg) (>= arg 1) (<= arg 9))
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
703 (error "rx `backref' requires numeric 1<=arg<=9: %s" arg)))
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
704
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 (defun rx-kleene (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
706 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 FORM is `(OP FORM1)', where OP is one of the `zero-or-one',
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
708 `zero-or-more' etc. operators.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
709 If OP is one of `*', `+', `?', produce a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
710 If OP is one of `*?', `+?', `??', produce a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 If OP is anything else, produce a greedy regexp if `rx-greedy-flag'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
712 is non-nil."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
713 (rx-check form)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
714 (setq form (rx-trans-forms form))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
715 (let ((suffix (cond ((memq (car form) '(* + ?\s)) "")
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
716 ((memq (car form) '(*? +? ??)) "?")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
717 (rx-greedy-flag "")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
718 (t "?")))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
719 (op (cond ((memq (car form) '(* *? 0+ zero-or-more)) "*")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
720 ((memq (car form) '(+ +? 1+ one-or-more)) "+")
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
721 (t "?"))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
722 (rx-group-if
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
723 (concat (rx-form (cadr form) '*) op suffix)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
724 (and (memq rx-parent '(t *)) rx-parent))))
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
725
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
726
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
727 (defun rx-atomic-p (r &optional lax)
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
728 "Return non-nil if regexp string R is atomic.
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
729 An atomic regexp R is one such that a suffix operator
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
730 appended to R will apply to all of R. For example, \"a\"
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
731 \"[abc]\" and \"\\(ab\\|ab*c\\)\" are atomic and \"ab\",
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
732 \"[ab]c\", and \"ab\\|ab*c\" are not atomic.
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
733
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
734 This function may return false negatives, but it will not
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
735 return false positives. It is nevertheless useful in
78474
88c9f4e4160e Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78217
diff changeset
736 situations where an efficiency shortcut can be taken only if a
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
737 regexp is atomic. The function can be improved to detect
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
738 more cases of atomic regexps. Presently, this function
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
739 detects the following categories of atomic regexp;
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
740
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
741 a group or shy group: \\(...\\)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
742 a character class: [...]
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
743 a single character: a
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
744
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
745 On the other hand, false negatives will be returned for
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
746 regexps that are atomic but end in operators, such as
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
747 \"a+\". I think these are rare. Probably such cases could
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
748 be detected without much effort. A guarantee of no false
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
749 negatives would require a theoretic specification of the set
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
750 of all atomic regexps."
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
751 (let ((l (length r)))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
752 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
753 ((<= l 1))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
754 ((= l 2) (= (aref r 0) ?\\))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
755 ((= l 3) (string-match "\\`\\(?:\\\\[cCsS_]\\|\\[[^^]\\]\\)" r))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
756 ((null lax)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
757 (cond
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
758 ((string-match "\\`\\[^?\]?\\(?:\\[:[a-z]+:]\\|[^\]]\\)*\\]\\'" r))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
759 ((string-match "\\`\\\\(\\(?:[^\\]\\|\\\\[^\)]\\)*\\\\)\\'" r)))))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
760
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
761
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
762 (defun rx-syntax (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763 "Parse and produce code from FORM, which is `(syntax SYMBOL)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
764 (rx-check form)
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
765 (let* ((sym (cadr form))
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
766 (syntax (cdr (assq sym rx-syntax))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
767 (unless syntax
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
768 ;; Try sregex compatibility.
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
769 (cond
112038
ad2a8fce0d7a * lisp/emacs-lisp/rx.el (rx-syntax): Fix typo.
Andreas Schwab <schwab@linux-m68k.org>
parents: 112017
diff changeset
770 ((characterp sym) (setq syntax sym))
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
771 ((symbolp sym)
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
772 (let ((name (symbol-name sym)))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
773 (if (= 1 (length name))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
774 (setq syntax (aref name 0))))))
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
775 (unless syntax
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
776 (error "Unknown rx syntax `%s'" sym)))
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
777 (format "\\s%c" syntax)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
778
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
779
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
780 (defun rx-check-category (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
781 "Check the argument FORM of a `(category FORM)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
782 (unless (or (integerp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
783 (cdr (assq form rx-categories)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
784 (error "Unknown category `%s'" form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
785 t)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
786
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
787
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
788 (defun rx-category (form)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
789 "Parse and produce code from FORM, which is `(category SYMBOL)'."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
790 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
791 (let ((char (if (integerp (cadr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
792 (cadr form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
793 (cdr (assq (cadr form) rx-categories)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
794 (format "\\c%c" char)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
795
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
796
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
797 (defun rx-eval (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
798 "Parse and produce code from FORM, which is `(eval FORM)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
799 (rx-check form)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
800 (rx-form (eval (cadr form)) rx-parent))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
801
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
802
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
803 (defun rx-greedy (form)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
804 "Parse and produce code from FORM.
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
805 If FORM is '(minimal-match FORM1)', non-greedy versions of `*',
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
806 `+', and `?' operators will be used in FORM1. If FORM is
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
807 '(maximal-match FORM1)', greedy operators will be used."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
808 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
809 (let ((rx-greedy-flag (eq (car form) 'maximal-match)))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
810 (rx-form (cadr form) rx-parent)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
811
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
812
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
813 (defun rx-regexp (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
814 "Parse and produce code from FORM, which is `(regexp STRING)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
815 (rx-check form)
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
816 (rx-group-if (cadr form) rx-parent))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
817
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
818
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
819 (defun rx-form (form &optional rx-parent)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
820 "Parse and produce code for regular expression FORM.
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
821 FORM is a regular expression in sexp form.
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
822 RX-PARENT shows which type of expression calls and controls putting of
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
823 shy groups around the result and some more in other functions."
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
824 (if (stringp form)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
825 (rx-group-if (regexp-quote form)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
826 (if (and (eq rx-parent '*) (< 1 (length form)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
827 rx-parent))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
828 (cond ((integerp form)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
829 (regexp-quote (char-to-string form)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
830 ((symbolp form)
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
831 (let ((info (rx-info form nil)))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
832 (cond ((stringp info)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
833 info)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
834 ((null info)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
835 (error "Unknown rx form `%s'" form))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
836 (t
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
837 (funcall (nth 0 info) form)))))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
838 ((consp form)
112017
db006527425b * lisp/emacs-lisp/rx.el: Make it a superset of sregex.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 110231
diff changeset
839 (let ((info (rx-info (car form) 'head)))
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
840 (unless (consp info)
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
841 (error "Unknown rx form `%s'" (car form)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
842 (funcall (nth 0 info) form)))
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
843 (t
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
844 (error "rx syntax error at `%s'" form)))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
845
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
846
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
847 ;;;###autoload
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
848 (defun rx-to-string (form &optional no-group)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
849 "Parse and produce code for regular expression FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
850 FORM is a regular expression in sexp form.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
851 NO-GROUP non-nil means don't put shy groups around the result."
98557
73eaaf9adee6 (rx-constituents): Change `anything' to call
Chong Yidong <cyd@stupidchicken.com>
parents: 98489
diff changeset
852 (rx-group-if (rx-form form) (null no-group)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
853
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
854
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
855 ;;;###autoload
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
856 (defmacro rx (&rest regexps)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
857 "Translate regular expressions REGEXPS in sexp form to a regexp string.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
858 REGEXPS is a non-empty sequence of forms of the sort listed below.
100727
7ab2f3422f46 (rx): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100293
diff changeset
859
7ab2f3422f46 (rx): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100293
diff changeset
860 Note that `rx' is a Lisp macro; when used in a Lisp program being
7ab2f3422f46 (rx): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100293
diff changeset
861 compiled, the translation is performed by the compiler.
7ab2f3422f46 (rx): Doc fix.
Chong Yidong <cyd@stupidchicken.com>
parents: 100293
diff changeset
862 See `rx-to-string' for how to do such a translation at run-time.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
863
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
864 The following are valid subforms of regular expressions in sexp
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
865 notation.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
866
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
867 STRING
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
868 matches string STRING literally.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
869
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
870 CHAR
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
871 matches character CHAR literally.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
872
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
873 `not-newline', `nonl'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
874 matches any character except a newline.
83899
bdeef0472e21 (rx): Fix typo in docstring.
Michaël Cadilhac <michael.cadilhac@lrde.org>
parents: 82365
diff changeset
875
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
876 `anything'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
877 matches any character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
878
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
879 `(any SET ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
880 `(in SET ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
881 `(char SET ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
882 matches any character in SET .... SET may be a character or string.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
883 Ranges of characters can be specified as `A-Z' in strings.
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
884 Ranges may also be specified as conses like `(?A . ?Z)'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
885
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
886 SET may also be the name of a character class: `digit',
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
887 `control', `hex-digit', `blank', `graph', `print', `alnum',
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
888 `alpha', `ascii', `nonascii', `lower', `punct', `space', `upper',
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
889 `word', or one of their synonyms.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
890
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
891 `(not (any SET ...))'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
892 matches any character not in SET ...
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
893
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
894 `line-start', `bol'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
895 matches the empty string, but only at the beginning of a line
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
896 in the text being matched
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
897
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
898 `line-end', `eol'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
899 is similar to `line-start' but matches only at the end of a line
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
900
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
901 `string-start', `bos', `bot'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
902 matches the empty string, but only at the beginning of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
903 string being matched against.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
904
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
905 `string-end', `eos', `eot'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
906 matches the empty string, but only at the end of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
907 string being matched against.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
908
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
909 `buffer-start'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
910 matches the empty string, but only at the beginning of the
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
911 buffer being matched against. Actually equivalent to `string-start'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
912
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
913 `buffer-end'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
914 matches the empty string, but only at the end of the
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
915 buffer being matched against. Actually equivalent to `string-end'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
916
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
917 `point'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
918 matches the empty string, but only at point.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
919
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
920 `word-start', `bow'
77829
d858d80ae609 Nikolaj Schumacher <n_schumacher at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
921 matches the empty string, but only at the beginning of a word.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
922
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
923 `word-end', `eow'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
924 matches the empty string, but only at the end of a word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
925
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
926 `word-boundary'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
927 matches the empty string, but only at the beginning or end of a
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
928 word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
929
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
930 `(not word-boundary)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
931 `not-word-boundary'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
932 matches the empty string, but not at the beginning or end of a
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
933 word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
934
77829
d858d80ae609 Nikolaj Schumacher <n_schumacher at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
935 `symbol-start'
d858d80ae609 Nikolaj Schumacher <n_schumacher at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
936 matches the empty string, but only at the beginning of a symbol.
d858d80ae609 Nikolaj Schumacher <n_schumacher at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
937
d858d80ae609 Nikolaj Schumacher <n_schumacher at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
938 `symbol-end'
d858d80ae609 Nikolaj Schumacher <n_schumacher at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
939 matches the empty string, but only at the end of a symbol.
d858d80ae609 Nikolaj Schumacher <n_schumacher at web.de> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 75346
diff changeset
940
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
941 `digit', `numeric', `num'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
942 matches 0 through 9.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
943
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
944 `control', `cntrl'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
945 matches ASCII control characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
946
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
947 `hex-digit', `hex', `xdigit'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
948 matches 0 through 9, a through f and A through F.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
949
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
950 `blank'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
951 matches space and tab only.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
952
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
953 `graphic', `graph'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
954 matches graphic characters--everything except ASCII control chars,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
955 space, and DEL.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
956
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
957 `printing', `print'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
958 matches printing characters--everything except ASCII control chars
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
959 and DEL.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
960
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
961 `alphanumeric', `alnum'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
962 matches letters and digits. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
963 it matches anything that has word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
964
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
965 `letter', `alphabetic', `alpha'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
966 matches letters. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
967 it matches anything that has word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
968
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
969 `ascii'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
970 matches ASCII (unibyte) characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
971
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
972 `nonascii'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
973 matches non-ASCII (multibyte) characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
974
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
975 `lower', `lower-case'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
976 matches anything lower-case.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
977
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
978 `upper', `upper-case'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
979 matches anything upper-case.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
980
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
981 `punctuation', `punct'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
982 matches punctuation. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
983 it matches anything that has non-word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
984
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
985 `space', `whitespace', `white'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
986 matches anything that has whitespace syntax.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
987
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
988 `word', `wordchar'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
989 matches anything that has word syntax.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
990
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
991 `not-wordchar'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
992 matches anything that has non-word syntax.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
993
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
994 `(syntax SYNTAX)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
995 matches a character with syntax SYNTAX. SYNTAX must be one
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
996 of the following symbols, or a symbol corresponding to the syntax
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
997 character, e.g. `\\.' for `\\s.'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
998
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
999 `whitespace' (\\s- in string notation)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1000 `punctuation' (\\s.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1001 `word' (\\sw)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1002 `symbol' (\\s_)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1003 `open-parenthesis' (\\s()
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1004 `close-parenthesis' (\\s))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1005 `expression-prefix' (\\s')
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1006 `string-quote' (\\s\")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1007 `paired-delimiter' (\\s$)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1008 `escape' (\\s\\)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1009 `character-quote' (\\s/)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1010 `comment-start' (\\s<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1011 `comment-end' (\\s>)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
1012 `string-delimiter' (\\s|)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
1013 `comment-delimiter' (\\s!)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1014
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1015 `(not (syntax SYNTAX))'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1016 matches a character that doesn't have syntax SYNTAX.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1017
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1018 `(category CATEGORY)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1019 matches a character with category CATEGORY. CATEGORY must be
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1020 either a character to use for C, or one of the following symbols.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1021
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1022 `consonant' (\\c0 in string notation)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1023 `base-vowel' (\\c1)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1024 `upper-diacritical-mark' (\\c2)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1025 `lower-diacritical-mark' (\\c3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1026 `tone-mark' (\\c4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1027 `symbol' (\\c5)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1028 `digit' (\\c6)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1029 `vowel-modifying-diacritical-mark' (\\c7)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1030 `vowel-sign' (\\c8)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1031 `semivowel-lower' (\\c9)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1032 `not-at-end-of-line' (\\c<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1033 `not-at-beginning-of-line' (\\c>)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1034 `alpha-numeric-two-byte' (\\cA)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1035 `chinse-two-byte' (\\cC)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1036 `greek-two-byte' (\\cG)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1037 `japanese-hiragana-two-byte' (\\cH)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1038 `indian-tow-byte' (\\cI)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1039 `japanese-katakana-two-byte' (\\cK)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1040 `korean-hangul-two-byte' (\\cN)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1041 `cyrillic-two-byte' (\\cY)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1042 `combining-diacritic' (\\c^)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1043 `ascii' (\\ca)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1044 `arabic' (\\cb)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1045 `chinese' (\\cc)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1046 `ethiopic' (\\ce)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1047 `greek' (\\cg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1048 `korean' (\\ch)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1049 `indian' (\\ci)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1050 `japanese' (\\cj)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1051 `japanese-katakana' (\\ck)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1052 `latin' (\\cl)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1053 `lao' (\\co)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1054 `tibetan' (\\cq)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1055 `japanese-roman' (\\cr)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1056 `thai' (\\ct)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1057 `vietnamese' (\\cv)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1058 `hebrew' (\\cw)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1059 `cyrillic' (\\cy)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1060 `can-break' (\\c|)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1061
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1062 `(not (category CATEGORY))'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1063 matches a character that doesn't have category CATEGORY.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1064
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1065 `(and SEXP1 SEXP2 ...)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1066 `(: SEXP1 SEXP2 ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1067 `(seq SEXP1 SEXP2 ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1068 `(sequence SEXP1 SEXP2 ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1069 matches what SEXP1 matches, followed by what SEXP2 matches, etc.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1070
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1071 `(submatch SEXP1 SEXP2 ...)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1072 `(group SEXP1 SEXP2 ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1073 like `and', but makes the match accessible with `match-end',
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1074 `match-beginning', and `match-string'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1075
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1076 `(or SEXP1 SEXP2 ...)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1077 `(| SEXP1 SEXP2 ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1078 matches anything that matches SEXP1 or SEXP2, etc. If all
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1079 args are strings, use `regexp-opt' to optimize the resulting
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1080 regular expression.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1081
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1082 `(minimal-match SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1083 produce a non-greedy regexp for SEXP. Normally, regexps matching
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
1084 zero or more occurrences of something are \"greedy\" in that they
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1085 match as much as they can, as long as the overall regexp can
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1086 still match. A non-greedy regexp matches as little as possible.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1087
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1088 `(maximal-match SEXP)'
47257
14ef33c0a704 (rx): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 39516
diff changeset
1089 produce a greedy regexp for SEXP. This is the default.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1090
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1091 Below, `SEXP ...' represents a sequence of regexp forms, treated as if
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1092 enclosed in `(and ...)'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1093
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1094 `(zero-or-more SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1095 `(0+ SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1096 matches zero or more occurrences of what SEXP ... matches.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1097
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1098 `(* SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1099 like `zero-or-more', but always produces a greedy regexp, independent
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1100 of `rx-greedy-flag'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1101
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1102 `(*? SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1103 like `zero-or-more', but always produces a non-greedy regexp,
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1104 independent of `rx-greedy-flag'.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
1105
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1106 `(one-or-more SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1107 `(1+ SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1108 matches one or more occurrences of SEXP ...
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1109
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1110 `(+ SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1111 like `one-or-more', but always produces a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1112
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1113 `(+? SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1114 like `one-or-more', but always produces a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1115
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1116 `(zero-or-one SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1117 `(optional SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1118 `(opt SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1119 matches zero or one occurrences of A.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
1120
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1121 `(? SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1122 like `zero-or-one', but always produces a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1123
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1124 `(?? SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1125 like `zero-or-one', but always produces a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1126
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1127 `(repeat N SEXP)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1128 `(= N SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1129 matches N occurrences.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1130
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1131 `(>= N SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1132 matches N or more occurrences.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1133
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1134 `(repeat N M SEXP)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1135 `(** N M SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1136 matches N to M occurrences.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1137
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1138 `(backref N)'
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
1139 matches what was matched previously by submatch N.
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
1140
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1141 `(eval FORM)'
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
1142 evaluate FORM and insert result. If result is a string,
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
1143 `regexp-quote' it.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1144
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1145 `(regexp REGEXP)'
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
1146 include REGEXP in string notation in the result."
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1147 (cond ((null regexps)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1148 (error "No regexp"))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1149 ((cdr regexps)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1150 (rx-to-string `(and ,@regexps) t))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1151 (t
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1152 (rx-to-string (car regexps) t))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1153
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1154 ;; ;; sregex.el replacement
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1155
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1156 ;; ;;;###autoload (provide 'sregex)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1157 ;; ;;;###autoload (autoload 'sregex "rx")
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1158 ;; (defalias 'sregex 'rx-to-string)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1159 ;; ;;;###autoload (autoload 'sregexq "rx" nil nil 'macro)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1160 ;; (defalias 'sregexq 'rx)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
1161
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1162 (provide 'rx)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1163
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1164 ;;; rx.el ends here