* lisp/emacs-lisp/rx.el: Make it a superset of sregex.

(rx-constituents): Add `any => "."', mark `repeat' as taking any number
of args, add `regex' alias.
(rx-info): Add arg to distinguish head and standalone forms.
(rx-check, rx-form): Pass the corresponding arg.
(rx-**): Simplify.
(rx-repeat): Make it work for any number of args.
(rx-syntax): Make it accept syntax chars as is.
* lisp/obsolete/sregex.el: Move from emacs-lisp/.
* lisp/emacs-lisp/re-builder.el: Remove sregex support.
* lisp/emacs-lisp/edebug.el (sregexq, rx): Remove redundant defs.
This commit is contained in:
Stefan Monnier 2010-12-26 18:17:09 -05:00
parent e77714da30
commit 723ee192a5
6 changed files with 64 additions and 37 deletions

View file

@ -541,6 +541,8 @@ listing object name completions when being sent text via
*** An API for manipulating SQL product definitions has been added.
** sregex.el is now obsolete, since rx.el is a strict superset.
** s-region.el is now declared obsolete, superceded by shift-select-mode
enabled by default in 23.1.

View file

@ -1,3 +1,17 @@
2010-12-26 Stefan Monnier <monnier@iro.umontreal.ca>
* emacs-lisp/rx.el: Make it a superset of sregex.
(rx-constituents): Add `any => "."', mark `repeat' as taking any number
of args, add `regex' alias.
(rx-info): Add arg to distinguish head and standalone forms.
(rx-check, rx-form): Pass the corresponding arg.
(rx-**): Simplify.
(rx-repeat): Make it work for any number of args.
(rx-syntax): Make it accept syntax chars as is.
* obsolete/sregex.el: Move from emacs-lisp/.
* emacs-lisp/re-builder.el: Remove sregex support.
* emacs-lisp/edebug.el (sregexq, rx): Remove redundant defs.
2010-12-25 Eli Zaretskii <eliz@gnu.org>
* mouse.el (mouse-yank-primary): On MS-Windows, try the (emulated)
@ -19,8 +33,8 @@
2010-12-21 Daiki Ueno <ueno@unixuser.org>
* obsolete/pgg-parse.el, obsolete/pgg-pgp5.el, obsolete/pgg-pgp.el,
* obsolete/pgg-gpg.el, obsolete/pgg-def.el, obsolete/pgg.el: Move
from lisp/.
* obsolete/pgg-gpg.el, obsolete/pgg-def.el, obsolete/pgg.el:
Move from lisp/.
2010-12-20 Leo <sdl.web@gmail.com>

View file

@ -2131,8 +2131,6 @@ expressions; a `progn' form will be returned enclosing these forms."
(def-edebug-spec with-custom-print body)
(def-edebug-spec sregexq (&rest sexp))
(def-edebug-spec rx (&rest sexp))
;;; The debugger itself

View file

@ -60,8 +60,8 @@
;; even the auto updates go all the way. Forcing an update overrides
;; this limit allowing an easy way to see all matches.
;; Currently `re-builder' understands five different forms of input,
;; namely `read', `string', `rx', and `sregex' syntax. Read
;; Currently `re-builder' understands three different forms of input,
;; namely `read', `string', and `rx' syntax. Read
;; syntax and string syntax are both delimited by `"'s and behave
;; according to their name. With the `string' syntax there's no need
;; to escape the backslashes and double quotes simplifying the editing
@ -75,7 +75,7 @@
;; When editing a symbolic regular expression, only the first
;; expression in the RE Builder buffer is considered, which helps
;; limiting the extent of the expression like the `"'s do for the text
;; modes. For the `sregex' syntax the function `sregex' is applied to
;; modes. For the `rx' syntax the function `rx-to-string' is applied to
;; the evaluated expression read. So you can use quoted arguments
;; with something like '("findme") or you can construct arguments to
;; your hearts delight with a valid ELisp expression. (The compiled
@ -126,11 +126,10 @@
(defcustom reb-re-syntax 'read
"Syntax for the REs in the RE Builder.
Can either be `read', `string', `sregex', or `rx'."
Can either be `read', `string', or `rx'."
:group 're-builder
:type '(choice (const :tag "Read syntax" read)
(const :tag "String syntax" string)
(const :tag "`sregex' syntax" sregex)
(const :tag "`rx' syntax" rx)))
(defcustom reb-auto-match-limit 200
@ -279,10 +278,8 @@ Except for Lisp syntax this is the same as `reb-regexp'.")
emacs-lisp-mode "RE Builder Lisp"
"Major mode for interactively building symbolic Regular Expressions."
;; Pull in packages as needed
(cond ((eq reb-re-syntax 'sregex) ; sregex is not autoloaded
(require 'sregex)) ; right now..
((eq reb-re-syntax 'rx) ; rx-to-string is autoloaded
(require 'rx))) ; require rx anyway
(cond ((memq reb-re-syntax '(sregex rx)) ; rx-to-string is autoloaded
(require 'rx))) ; require rx anyway
(reb-mode-common))
;; Use the same "\C-c" keymap as `reb-mode' and use font-locking from
@ -612,9 +609,7 @@ optional fourth argument FORCE is non-nil."
(defun reb-cook-regexp (re)
"Return RE after processing it according to `reb-re-syntax'."
(cond ((eq reb-re-syntax 'sregex)
(apply 'sregex (eval (car (read-from-string re)))))
((eq reb-re-syntax 'rx)
(cond ((memq reb-re-syntax '(sregex rx))
(rx-to-string (eval (car (read-from-string re)))))
(t re)))

View file

@ -120,19 +120,17 @@
(nonl . not-newline) ; SRE
(anything . (rx-anything 0 nil))
(any . (rx-any 1 nil rx-check-any)) ; inconsistent with SRE
(any . ".") ; sregex
(in . any)
(char . any) ; sregex
(not-char . (rx-not-char 1 nil rx-check-any)) ; sregex
(not . (rx-not 1 1 rx-check-not))
;; Partially consistent with sregex, whose `repeat' is like our
;; `**'. (`repeat' with optional max arg and multiple sexp forms
;; is ambiguous.)
(repeat . (rx-repeat 2 3))
(repeat . (rx-repeat 2 nil))
(= . (rx-= 2 nil)) ; SRE
(>= . (rx->= 2 nil)) ; SRE
(** . (rx-** 2 nil)) ; SRE
(submatch . (rx-submatch 1 nil)) ; SRE
(group . submatch)
(group . submatch) ; sregex
(zero-or-more . (rx-kleene 1 nil))
(one-or-more . (rx-kleene 1 nil))
(zero-or-one . (rx-kleene 1 nil))
@ -175,6 +173,7 @@
(category . (rx-category 1 1 rx-check-category))
(eval . (rx-eval 1 1))
(regexp . (rx-regexp 1 1 stringp))
(regex . regexp) ; sregex
(digit . "[[:digit:]]")
(numeric . digit) ; SRE
(num . digit) ; SRE
@ -295,15 +294,27 @@ regular expression strings.")
`zero-or-more', and `one-or-more'. Dynamically bound.")
(defun rx-info (op)
(defun rx-info (op head)
"Return parsing/code generation info for OP.
If OP is the space character ASCII 32, return info for the symbol `?'.
If OP is the character `?', return info for the symbol `??'.
See also `rx-constituents'."
See also `rx-constituents'.
If HEAD is non-nil, then OP is the head of a sexp, otherwise it's
a standalone symbol."
(cond ((eq op ? ) (setq op '\?))
((eq op ??) (setq op '\??)))
(while (and (not (null op)) (symbolp op))
(setq op (cdr (assq op rx-constituents))))
(let (old-op)
(while (and (not (null op)) (symbolp op))
(setq old-op op)
(setq op (cdr (assq op rx-constituents)))
(when (if head (stringp op) (consp op))
;; We found something but of the wrong kind. Let's look for an
;; alternate definition for the other case.
(let ((new-op
(cdr (assq old-op (cdr (memq (assq old-op rx-constituents)
rx-constituents))))))
(if (and new-op (not (if head (stringp new-op) (consp new-op))))
(setq op new-op))))))
op)
@ -311,7 +322,7 @@ See also `rx-constituents'."
"Check FORM according to its car's parsing info."
(unless (listp form)
(error "rx `%s' needs argument(s)" form))
(let* ((rx (rx-info (car form)))
(let* ((rx (rx-info (car form) 'head))
(nargs (1- (length form)))
(min-args (nth 1 rx))
(max-args (nth 2 rx))
@ -643,14 +654,17 @@ If SKIP is non-nil, allow that number of items after the head, i.e.
(defun rx-** (form)
"Parse and produce code from FORM `(** N M ...)'."
(rx-check form)
(setq form (cons 'repeat (cdr (rx-trans-forms form 2))))
(rx-form form '*))
(rx-form (cons 'repeat (cdr (rx-trans-forms form 2))) '*))
(defun rx-repeat (form)
"Parse and produce code from FORM.
FORM is either `(repeat N FORM1)' or `(repeat N M FORM1)'."
FORM is either `(repeat N FORM1)' or `(repeat N M FORMS...)'."
(rx-check form)
(if (> (length form) 4)
(setq form (rx-trans-forms form 2)))
(if (null (nth 2 form))
(setq form (list* (nth 0 form) (nth 1 form) (nthcdr 3 form))))
(cond ((= (length form) 3)
(unless (and (integerp (nth 1 form))
(> (nth 1 form) 0))
@ -749,15 +763,18 @@ of all atomic regexps."
"Parse and produce code from FORM, which is `(syntax SYMBOL)'."
(rx-check form)
(let* ((sym (cadr form))
(syntax (assq sym rx-syntax)))
(syntax (cdr (assq sym rx-syntax))))
(unless syntax
;; Try sregex compatibility.
(let ((name (symbol-name sym)))
(if (= 1 (length name))
(setq syntax (rassq (aref name 0) rx-syntax))))
(cond
((character sym) (setq syntax sym))
((symbolp sym)
(let ((name (symbol-name sym)))
(if (= 1 (length name))
(setq syntax (aref name 0))))))
(unless syntax
(error "Unknown rx syntax `%s'" (cadr form))))
(format "\\s%c" (cdr syntax))))
(error "Unknown rx syntax `%s'" sym)))
(format "\\s%c" syntax)))
(defun rx-check-category (form)
@ -811,7 +828,7 @@ shy groups around the result and some more in other functions."
(cond ((integerp form)
(regexp-quote (char-to-string form)))
((symbolp form)
(let ((info (rx-info form)))
(let ((info (rx-info form nil)))
(cond ((stringp info)
info)
((null info)
@ -819,7 +836,7 @@ shy groups around the result and some more in other functions."
(t
(funcall (nth 0 info) form)))))
((consp form)
(let ((info (rx-info (car form))))
(let ((info (rx-info (car form) 'head)))
(unless (consp info)
(error "Unknown rx form `%s'" (car form)))
(funcall (nth 0 info) form)))

View file

@ -6,6 +6,7 @@
;; Author: Bob Glickstein <bobg+sregex@zanshin.com>
;; Maintainer: Bob Glickstein <bobg+sregex@zanshin.com>
;; Keywords: extensions
;; Obsolete-since: 24.1
;; This file is part of GNU Emacs.