Mercurial > emacs
changeset 50713:645707022f8f
(regexp-opt-depth): Don't count a "//(" which appears inside a character set.
(regexp-opt-not-groupie*-re): New constant.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Sat, 26 Apr 2003 23:24:59 +0000 |
parents | e28c4c84cdf5 |
children | 6cd3d0fd5cf1 |
files | lisp/emacs-lisp/regexp-opt.el |
diffstat | 1 files changed, 24 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/lisp/emacs-lisp/regexp-opt.el Sat Apr 26 09:02:00 2003 +0000 +++ b/lisp/emacs-lisp/regexp-opt.el Sat Apr 26 23:24:59 2003 +0000 @@ -110,6 +110,24 @@ (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 @@ (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.