annotate lisp/emacs-lisp/rx.el @ 52245:1f6577b47562

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