From 59b2ee6929bad652fab10c85addc02e7394b1bf6 Mon Sep 17 00:00:00 2001 From: Juanma Barranquero Date: Sat, 26 Apr 2003 23:29:45 +0000 Subject: [PATCH] (regexp-opt-depth): Don't count a "//(" which appears inside a character set. (regexp-opt-not-groupie*-re): New constant. --- lisp/ChangeLog | 6 ++++++ lisp/emacs-lisp/regexp-opt.el | 29 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e04771d2188..f69e562a898 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2003-04-27 Alan Mackenzie + + * emacs-lisp/regexp-opt.el (regexp-opt-depth): Don't count a "//(" + which appears inside a character set. + (regexp-opt-not-groupie*-re): New constant. + 2003-04-26 John Paul Wallington * ibuffer.el (ibuffer-name-map, ibuffer-mode-name-map) diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el index 486cf006e4b..11a66aa2a14 100644 --- a/lisp/emacs-lisp/regexp-opt.el +++ b/lisp/emacs-lisp/regexp-opt.el @@ -110,6 +110,24 @@ by \\=\\< and \\>." (re (regexp-opt-group sorted-strings open))) (if words (concat "\\<" re "\\>") re)))) +(defconst regexp-opt-not-groupie*-re + (let* ((harmless-ch "[^\\\\[]") + (esc-pair-not-lp "\\\\[^(]") + (class-harmless-ch "[^][]") + (class-lb-harmless "[^]:]") + (class-lb-colon-maybe-charclass ":\\([a-z]+:]\\)?") + (class-lb (concat "\\[\\(" class-lb-harmless + "\\|" class-lb-colon-maybe-charclass "\\)")) + (class + (concat "\\[^?]?" + "\\(" class-harmless-ch + "\\|" class-lb "\\)*" + "\\[?]")) ; special handling for bare [ at end of re + (shy-lp "\\\\(\\?:")) + (concat "\\(" harmless-ch "\\|" esc-pair-not-lp + "\\|" class "\\|" shy-lp "\\)*")) + "Matches any part of a regular expression EXCEPT for non-shy \"\\\\(\"s") + ;;;###autoload (defun regexp-opt-depth (regexp) "Return the depth of REGEXP. @@ -120,11 +138,12 @@ in REGEXP." (string-match regexp "") ;; Count the number of open parentheses in REGEXP. (let ((count 0) start) - (while (string-match "\\(\\`\\|[^\\]\\)\\\\\\(\\\\\\\\\\)*([^?]" - regexp start) - (setq count (1+ count) - ;; Go back 2 chars (one for [^?] and one for [^\\]). - start (- (match-end 0) 2))) + (while + (progn + (string-match regexp-opt-not-groupie*-re regexp start) + (setq start ( + (match-end 0) 2)) ; +2 for "\\(" after match-end. + (<= start (length regexp))) + (setq count (1+ count))) count))) ;;; Workhorse functions. -- 2.11.4.GIT