annotate lisp/emacs-lisp/rx.el @ 56807:d2c0e48f4d5a

Adapt sectioning in Info to the node structure. (Invoking emacsclient): Make "Invoking emacsclient" a subsection of "Using Emacs as a Server".
author Luc Teirlinck <teirllm@auburn.edu>
date Fri, 27 Aug 2004 23:25:13 +0000
parents 93f6ab2a0eb5
children a6ae354aa8ef 4c90ffeb71c5
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
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
3 ;; Copyright (C) 2001, 03, 2004 Free Software Foundation, Inc.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Author: Gerd Moellmann <gerd@gnu.org>
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Maintainer: FSF
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; Keywords: strings, regexps, extensions
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; any later version.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;; This is another implementation of sexp-form regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; It was unfortunately written without being aware of the Sregex
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; package coming with Emacs, but as things stand, Rx completely
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; covers all regexp features, which Sregex doesn't, doesn't suffer
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; from the bugs mentioned in the commentary section of Sregex, and
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; uses a nicer syntax (IMHO, of course :-).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
35 ;; This significantly extended version of the original, is almost
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
36 ;; compatible with Sregex. The only incompatibility I (fx) know of is
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
37 ;; that the `repeat' form can't have multiple regexp args.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
38
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
39 ;; Now alternative forms are provided for a degree of compatibility
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
40 ;; with Shivers' attempted definitive SRE notation
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
41 ;; <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
42 ;; catered for include: dsm, uncase, w/case, w/nocase, ,@<exp>,
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
43 ;; ,<exp>, (word ...), word+, posix-string, and character class forms.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
44 ;; Some forms are inconsistent with SRE, either for historical reasons
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
45 ;; or because of the implementation -- simple translation into Emacs
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
46 ;; regexp strings. These include: any, word. Also, case-sensitivity
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
47 ;; and greediness are controlled by variables external to the regexp,
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
48 ;; 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
49 ;; SRE's POSIX semantics. There are probably more difficulties.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
50
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; Rx translates a sexp notation for regular expressions into the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; usual string notation. The translation can be done at compile-time
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; 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
54 ;; function `rx-to-string'. See the documentation of `rx' for a
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; complete description of the sexp notation.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;; Some examples of string regexps and their sexp counterparts:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; "^[a-z]*"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;; (rx (and line-start (0+ (in "a-z"))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; "\n[^ \t]"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; (rx (and "\n" (not blank))), or
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;; (rx (and "\n" (not (any " \t"))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 ;; "\\*\\*\\* EOOH \\*\\*\\*\n"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;; (rx "*** EOOH ***\n")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; "\\<\\(catch\\|finally\\)\\>[^_]"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; (rx (and word-start (submatch (or "catch" "finally")) word-end
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;; (not (any ?_))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; "[ \t\n]*:\\([^:]+\\|$\\)"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; (rx (and (zero-or-more (in " \t\n")) ":"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;; (submatch (or line-end (one-or-more (not (any ?:)))))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; (rx (and line-start
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; "content-transfer-encoding:"
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
80 ;; (+ (? ?\n)) blank
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 ;; "quoted-printable"
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
82 ;; (+ (? ?\n)) blank))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ;; (concat "^\\(?:" something-else "\\)")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ;; (rx (and line-start (eval something-else))), statically or
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;; (rx-to-string '(and line-start ,something-else)), dynamically.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; (regexp-opt '(STRING1 STRING2 ...))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; (rx (or STRING1 STRING2 ...)), or in other words, `or' automatically
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; calls `regexp-opt' as needed.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; "^;;\\s-*\n\\|^\n"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;; (rx (or (and line-start ";;" (0+ space) ?\n)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;; (and line-start ?\n)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 ;; "\\$[I]d: [^ ]+ \\([^ ]+\\) "
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
97 ;; (rx (and "$Id: "
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
98 ;; (1+ (not (in " ")))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 ;; " "
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 ;; (submatch (1+ (not (in " "))))
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
101 ;; " "))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 ;; "\\\\\\\\\\[\\w+"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 ;; (rx (and ?\\ ?\\ ?\[ (1+ word)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 ;; etc.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 ;;; History:
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
109 ;;
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 ;;; Code:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (defconst rx-constituents
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 '((and . (rx-and 1 nil))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
115 (seq . and) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
116 (: . and) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
117 (sequence . and) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 (or . (rx-or 1 nil))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
119 (| . or) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (not-newline . ".")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
121 (nonl . not-newline) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (anything . ".\\|\n")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
123 (any . (rx-any 1 nil rx-check-any)) ; inconsistent with SRE
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))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
128 ;; Partially consistent with sregex, whose `repeat' is like our
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
129 ;; `**'. (`repeat' with optional max arg and multiple sexp forms
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
130 ;; is ambiguous.)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (repeat . (rx-repeat 2 3))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
132 (= . (rx-= 2 nil)) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
133 (>= . (rx->= 2 nil)) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
134 (** . (rx-** 2 nil)) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
135 (submatch . (rx-submatch 1 nil)) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (group . submatch)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
137 (zero-or-more . (rx-kleene 1 nil))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
138 (one-or-more . (rx-kleene 1 nil))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
139 (zero-or-one . (rx-kleene 1 nil))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
140 (\? . zero-or-one) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (\?? . zero-or-one)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
142 (* . zero-or-more) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (*? . zero-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (0+ . zero-or-more)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
145 (+ . one-or-more) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (+? . one-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (1+ . one-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (optional . zero-or-one)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
149 (opt . zero-or-one) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (minimal-match . (rx-greedy 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (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
152 (backref . (rx-backref 1 1 rx-check-backref))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (line-start . "^")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
154 (bol . line-start) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (line-end . "$")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
156 (eol . line-end) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (string-start . "\\`")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
158 (bos . string-start) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
159 (bot . string-start) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (string-end . "\\'")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
161 (eos . string-end) ; SRE
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
162 (eot . string-end) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (buffer-start . "\\`")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (buffer-end . "\\'")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (point . "\\=")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (word-start . "\\<")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
167 (bow . word-start) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (word-end . "\\>")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
169 (eow . word-end) ; SRE
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (word-boundary . "\\b")
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
171 (not-word-boundary . "\\B") ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (syntax . (rx-syntax 1 1))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
173 (not-syntax . (rx-not-syntax 1 1)) ; sregex
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (category . (rx-category 1 1 rx-check-category))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (eval . (rx-eval 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (regexp . (rx-regexp 1 1 stringp))
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
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
208 (not-wordchar . "[^[:word:]]") ; sregex (use \\W?)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
209 )
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 "Alist of sexp form regexp constituents.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 Each element of the alist has the form (SYMBOL . DEFN).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 SYMBOL is a valid constituent of sexp regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 If DEFN is a string, SYMBOL is translated into DEFN.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 If DEFN is a symbol, use the definition of DEFN, recursively.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 Otherwise, DEFN must be a list (FUNCTION MIN-ARGS MAX-ARGS PREDICATE).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 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
217 are the minimum and maximum number of arguments the function-form
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 sexp constituent SYMBOL may have in sexp regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 MAX-ARGS nil means no limit. PREDICATE, if specified, means that
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 all arguments must satisfy PREDICATE.")
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
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (defconst rx-syntax
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 '((whitespace . ?-)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (punctuation . ?.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (word . ?w)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (symbol . ?_)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (open-parenthesis . ?\()
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (close-parenthesis . ?\))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (expression-prefix . ?\')
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (string-quote . ?\")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 (paired-delimiter . ?$)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (escape . ?\\)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 (character-quote . ?/)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (comment-start . ?<)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
236 (comment-end . ?>)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
237 (string-delimiter . ?|)
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
238 (comment-delimiter . ?!))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 "Alist mapping Rx syntax symbols to syntax characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 symbol in `(syntax SYMBOL)', and CHAR is the syntax character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 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
243 regular expressions.")
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
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (defconst rx-categories
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 '((consonant . ?0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (base-vowel . ?1)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (upper-diacritical-mark . ?2)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 (lower-diacritical-mark . ?3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (tone-mark . ?4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (symbol . ?5)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (digit . ?6)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (vowel-modifying-diacritical-mark . ?7)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (vowel-sign . ?8)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (semivowel-lower . ?9)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (not-at-end-of-line . ?<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (not-at-beginning-of-line . ?>)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (alpha-numeric-two-byte . ?A)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (chinse-two-byte . ?C)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (greek-two-byte . ?G)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (japanese-hiragana-two-byte . ?H)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (indian-two-byte . ?I)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (japanese-katakana-two-byte . ?K)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (korean-hangul-two-byte . ?N)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (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
267 (combining-diacritic . ?^)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (ascii . ?a)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (arabic . ?b)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (chinese . ?c)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (ethiopic . ?e)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (greek . ?g)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (korean . ?h)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (indian . ?i)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (japanese . ?j)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (japanese-katakana . ?k)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (latin . ?l)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (lao . ?o)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 (tibetan . ?q)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (japanese-roman . ?r)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (thai . ?t)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (vietnamese . ?v)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (hebrew . ?w)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (cyrillic . ?y)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (can-break . ?|))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 "Alist mapping symbols to category characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 symbol in `(category SYMBOL)', and CHAR is the category character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 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
290 regular expression strings.")
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
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (defvar rx-greedy-flag t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 "Non-nil means produce greedy regular expressions for `zero-or-one',
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 `zero-or-more', and `one-or-more'. Dynamically bound.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (defun rx-info (op)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 "Return parsing/code generation info for OP.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 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
301 If OP is the character `?', return info for the symbol `??'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 See also `rx-constituents'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 (cond ((eq op ? ) (setq op '\?))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 ((eq op ??) (setq op '\??)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 (while (and (not (null op)) (symbolp op))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 (setq op (cdr (assq op rx-constituents))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 op)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
308
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 (defun rx-check (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 "Check FORM according to its car's parsing info."
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
312 (unless (listp form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
313 (error "rx `%s' needs argument(s)" form))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (let* ((rx (rx-info (car form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (nargs (1- (length form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (min-args (nth 1 rx))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 (max-args (nth 2 rx))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (type-pred (nth 3 rx)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (when (and (not (null min-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (< nargs min-args))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
321 (error "rx form `%s' requires at least %d args"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (car form) min-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (when (and (not (null max-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 (> nargs max-args))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
325 (error "rx form `%s' accepts at most %d args"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (car form) max-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (when (not (null type-pred))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (dolist (sub-form (cdr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (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
330 (error "rx form `%s' requires args satisfying `%s'"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (car form) type-pred))))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (defun rx-and (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 FORM is of the form `(and FORM1 ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (rx-check form)
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
338 (concat "\\(?:"
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
339 (mapconcat
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
340 (function (lambda (x) (rx-to-string x 'no-group)))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
341 (cdr form) nil)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
342 "\\)"))
39516
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
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (defun rx-or (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 "Parse and produce code from FORM, which is `(or FORM1 ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (let ((all-args-strings t))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 (dolist (arg (cdr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (unless (stringp arg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (setq all-args-strings nil)))
52971
d5c1eeaa97e2 (rx-or): Fix the case of "(rx (and ?a (or ?b ?c) ?d))".
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
352 (concat "\\(?:"
d5c1eeaa97e2 (rx-or): Fix the case of "(rx (and ?a (or ?b ?c) ?d))".
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
353 (if all-args-strings
d5c1eeaa97e2 (rx-or): Fix the case of "(rx (and ?a (or ?b ?c) ?d))".
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
354 (regexp-opt (cdr form))
d5c1eeaa97e2 (rx-or): Fix the case of "(rx (and ?a (or ?b ?c) ?d))".
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
355 (mapconcat #'rx-to-string (cdr form) "\\|"))
d5c1eeaa97e2 (rx-or): Fix the case of "(rx (and ?a (or ?b ?c) ?d))".
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
356 "\\)")))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
359 (defvar rx-bracket) ; dynamically bound in `rx-any'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (defun rx-check-any (arg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 "Check arg ARG for Rx `any'."
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
363 (if (integerp arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
364 (setq arg (string arg)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
365 (when (stringp arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
366 (if (zerop (length arg))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
367 (error "String arg for Rx `any' must not be empty"))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
368 ;; Quote ^ at start; don't bother to check whether this is first arg.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
369 (if (eq ?^ (aref arg 0))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
370 (setq arg (concat "\\" arg)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
371 ;; Remove ] and set flag for adding it to start of overall result.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
372 (when (string-match "]" arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
373 (setq arg (replace-regexp-in-string "]" "" arg)
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
374 rx-bracket "]")))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
375 (when (symbolp arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
376 (let ((translation (condition-case nil
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
377 (rx-to-string arg 'no-group)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
378 (error nil))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
379 (unless translation (error "Invalid char class `%s' in Rx `any'" arg))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
380 (setq arg (substring translation 1 -1)))) ; strip outer brackets
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
381 ;; sregex compatibility
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
382 (when (and (integerp (car-safe arg))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
383 (integerp (cdr-safe arg)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
384 (setq arg (string (car arg) ?- (cdr arg))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
385 (unless (stringp arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
386 (error "rx `any' requires string, character, char pair or char class args"))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
387 arg)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (defun rx-any (form)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
390 "Parse and produce code from FORM, which is `(any ARG ...)'.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
391 ARG is optional."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (rx-check form)
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
393 (let* ((rx-bracket nil)
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
394 (args (mapcar #'rx-check-any (cdr form)))) ; side-effects `rx-bracket'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
395 ;; If there was a ?- in the form, move it to the front to avoid
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
396 ;; accidental range.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
397 (if (member "-" args)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
398 (setq args (cons "-" (delete "-" args))))
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
399 (apply #'concat "[" rx-bracket (append args '("]")))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
402 (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
403 "Check arg ARG for Rx `not'."
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
404 (unless (or (and (symbolp arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
405 (string-match "\\`\\[\\[:[-a-z]:]]\\'"
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
406 (condition-case nil
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
407 (rx-to-string arg 'no-group)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
408 (error ""))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
409 (eq arg 'word-boundary)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
410 (and (consp arg)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
411 (memq (car arg) '(not any in syntax category))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
412 (error "rx `not' syntax error: %s" arg))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
413 t)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (defun rx-not (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 "Parse and produce code from FORM. FORM is `(not ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (rx-check form)
53974
818e19ae4c5a (rx-not): Bind case-fold-search to nil.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52971
diff changeset
419 (let ((result (rx-to-string (cadr form) 'no-group))
818e19ae4c5a (rx-not): Bind case-fold-search to nil.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52971
diff changeset
420 case-fold-search)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 (cond ((string-match "\\`\\[^" result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 (if (= (length result) 4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (substring result 2 3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (concat "[" (substring result 2))))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
425 ((eq ?\[ (aref result 0))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (concat "[^" (substring result 1)))
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
427 ((string-match "\\`\\\\[scb]" result)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
428 (concat (capitalize (substring result 0 2)) (substring result 2)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (concat "[^" result "]")))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
433 (defun rx-not-char (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
434 "Parse and produce code from FORM. FORM is `(not-char ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
435 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
436 (rx-not `(not (in ,@(cdr form)))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
437
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
438
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
439 (defun rx-not-syntax (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
440 "Parse and produce code from FORM. FORM is `(not-syntax SYNTAX)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
441 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
442 (rx-not `(not (syntax ,@(cdr form)))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
443
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
444
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
445 (defun rx-trans-forms (form &optional skip)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
446 "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
447 A form (HEAD REST ...) becomes (HEAD (and REST ...)).
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
448 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
449 `(= N REST ...)' becomes `(= N (and REST ...))' if SKIP is 1."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
450 (unless skip (setq skip 0))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
451 (let ((tail (nthcdr (1+ skip) form)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
452 (if (= (length tail) 1)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
453 form
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
454 (let ((form (copy-sequence form)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
455 (setcdr (nthcdr skip form) (list (cons 'and tail)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
456 form))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
457
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
458
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
459 (defun rx-= (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
460 "Parse and produce code from FORM `(= N ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
461 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
462 (setq form (rx-trans-forms form 1))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
463 (unless (and (integerp (nth 1 form))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
464 (> (nth 1 form) 0))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
465 (error "rx `=' requires positive integer first arg"))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
466 (format "%s\\{%d\\}" (rx-to-string (nth 2 form)) (nth 1 form)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
467
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
468
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
469 (defun rx->= (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
470 "Parse and produce code from FORM `(>= N ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
471 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
472 (setq form (rx-trans-forms form 1))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
473 (unless (and (integerp (nth 1 form))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
474 (> (nth 1 form) 0))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
475 (error "rx `>=' requires positive integer first arg"))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
476 (format "%s\\{%d,\\}" (rx-to-string (nth 2 form)) (nth 1 form)))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
477
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
478
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
479 (defun rx-** (form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
480 "Parse and produce code from FORM `(** N M ...)'."
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
481 (rx-check form)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
482 (setq form (cons 'repeat (cdr (rx-trans-forms form 2))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
483 (rx-to-string form))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
484
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
485
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 (defun rx-repeat (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 FORM is either `(repeat N FORM1)' or `(repeat N M FORM1)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (cond ((= (length form) 3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (unless (and (integerp (nth 1 form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 (> (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
493 (error "rx `repeat' requires positive integer first arg"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (format "%s\\{%d\\}" (rx-to-string (nth 2 form)) (nth 1 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 ((or (not (integerp (nth 2 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (< (nth 2 form) 0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (not (integerp (nth 1 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 (< (nth 1 form) 0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 (< (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
500 (error "rx `repeat' range error"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 (t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (format "%s\\{%d,%d\\}" (rx-to-string (nth 3 form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 (nth 1 form) (nth 2 form)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (defun rx-submatch (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 "Parse and produce code from FORM, which is `(submatch ...)'."
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
508 (concat "\\("
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
509 (mapconcat (function (lambda (x) (rx-to-string x 'no-group)))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
510 (cdr form) nil)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
511 "\\)"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
513 (defun rx-backref (form)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
514 "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
515 (rx-check form)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
516 (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
517
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
518 (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
519 "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
520 (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
521 (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
522
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 (defun rx-kleene (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 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
526 `zero-or-more' etc. operators.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 If OP is one of `*', `+', `?', produce a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 If OP is one of `*?', `+?', `??', produce a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 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
530 is non-nil."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 (rx-check form)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
532 (setq form (rx-trans-forms form))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 (let ((suffix (cond ((memq (car form) '(* + ? )) "")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 ((memq (car form) '(*? +? ??)) "?")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (rx-greedy-flag "")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 (t "?")))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (op (cond ((memq (car form) '(* *? 0+ zero-or-more)) "*")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 ((memq (car form) '(+ +? 1+ one-or-more)) "+")
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
539 (t "?")))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
540 (result (rx-to-string (cadr form) 'no-group)))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
541 (if (not (rx-atomic-p result))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
542 (setq result (concat "\\(?:" result "\\)")))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
543 (concat result op suffix)))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
544
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
545 (defun rx-atomic-p (r)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
546 "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
547 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
548 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
549 \"[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
550 \"[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
551
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
552 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
553 return false positives. It is nevertheless useful in
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
554 situations where an efficiency shortcut can be taken iff a
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
555 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
556 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
557 detects the following categories of atomic regexp;
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
558
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
559 a group or shy group: \\(...\\)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
560 a character class: [...]
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
561 a single character: a
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
562
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
563 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
564 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
565 \"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
566 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
567 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
568 of all atomic regexps."
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
569 (let ((l (length r)))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
570 (or (equal l 1)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
571 (and (>= l 6)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
572 (equal (substring r 0 2) "\\(")
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
573 (equal (substring r -2) "\\)"))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
574 (and (>= l 2)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
575 (equal (substring r 0 1) "[")
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
576 (equal (substring r -1) "]")))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 (defun rx-syntax (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 "Parse and produce code from FORM, which is `(syntax SYMBOL)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 (rx-check form)
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
582 (let* ((sym (cadr form))
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
583 (syntax (assq sym rx-syntax)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 (unless syntax
55103
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
585 ;; Try sregex compatibility.
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
586 (let ((name (symbol-name sym)))
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
587 (if (= 1 (length name))
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
588 (setq syntax (rassq (aref name 0) rx-syntax))))
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
589 (unless syntax
93f6ab2a0eb5 (rx-syntax): Move sregex style syntax to code.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 55102
diff changeset
590 (error "Unknown rx syntax `%s'" (cadr form))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (format "\\s%c" (cdr syntax))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (defun rx-check-category (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 "Check the argument FORM of a `(category FORM)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (unless (or (integerp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (cdr (assq form rx-categories)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (error "Unknown category `%s'" form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 t)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
600
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (defun rx-category (form)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
603 "Parse and produce code from FORM, which is `(category SYMBOL)'."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 (let ((char (if (integerp (cadr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 (cadr form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 (cdr (assq (cadr form) rx-categories)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 (format "\\c%c" char)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 (defun rx-eval (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 "Parse and produce code from FORM, which is `(eval FORM)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 (rx-to-string (eval (cadr form))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617 (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
618 "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
619 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
620 `+', 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
621 '(maximal-match FORM1)', greedy operators will be used."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (let ((rx-greedy-flag (eq (car form) 'maximal-match)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (rx-to-string (cadr form))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (defun rx-regexp (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 "Parse and produce code from FORM, which is `(regexp STRING)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 (concat "\\(?:" (cadr form) "\\)"))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
631
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 ;;;###autoload
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 (defun rx-to-string (form &optional no-group)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 "Parse and produce code for regular expression FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 FORM is a regular expression in sexp form.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 NO-GROUP non-nil means don't put shy groups around the result."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 (cond ((stringp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 (regexp-quote form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 ((integerp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 (regexp-quote (char-to-string form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 ((symbolp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 (let ((info (rx-info form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 (cond ((stringp info)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 info)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 ((null info)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
647 (error "Unknown rx form `%s'" form))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
648 (t
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 (funcall (nth 0 info) form)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 ((consp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 (let ((info (rx-info (car form))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 (unless (consp info)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
653 (error "Unknown rx form `%s'" (car form)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 (let ((result (funcall (nth 0 info) form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 (if (or no-group (string-match "\\`\\\\[(]" result))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 result
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 (concat "\\(?:" result "\\)")))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 (t
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
659 (error "rx syntax error at `%s'" form))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 ;;;###autoload
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
663 (defmacro rx (&rest regexps)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
664 "Translate regular expressions REGEXPS in sexp form to a regexp string.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
665 REGEXPS is a non-empty sequence of forms of the sort listed below.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
666 See also `rx-to-string' for how to do such a translation at run-time.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 The following are valid subforms of regular expressions in sexp
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669 notation.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 STRING
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 matches string STRING literally.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 CHAR
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 matches character CHAR literally.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
677 `not-newline', `nonl'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 matches any character except a newline.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 .
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 `anything'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 matches any character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
683 `(any SET ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
684 `(in SET ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
685 `(char SET ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
686 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
687 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
688 Ranges may also be specified as conses like `(?A . ?Z)'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
689
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
690 SET may also be the name of a character class: `digit',
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
691 `control', `hex-digit', `blank', `graph', `print', `alnum',
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
692 `alpha', `ascii', `nonascii', `lower', `punct', `space', `upper',
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
693 `word', or one of their synonyms.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
695 `(not (any SET ...))'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
696 matches any character not in SET ...
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
697
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
698 `line-start', `bol'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
699 matches the empty string, but only at the beginning of a line
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
700 in the text being matched
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
701
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
702 `line-end', `eol'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
703 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
704
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
705 `string-start', `bos', `bot'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
706 matches the empty string, but only at the beginning of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 string being matched against.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
708
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
709 `string-end', `eos', `eot'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
710 matches the empty string, but only at the end of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 string being matched against.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
712
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
713 `buffer-start'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
714 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
715 buffer being matched against. Actually equivalent to `string-start'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
716
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
717 `buffer-end'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
718 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
719 buffer being matched against. Actually equivalent to `string-end'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
720
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
721 `point'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
722 matches the empty string, but only at point.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
723
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
724 `word-start', `bow'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
725 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
726 word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
727
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
728 `word-end', `eow'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
729 matches the empty string, but only at the end of a word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
730
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 `word-boundary'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
732 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
733 word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
735 `(not word-boundary)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
736 `not-word-boundary'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 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
738 word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
740 `digit', `numeric', `num'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
741 matches 0 through 9.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
743 `control', `cntrl'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 matches ASCII control characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
746 `hex-digit', `hex', `xdigit'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747 matches 0 through 9, a through f and A through F.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
749 `blank'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
750 matches space and tab only.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
751
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
752 `graphic', `graph'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
753 matches graphic characters--everything except ASCII control chars,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
754 space, and DEL.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
755
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
756 `printing', `print'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
757 matches printing characters--everything except ASCII control chars
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
758 and DEL.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
759
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
760 `alphanumeric', `alnum'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
761 matches letters and digits. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
762 it matches anything that has word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
764 `letter', `alphabetic', `alpha'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
765 matches letters. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
766 it matches anything that has word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
767
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
768 `ascii'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
769 matches ASCII (unibyte) characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
770
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
771 `nonascii'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
772 matches non-ASCII (multibyte) characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
773
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
774 `lower', `lower-case'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
775 matches anything lower-case.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
776
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
777 `upper', `upper-case'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
778 matches anything upper-case.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
779
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
780 `punctuation', `punct'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
781 matches punctuation. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
782 it matches anything that has non-word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
783
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
784 `space', `whitespace', `white'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
785 matches anything that has whitespace syntax.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
786
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
787 `word', `wordchar'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
788 matches anything that has word syntax.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
789
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
790 `not-wordchar'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
791 matches anything that has non-word syntax.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
792
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
793 `(syntax SYNTAX)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
794 matches a character with syntax SYNTAX. SYNTAX must be one
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
795 of the following symbols, or a symbol corresponding to the syntax
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
796 character, e.g. `\\.' for `\\s.'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
797
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
798 `whitespace' (\\s- in string notation)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
799 `punctuation' (\\s.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
800 `word' (\\sw)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
801 `symbol' (\\s_)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
802 `open-parenthesis' (\\s()
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
803 `close-parenthesis' (\\s))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
804 `expression-prefix' (\\s')
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
805 `string-quote' (\\s\")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
806 `paired-delimiter' (\\s$)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
807 `escape' (\\s\\)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
808 `character-quote' (\\s/)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
809 `comment-start' (\\s<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
810 `comment-end' (\\s>)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
811 `string-delimiter' (\\s|)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
812 `comment-delimiter' (\\s!)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
813
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
814 `(not (syntax SYNTAX))'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
815 matches a character that doesn't have syntax SYNTAX.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
816
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
817 `(category CATEGORY)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
818 matches a character with category CATEGORY. CATEGORY must be
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
819 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
820
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
821 `consonant' (\\c0 in string notation)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
822 `base-vowel' (\\c1)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
823 `upper-diacritical-mark' (\\c2)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
824 `lower-diacritical-mark' (\\c3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
825 `tone-mark' (\\c4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
826 `symbol' (\\c5)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
827 `digit' (\\c6)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
828 `vowel-modifying-diacritical-mark' (\\c7)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
829 `vowel-sign' (\\c8)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
830 `semivowel-lower' (\\c9)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
831 `not-at-end-of-line' (\\c<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
832 `not-at-beginning-of-line' (\\c>)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
833 `alpha-numeric-two-byte' (\\cA)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
834 `chinse-two-byte' (\\cC)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
835 `greek-two-byte' (\\cG)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
836 `japanese-hiragana-two-byte' (\\cH)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
837 `indian-tow-byte' (\\cI)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
838 `japanese-katakana-two-byte' (\\cK)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
839 `korean-hangul-two-byte' (\\cN)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
840 `cyrillic-two-byte' (\\cY)
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
841 `combining-diacritic' (\\c^)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
842 `ascii' (\\ca)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
843 `arabic' (\\cb)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
844 `chinese' (\\cc)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
845 `ethiopic' (\\ce)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
846 `greek' (\\cg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
847 `korean' (\\ch)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
848 `indian' (\\ci)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
849 `japanese' (\\cj)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
850 `japanese-katakana' (\\ck)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
851 `latin' (\\cl)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
852 `lao' (\\co)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
853 `tibetan' (\\cq)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
854 `japanese-roman' (\\cr)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
855 `thai' (\\ct)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
856 `vietnamese' (\\cv)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
857 `hebrew' (\\cw)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
858 `cyrillic' (\\cy)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
859 `can-break' (\\c|)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
860
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
861 `(not (category CATEGORY))'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
862 matches a character that doesn't have category CATEGORY.
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 `(and SEXP1 SEXP2 ...)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
865 `(: SEXP1 SEXP2 ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
866 `(seq SEXP1 SEXP2 ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
867 `(sequence SEXP1 SEXP2 ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
868 matches what SEXP1 matches, followed by what SEXP2 matches, etc.
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 `(submatch SEXP1 SEXP2 ...)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
871 `(group SEXP1 SEXP2 ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
872 like `and', but makes the match accessible with `match-end',
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
873 `match-beginning', and `match-string'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
874
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
875 `(group SEXP1 SEXP2 ...)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
876 another name for `submatch'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
877
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
878 `(or SEXP1 SEXP2 ...)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
879 `(| SEXP1 SEXP2 ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
880 matches anything that matches SEXP1 or SEXP2, etc. If all
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
881 args are strings, use `regexp-opt' to optimize the resulting
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
882 regular expression.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
883
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
884 `(minimal-match SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
885 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
886 zero or more occurrences of something are \"greedy\" in that they
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
887 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
888 still match. A non-greedy regexp matches as little as possible.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
889
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
890 `(maximal-match SEXP)'
47257
14ef33c0a704 (rx): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 39516
diff changeset
891 produce a greedy regexp for SEXP. This is the default.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
892
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
893 Below, `SEXP ...' represents a sequence of regexp forms, treated as if
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
894 enclosed in `(and ...)'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
895
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
896 `(zero-or-more SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
897 `(0+ SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
898 matches zero or more occurrences of what SEXP ... matches.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
899
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
900 `(* SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
901 like `zero-or-more', but always produces a greedy regexp, independent
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
902 of `rx-greedy-flag'.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
903
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
904 `(*? SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
905 like `zero-or-more', but always produces a non-greedy regexp,
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
906 independent of `rx-greedy-flag'.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
907
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
908 `(one-or-more SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
909 `(1+ SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
910 matches one or more occurrences of SEXP ...
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
911
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
912 `(+ SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
913 like `one-or-more', but always produces a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
914
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
915 `(+? SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
916 like `one-or-more', but always produces a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
917
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
918 `(zero-or-one SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
919 `(optional SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
920 `(opt SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
921 matches zero or one occurrences of A.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
922
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
923 `(? SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
924 like `zero-or-one', but always produces a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
925
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
926 `(?? SEXP ...)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
927 like `zero-or-one', but always produces a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
928
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
929 `(repeat N SEXP)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
930 `(= N SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
931 matches N occurrences.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
932
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
933 `(>= N SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
934 matches N or more occurrences.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
935
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
936 `(repeat N M SEXP)'
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
937 `(** N M SEXP ...)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
938 matches N to M occurrences.
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
939
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
940 `(backref N)'
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
941 matches what was matched previously by submatch N.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
942
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
943 `(backref N)'
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
944 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
945
54601
d2d20534e329 (rx): Work at compile time, not run time.
Eli Zaretskii <eliz@gnu.org>
parents: 54503
diff changeset
946 `(backref N)'
d2d20534e329 (rx): Work at compile time, not run time.
Eli Zaretskii <eliz@gnu.org>
parents: 54503
diff changeset
947 matches what was matched previously by submatch N.
d2d20534e329 (rx): Work at compile time, not run time.
Eli Zaretskii <eliz@gnu.org>
parents: 54503
diff changeset
948
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
949 `(eval FORM)'
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
950 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
951 `regexp-quote' it.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
952
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
953 `(regexp REGEXP)'
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
954 include REGEXP in string notation in the result."
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
955 (cond ((null regexps)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
956 (error "No regexp"))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
957 ((cdr regexps)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
958 (rx-to-string `(and ,@regexps) t))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
959 (t
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
960 (rx-to-string (car regexps) t))))
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
961
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
962 ;; ;; sregex.el replacement
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
963
55102
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
964 ;; ;;;###autoload (provide 'sregex)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
965 ;; ;;;###autoload (autoload 'sregex "rx")
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
966 ;; (defalias 'sregex 'rx-to-string)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
967 ;; ;;;###autoload (autoload 'sregexq "rx" nil nil 'macro)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
968 ;; (defalias 'sregexq 'rx)
95c1c6487fda Doc fixes.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 54601
diff changeset
969
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
970 (provide 'rx)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
971
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
972 ;;; arch-tag: 12d01a63-0008-42bb-ab8c-1c7d63be370b
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
973 ;;; rx.el ends here