• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /macosx-10.10.1/emacs-93/emacs/lisp/emacs-lisp/

Lines Matching defs:regexp

0 ;;; regexp-opt.el --- generate efficient regexps to match strings
29 ;; The "opt" in "regexp-opt" stands for "optim\\(al\\|i[sz]e\\)".
31 ;; This package generates a regexp from a given list of strings (which matches
32 ;; one of those strings) so that the regexp generated by:
34 ;; (regexp-opt strings)
36 ;; is equivalent to, but more efficient than, the regexp generated by:
38 ;; (mapconcat 'regexp-quote strings "\\|")
47 ;; (concat "(" (regexp-opt strings t) "\\>"))
50 ;; Searching using the above example `regexp-opt' regexp takes approximately
51 ;; two-thirds of the time taken using the equivalent `mapconcat' regexp.
57 ;; (defvar definition-regexp
60 ;; (regexp-opt '("defun" "defsubst" "defmacro" "defalias"
66 ;; (defvar definition-regexp
69 ;; Note that if you use this trick for all instances of `regexp-opt' and
70 ;; `regexp-opt-depth' in your code, regexp-opt.el would only have to be loaded
72 ;; regexp-opt.el be changed, perhaps to fix a bug or to add a feature to
73 ;; improve the efficiency of `regexp-opt' regexps, you would have to recompile
79 ;; No doubt `regexp-opt' doesn't always produce optimal regexps, so code, ideas
91 (defun regexp-opt (strings &optional paren)
92 "Return a regexp to match a string in the list STRINGS.
94 quoted or not. If optional PAREN is non-nil, ensure that the returned regexp
95 is enclosed by at least one regexp grouping construct.
96 The returned regexp is typically more efficient than the equivalent regexp:
99 (concat open (mapconcat 'regexp-quote STRINGS \"\\\\|\") close))
101 If PAREN is `words', then the resulting regexp is additionally surrounded
108 (completion-regexp-list nil)
113 (re (regexp-opt-group sorted-strings open)))
117 (defun regexp-opt-depth (regexp)
119 This means the number of non-shy regexp grouping constructs
123 (string-match regexp "")
126 (while (string-match "\\\\(\\(\\?:\\)?" regexp start)
129 (subregexp-context-p regexp (match-beginning 0) last))
132 (setq last start) ; Speed up next regexp-opt-re-context-p.
142 (defun regexp-opt-group (strings &optional paren lax)
143 ;; Return a regexp to match a string in the sorted list STRINGS.
144 ;; If PAREN non-nil, output regexp parentheses around returned regexp.
146 ;; Merges keywords to avoid backtracking in Emacs' regexp matcher.
168 (concat open-charset (regexp-quote (car strings)) close-charset)
169 (concat open-group (regexp-quote (car strings)) close-group)))
174 (regexp-opt-group (cdr strings) t t) "?"
192 (regexp-opt-group (nreverse rest))
193 "\\|" (regexp-opt-charset letters)
197 (regexp-opt-charset letters)
208 (regexp-quote prefix)
209 (regexp-opt-group suffixes t t)
224 (regexp-opt-group prefixes t t)
225 (regexp-quote
235 (regexp-opt-group half1)
236 "\\|" (regexp-opt-group half2)
240 (defun regexp-opt-charset (chars)
242 ;; Return a regexp to match a character in CHARS.
245 ;; position of character set meta characters in the character set regexp.
288 (provide 'regexp-opt)
291 ;;; regexp-opt.el ends here