annotate lisp/emacs-lisp/rx.el @ 54725:0b482d5702c7

(term-is-xemacs): Remove. (term-if-xemacs, term-ifnot-xemacs): Test (featurep 'xemacs). (term-window-width): New function. (term-mode, term-check-size): Use it. (term-mode): Disable overflow-newline-into-fringe in term buffer.
author Kim F. Storm <storm@cua.dk>
date Mon, 05 Apr 2004 21:34:05 +0000
parents d2d20534e329
children 95c1c6487fda
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
54601
d2d20534e329 (rx): Work at compile time, not run time.
Eli Zaretskii <eliz@gnu.org>
parents: 54503
diff changeset
3 ;; Copyright (C) 2001, 2003, 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
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; Rx translates a sexp notation for regular expressions into the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; usual string notation. The translation can be done at compile-time
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; 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
38 ;; function `rx-to-string'. See the documentation of `rx' for a
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; complete description of the sexp notation.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; Some examples of string regexps and their sexp counterparts:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; "^[a-z]*"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; (rx (and line-start (0+ (in "a-z"))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; "\n[^ \t]"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; (rx (and "\n" (not blank))), or
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; (rx (and "\n" (not (any " \t"))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; "\\*\\*\\* EOOH \\*\\*\\*\n"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; (rx "*** EOOH ***\n")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; "\\<\\(catch\\|finally\\)\\>[^_]"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; (rx (and word-start (submatch (or "catch" "finally")) word-end
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; (not (any ?_))))
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 ;; "[ \t\n]*:\\([^:]+\\|$\\)"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; (rx (and (zero-or-more (in " \t\n")) ":"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; (submatch (or line-end (one-or-more (not (any ?:)))))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 ;; "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;; (rx (and line-start
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; "content-transfer-encoding:"
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
64 ;; (+ (? ?\n)) blank
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 ;; "quoted-printable"
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
66 ;; (+ (? ?\n)) blank))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 ;; (concat "^\\(?:" something-else "\\)")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 ;; (rx (and line-start (eval something-else))), statically or
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 ;; (rx-to-string '(and line-start ,something-else)), dynamically.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 ;; (regexp-opt '(STRING1 STRING2 ...))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 ;; (rx (or STRING1 STRING2 ...)), or in other words, `or' automatically
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 ;; calls `regexp-opt' as needed.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 ;; "^;;\\s-*\n\\|^\n"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 ;; (rx (or (and line-start ";;" (0+ space) ?\n)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;; (and line-start ?\n)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;; "\\$[I]d: [^ ]+ \\([^ ]+\\) "
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
81 ;; (rx (and "$Id: "
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
82 ;; (1+ (not (in " ")))
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 ;; (submatch (1+ (not (in " "))))
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
85 ;; " "))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 ;; "\\\\\\\\\\[\\w+"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; (rx (and ?\\ ?\\ ?\[ (1+ word)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;;
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 ;; etc.
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 ;;; History:
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
93 ;;
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;;; Code:
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (defconst rx-constituents
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 '((and . (rx-and 1 nil))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (or . (rx-or 1 nil))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (not-newline . ".")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (anything . ".\\|\n")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (any . (rx-any 1 1 rx-check-any))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (in . any)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (not . (rx-not 1 1 rx-check-not))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 (repeat . (rx-repeat 2 3))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (submatch . (rx-submatch 1 nil))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 (group . submatch)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (zero-or-more . (rx-kleene 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (one-or-more . (rx-kleene 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (zero-or-one . (rx-kleene 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (\? . zero-or-one)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (\?? . zero-or-one)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 (* . zero-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (*? . zero-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 (0+ . zero-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (+ . one-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 (+? . one-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (1+ . one-or-more)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (optional . zero-or-one)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (minimal-match . (rx-greedy 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (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
123 (backref . (rx-backref 1 1 rx-check-backref))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (line-start . "^")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (line-end . "$")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 (string-start . "\\`")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (string-end . "\\'")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (buffer-start . "\\`")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (buffer-end . "\\'")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (point . "\\=")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (word-start . "\\<")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (word-end . "\\>")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (word-boundary . "\\b")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (syntax . (rx-syntax 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (category . (rx-category 1 1 rx-check-category))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (eval . (rx-eval 1 1))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (regexp . (rx-regexp 1 1 stringp))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (digit . "[[:digit:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (control . "[[:cntrl:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (hex-digit . "[[:xdigit:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (blank . "[[:blank:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (graphic . "[[:graph:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (printing . "[[:print:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (alphanumeric . "[[:alnum:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (letter . "[[:alpha:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (ascii . "[[:ascii:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (nonascii . "[[:nonascii:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (lower . "[[:lower:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (punctuation . "[[:punct:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (space . "[[:space:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (upper . "[[:upper:]]")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (word . "[[:word:]]"))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 "Alist of sexp form regexp constituents.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 Each element of the alist has the form (SYMBOL . DEFN).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 SYMBOL is a valid constituent of sexp regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 If DEFN is a string, SYMBOL is translated into DEFN.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 If DEFN is a symbol, use the definition of DEFN, recursively.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 Otherwise, DEFN must be a list (FUNCTION MIN-ARGS MAX-ARGS PREDICATE).
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 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
160 are the minimum and maximum number of arguments the function-form
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 sexp constituent SYMBOL may have in sexp regular expressions.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 MAX-ARGS nil means no limit. PREDICATE, if specified, means that
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 all arguments must satisfy PREDICATE.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 (defconst rx-syntax
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 '((whitespace . ?-)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (punctuation . ?.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 (word . ?w)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (symbol . ?_)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (open-parenthesis . ?\()
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (close-parenthesis . ?\))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (expression-prefix . ?\')
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (string-quote . ?\")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (paired-delimiter . ?$)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (escape . ?\\)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (character-quote . ?/)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (comment-start . ?<)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
179 (comment-end . ?>)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
180 (string-delimiter . ?|)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
181 (comment-delimiter . ?!))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 "Alist mapping Rx syntax symbols to syntax characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 symbol in `(syntax SYMBOL)', and CHAR is the syntax character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 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
186 regular expressions.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (defconst rx-categories
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 '((consonant . ?0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (base-vowel . ?1)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (upper-diacritical-mark . ?2)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (lower-diacritical-mark . ?3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 (tone-mark . ?4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (symbol . ?5)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 (digit . ?6)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (vowel-modifying-diacritical-mark . ?7)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (vowel-sign . ?8)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (semivowel-lower . ?9)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (not-at-end-of-line . ?<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (not-at-beginning-of-line . ?>)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 (alpha-numeric-two-byte . ?A)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (chinse-two-byte . ?C)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (greek-two-byte . ?G)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (japanese-hiragana-two-byte . ?H)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (indian-two-byte . ?I)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (japanese-katakana-two-byte . ?K)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (korean-hangul-two-byte . ?N)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (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
210 (combining-diacritic . ?^)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (ascii . ?a)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (arabic . ?b)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (chinese . ?c)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (ethiopic . ?e)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 (greek . ?g)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 (korean . ?h)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (indian . ?i)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (japanese . ?j)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (japanese-katakana . ?k)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (latin . ?l)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (lao . ?o)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (tibetan . ?q)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (japanese-roman . ?r)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (thai . ?t)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (vietnamese . ?v)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (hebrew . ?w)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (cyrillic . ?y)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (can-break . ?|))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 "Alist mapping symbols to category characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 symbol in `(category SYMBOL)', and CHAR is the category character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 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
233 regular expression strings.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (defvar rx-greedy-flag t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 "Non-nil means produce greedy regular expressions for `zero-or-one',
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 `zero-or-more', and `one-or-more'. Dynamically bound.")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (defun rx-info (op)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 "Return parsing/code generation info for OP.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 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
244 If OP is the character `?', return info for the symbol `??'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 See also `rx-constituents'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (cond ((eq op ? ) (setq op '\?))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 ((eq op ??) (setq op '\??)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (while (and (not (null op)) (symbolp op))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (setq op (cdr (assq op rx-constituents))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 op)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
251
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (defun rx-check (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 "Check FORM according to its car's parsing info."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (let* ((rx (rx-info (car form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (nargs (1- (length form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (min-args (nth 1 rx))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (max-args (nth 2 rx))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (type-pred (nth 3 rx)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (when (and (not (null min-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (< nargs min-args))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
262 (error "rx form `%s' requires at least %d args"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (car form) min-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (when (and (not (null max-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (> nargs max-args))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
266 (error "rx form `%s' accepts at most %d args"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (car form) max-args))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (when (not (null type-pred))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (dolist (sub-form (cdr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (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
271 (error "rx form `%s' requires args satisfying `%s'"
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (car form) type-pred))))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (defun rx-and (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 FORM is of the form `(and FORM1 ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (rx-check form)
48938
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
279 (concat "\\(?:"
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
280 (mapconcat
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
281 (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
282 (cdr form) nil)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
283 "\\)"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (defun rx-or (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 "Parse and produce code from FORM, which is `(or FORM1 ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (let ((all-args-strings t))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (dolist (arg (cdr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (unless (stringp arg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (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
293 (concat "\\(?:"
d5c1eeaa97e2 (rx-or): Fix the case of "(rx (and ?a (or ?b ?c) ?d))".
Eli Zaretskii <eliz@gnu.org>
parents: 52401
diff changeset
294 (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
295 (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
296 (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
297 "\\)")))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (defun rx-quote-for-set (string)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 "Transform STRING for use in a character set.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 If STRING contains a `]', move it to the front.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 If STRING starts with a '^', move it to the end."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (when (string-match "\\`\\(\\(?:.\\|\n\\)+\\)\\]\\(\\(?:.\\|\n\\)\\)*\\'"
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 string)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 (setq string (concat "]" (match-string 1 string)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 (match-string 2 string))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (when (string-match "\\`^\\(\\(?:.\\|\n\\)+\\)\\'" string)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 (setq string (concat (substring string 1) "^")))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 string)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (defun rx-check-any (arg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 "Check arg ARG for Rx `any'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (cond ((integerp arg) t)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 ((and (stringp arg) (zerop (length arg)))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
317 (error "String arg for rx `any' must not be empty"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 ((stringp arg) t)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (t
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
320 (error "rx `any' requires string or character arg"))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (defun rx-any (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 "Parse and produce code from FORM, which is `(any STRING)'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 STRING is optional. If it is omitted, build a regexp that
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 matches anything."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (let ((arg (cadr form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (cond ((integerp arg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (char-to-string arg))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 ((= (length arg) 1)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 arg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (concat "[" (rx-quote-for-set (cadr form)) "]")))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
337 (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
338 "Check arg ARG for Rx `not'."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (unless (or (memq form
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 '(digit control hex-digit blank graphic printing
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 alphanumeric letter ascii nonascii lower
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 punctuation space upper word))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (and (consp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 (memq (car form) '(not any in syntax category:))))
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
345 (error "rx `not' syntax error: %s" form))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 t)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 (defun rx-not (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 "Parse and produce code from FORM. FORM is `(not ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (rx-check form)
53974
818e19ae4c5a (rx-not): Bind case-fold-search to nil.
Eli Zaretskii <eliz@is.elta.co.il>
parents: 52971
diff changeset
352 (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
353 case-fold-search)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (cond ((string-match "\\`\\[^" result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (if (= (length result) 4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (substring result 2 3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (concat "[" (substring result 2))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 ((string-match "\\`\\[" result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (concat "[^" (substring result 1)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 ((string-match "\\`\\\\s." result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (concat "\\S" (substring result 2)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 ((string-match "\\`\\\\S." result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 (concat "\\s" (substring result 2)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 ((string-match "\\`\\\\c." result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 (concat "\\C" (substring result 2)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 ((string-match "\\`\\\\C." result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 (concat "\\c" (substring result 2)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 ((string-match "\\`\\\\B" result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (concat "\\b" (substring result 2)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 ((string-match "\\`\\\\b" result)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 (concat "\\B" (substring result 2)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (concat "[^" result "]")))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (defun rx-repeat (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 FORM is either `(repeat N FORM1)' or `(repeat N M FORM1)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (cond ((= (length form) 3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (unless (and (integerp (nth 1 form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (> (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
383 (error "rx `repeat' requires positive integer first arg"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (format "%s\\{%d\\}" (rx-to-string (nth 2 form)) (nth 1 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 ((or (not (integerp (nth 2 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (< (nth 2 form) 0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (not (integerp (nth 1 form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (< (nth 1 form) 0)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (< (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
390 (error "rx `repeat' range error"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (t
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (format "%s\\{%d,%d\\}" (rx-to-string (nth 3 form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 (nth 1 form) (nth 2 form)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (defun rx-submatch (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 "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
398 (concat "\\("
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
399 (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
400 (cdr form) nil)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
401 "\\)"))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
403 (defun rx-backref (form)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
404 "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
405 (rx-check form)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
406 (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
407
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
408 (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
409 "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
410 (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
411 (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
412
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (defun rx-kleene (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 "Parse and produce code from FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 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
416 `zero-or-more' etc. operators.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 If OP is one of `*', `+', `?', produce a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 If OP is one of `*?', `+?', `??', produce a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 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
420 is non-nil."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 (let ((suffix (cond ((memq (car form) '(* + ? )) "")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 ((memq (car form) '(*? +? ??)) "?")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (rx-greedy-flag "")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (t "?")))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (op (cond ((memq (car form) '(* *? 0+ zero-or-more)) "*")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 ((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
428 (t "?")))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
429 (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
430 (if (not (rx-atomic-p result))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
431 (setq result (concat "\\(?:" result "\\)")))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
432 (concat result op suffix)))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
433
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
434 (defun rx-atomic-p (r)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
435 "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
436 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
437 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
438 \"[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
439 \"[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
440
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
441 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
442 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
443 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
444 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
445 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
446 detects the following categories of atomic regexp;
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
447
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
448 a group or shy group: \\(...\\)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
449 a character class: [...]
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
450 a single character: a
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
451
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
452 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
453 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
454 \"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
455 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
456 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
457 of all atomic regexps."
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
458 (let ((l (length r)))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
459 (or (equal l 1)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
460 (and (>= l 6)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
461 (equal (substring r 0 2) "\\(")
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
462 (equal (substring r -2) "\\)"))
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
463 (and (>= l 2)
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
464 (equal (substring r 0 1) "[")
05f00479612c (rx-and): Generate a shy group.
Richard M. Stallman <rms@gnu.org>
parents: 47257
diff changeset
465 (equal (substring r -1) "]")))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 (defun rx-syntax (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 "Parse and produce code from FORM, which is `(syntax SYMBOL)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 (let ((syntax (assq (cadr form) rx-syntax)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (unless syntax
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (error "Unknown rx syntax `%s'" (cadr form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 (format "\\s%c" (cdr syntax))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477 (defun rx-check-category (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 "Check the argument FORM of a `(category FORM)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (unless (or (integerp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 (cdr (assq form rx-categories)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (error "Unknown category `%s'" form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 t)
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
483
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (defun rx-category (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 "Parse and produce code from FORM, which is `(category SYMBOL ...)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (let ((char (if (integerp (cadr form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (cadr form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (cdr (assq (cadr form) rx-categories)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (format "\\c%c" char)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (defun rx-eval (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 "Parse and produce code from FORM, which is `(eval FORM)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
496 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (rx-to-string (eval (cadr form))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (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
501 "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
502 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
503 `+', 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
504 '(maximal-match FORM1)', greedy operators will be used."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (let ((rx-greedy-flag (eq (car form) 'maximal-match)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 (rx-to-string (cadr form))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 (defun rx-regexp (form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 "Parse and produce code from FORM, which is `(regexp STRING)'."
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 (rx-check form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (concat "\\(?:" (cadr form) "\\)"))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 ;;;###autoload
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 (defun rx-to-string (form &optional no-group)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 "Parse and produce code for regular expression FORM.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 FORM is a regular expression in sexp form.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 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
521 (cond ((stringp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 (regexp-quote form))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 ((integerp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 (regexp-quote (char-to-string form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
525 ((symbolp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (let ((info (rx-info form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (cond ((stringp info)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 info)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 ((null info)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
530 (error "Unknown rx form `%s'" form))
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
531 (t
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 (funcall (nth 0 info) form)))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 ((consp form)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (let ((info (rx-info (car form))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (unless (consp info)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
536 (error "Unknown rx form `%s'" (car form)))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (let ((result (funcall (nth 0 info) form)))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 (if (or no-group (string-match "\\`\\\\[(]" result))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 result
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (concat "\\(?:" result "\\)")))))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 (t
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
542 (error "rx syntax error at `%s'" form))))
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 ;;;###autoload
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (defmacro rx (regexp)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 "Translate a regular expression REGEXP in sexp form to a regexp string.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 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
549
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 The following are valid subforms of regular expressions in sexp
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 notation.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 STRING
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 matches string STRING literally.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 CHAR
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 matches character CHAR literally.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 `not-newline'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 matches any character except a newline.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 .
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 `anything'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 matches any character
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 `(any SET)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 matches any character in SET. SET may be a character or string.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 Ranges of characters can be specified as `A-Z' in strings.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
569 '(in SET)'
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 like `any'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 `(not (any SET))'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 matches any character not in SET
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 `line-start'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 matches the empty string, but only at the beginning of a line
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 in the text being matched
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 `line-end'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 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
581
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 `string-start'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 matches the empty string, but only at the beginning of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 string being matched against.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 `string-end'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 matches the empty string, but only at the end of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588 string being matched against.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 `buffer-start'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 matches the empty string, but only at the beginning of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 buffer being matched against.
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 `buffer-end'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 matches the empty string, but only at the end of the
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 buffer being matched against.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 `point'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 matches the empty string, but only at point.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 `word-start'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 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
603 word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
605 `word-end'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 matches the empty string, but only at the end of a word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 `word-boundary'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609 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
610 word.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 `(not word-boundary)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 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
614 word.
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 `digit'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617 matches 0 through 9.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 `control'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620 matches ASCII control characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
621
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 `hex-digit'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 matches 0 through 9, a through f and A through F.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 `blank'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 matches space and tab only.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 `graphic'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 matches graphic characters--everything except ASCII control chars,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 space, and DEL.
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 `printing'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 matches printing characters--everything except ASCII control chars
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 and DEL.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 `alphanumeric'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 matches letters and digits. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 it matches anything that has word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 `letter'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 matches letters. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 it matches anything that has word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 `ascii'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 matches ASCII (unibyte) characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 `nonascii'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 matches non-ASCII (multibyte) characters.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 `lower'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 matches anything lower-case.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 `upper'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 matches anything upper-case.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 `punctuation'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 matches punctuation. (But at present, for multibyte characters,
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 it matches anything that has non-word syntax.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 `space'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 matches anything that has whitespace syntax.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 `word'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 matches anything that has word syntax.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
665
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
666 `(syntax SYNTAX)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 matches a character with syntax SYNTAX. SYNTAX must be one
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 of the following symbols.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 `whitespace' (\\s- in string notation)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 `punctuation' (\\s.)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 `word' (\\sw)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673 `symbol' (\\s_)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 `open-parenthesis' (\\s()
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 `close-parenthesis' (\\s))
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676 `expression-prefix' (\\s')
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 `string-quote' (\\s\")
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 `paired-delimiter' (\\s$)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 `escape' (\\s\\)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 `character-quote' (\\s/)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 `comment-start' (\\s<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682 `comment-end' (\\s>)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
683 `string-delimiter' (\\s|)
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
684 `comment-delimiter' (\\s!)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
686 `(not (syntax SYNTAX))'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
687 matches a character that has not syntax SYNTAX.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
688
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
689 `(category CATEGORY)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
690 matches a character with category CATEGORY. CATEGORY must be
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
691 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
692
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
693 `consonant' (\\c0 in string notation)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694 `base-vowel' (\\c1)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
695 `upper-diacritical-mark' (\\c2)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
696 `lower-diacritical-mark' (\\c3)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
697 `tone-mark' (\\c4)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 `symbol' (\\c5)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
699 `digit' (\\c6)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
700 `vowel-modifying-diacritical-mark' (\\c7)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
701 `vowel-sign' (\\c8)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702 `semivowel-lower' (\\c9)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
703 `not-at-end-of-line' (\\c<)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 `not-at-beginning-of-line' (\\c>)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 `alpha-numeric-two-byte' (\\cA)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
706 `chinse-two-byte' (\\cC)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 `greek-two-byte' (\\cG)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
708 `japanese-hiragana-two-byte' (\\cH)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
709 `indian-tow-byte' (\\cI)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
710 `japanese-katakana-two-byte' (\\cK)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 `korean-hangul-two-byte' (\\cN)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
712 `cyrillic-two-byte' (\\cY)
53992
c5c237251824 (rx-check, rx-check-any, rx-check-not)
Eli Zaretskii <eliz@is.elta.co.il>
parents: 53974
diff changeset
713 `combining-diacritic' (\\c^)
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
714 `ascii' (\\ca)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
715 `arabic' (\\cb)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
716 `chinese' (\\cc)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
717 `ethiopic' (\\ce)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
718 `greek' (\\cg)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
719 `korean' (\\ch)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
720 `indian' (\\ci)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
721 `japanese' (\\cj)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
722 `japanese-katakana' (\\ck)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
723 `latin' (\\cl)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
724 `lao' (\\co)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
725 `tibetan' (\\cq)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
726 `japanese-roman' (\\cr)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
727 `thai' (\\ct)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
728 `vietnamese' (\\cv)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
729 `hebrew' (\\cw)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
730 `cyrillic' (\\cy)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 `can-break' (\\c|)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
732
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
733 `(not (category CATEGORY))'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734 matches a character that has not category CATEGORY.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
735
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
736 `(and SEXP1 SEXP2 ...)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 matches what SEXP1 matches, followed by what SEXP2 matches, etc.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
738
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739 `(submatch SEXP1 SEXP2 ...)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
740 like `and', but makes the match accessible with `match-end',
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
741 `match-beginning', and `match-string'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
743 `(group SEXP1 SEXP2 ...)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 another name for `submatch'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
746 `(or SEXP1 SEXP2 ...)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747 matches anything that matches SEXP1 or SEXP2, etc. If all
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748 args are strings, use `regexp-opt' to optimize the resulting
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
749 regular expression.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
750
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
751 `(minimal-match SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
752 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
753 zero or more occurrences of something are \"greedy\" in that they
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
754 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
755 still match. A non-greedy regexp matches as little as possible.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
756
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
757 `(maximal-match SEXP)'
47257
14ef33c0a704 (rx): Fix spacing.
Juanma Barranquero <lekktu@gmail.com>
parents: 39516
diff changeset
758 produce a greedy regexp for SEXP. This is the default.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
759
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
760 `(zero-or-more SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
761 matches zero or more occurrences of what SEXP matches.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
762
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763 `(0+ SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
764 like `zero-or-more'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
765
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
766 `(* SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
767 like `zero-or-more', but always produces a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
768
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
769 `(*? SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
770 like `zero-or-more', but always produces a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
771
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
772 `(one-or-more SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
773 matches one or more occurrences of A.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
774
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
775 `(1+ SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
776 like `one-or-more'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
777
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
778 `(+ SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
779 like `one-or-more', but always produces a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
780
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
781 `(+? SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
782 like `one-or-more', but always produces a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
783
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
784 `(zero-or-one SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
785 matches zero or one occurrences of A.
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48938
diff changeset
786
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
787 `(optional SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
788 like `zero-or-one'.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
789
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
790 `(? SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
791 like `zero-or-one', but always produces a greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
792
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
793 `(?? SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
794 like `zero-or-one', but always produces a non-greedy regexp.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
795
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
796 `(repeat N SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
797 matches N occurrences of what SEXP matches.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
798
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
799 `(repeat N M SEXP)'
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
800 matches N to M occurrences of what SEXP matches.
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
801
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
802 `(backref N)'
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
803 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
804
54601
d2d20534e329 (rx): Work at compile time, not run time.
Eli Zaretskii <eliz@gnu.org>
parents: 54503
diff changeset
805 `(backref N)'
d2d20534e329 (rx): Work at compile time, not run time.
Eli Zaretskii <eliz@gnu.org>
parents: 54503
diff changeset
806 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
807
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
808 `(eval FORM)'
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
809 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
810 `regexp-quote' it.
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
811
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
812 `(regexp REGEXP)'
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
813 include REGEXP in string notation in the result."
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
814
54461
5c8be4779a36 (rx): Work at compile time, not run time.
Juanma Barranquero <lekktu@gmail.com>
parents: 53992
diff changeset
815 (rx-to-string regexp))
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 (provide 'rx)
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
818
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49598
diff changeset
819 ;;; arch-tag: 12d01a63-0008-42bb-ab8c-1c7d63be370b
39516
9160fa3bfe4b *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
820 ;;; rx.el ends here