Mercurial > hg > xemacs-beta
diff man/lispref/searching.texi @ 316:512e409c26a2 r21-0b56
Import from CVS: tag r21-0b56
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:44:46 +0200 |
parents | 341dac730539 |
children | a4f53d9b3154 |
line wrap: on
line diff
--- a/man/lispref/searching.texi Mon Aug 13 10:44:26 2007 +0200 +++ b/man/lispref/searching.texi Mon Aug 13 10:44:46 2007 +0200 @@ -277,7 +277,7 @@ This construct is very useful for when you want to match the text inside a pair of delimiters. For instance, @samp{/\*.*?\*/} will match C comments in a string. This could not be so elegantly achieved without -the use of a nongreedy quantifier. +the use of a non-greedy quantifier. This construct has not been available prior to XEmacs 20.4. It is not available in FSF Emacs. @@ -465,59 +465,67 @@ This is useful when you need to use a lot of nested grouping @samp{\( @dots{} \)} constructs to express complex alternation, but only want to memoize, or capture, one or two of the subexpression matches. Since -@samp{\(?: @dots{} \)} doesn't capture a submatch, it also doesn't need +@samp{\(?: @dots{} \)} doesn't capture a sub-match, it also doesn't need to be counted when you count @samp{\( @dots{} \)} groups to figure the @samp{match-string} index. That turns out to be a very convenient characteristic. -This situtation occurs where parts of a regular expression have been +This situation occurs where parts of a regular expression have been automaticly generated by a program that builds them from lists of strings, and the static code following the matching operation must -access a specific match number. Here's an example that shows this: +access a specific match number. Here's an example that shows this. + +We will assume that @code{(require 'regexp-opt)} has been executed +already, to ensure that @file{regexp-opt.el}, which is part of the +@code{xemacs-devel} package, is loaded. +@ifinfo +Please evaluate that @code{require} expression now, using @kbd{C-x C-e}, +if you intend to try the following example. +@end ifinfo +In a real program, lets pretend that @var{varnames} would be a list of +strings holding the names of some variables extracted somehow from the +text of a program source you are editing and running this function on. +For the purposes of this illustration, we can just bind it in the +@code{let*} expression. @example @group -;; Assume that: -(require 'regexp-opt) ;; gets executed at toplevel -;;; `regexp-opt.el' is part of the "xemacs-devel" package. -;; ... and that VARNAMES is a list of strings holding the name of some -;; variables extracted from the program source you are editting and -;; running this function on. For this example, it will just be bound -;; in the let* expression. (let* ((varnames '("k" "n" "i" "j" "varname")) (keys-regexp (regexp-opt - (mapcar #'symbol-name - '(if then else elif - case in of do while - with for next unless - cond begin end)))) + (mapcar #'symbol-name + '(if then else elif + case in of do while + with for next unless + cond begin end)))) (varname-regexp (regexp-opt varnames)) (contrived-regexp (concat "\\(" keys-regexp "\\)" - "\\s-(\\s-\\(" - varname-regexp - "\\)\\s-)")) + "\\s-(\\s-\\(" + varname-regexp + "\\)\\s-)")) (keyname "") (varname "")) - ;; In the body of this particular defun, we: + ;; @r{In the body of this particular defun, we:} (re-search-forward contrived-regexp nil t) - ;; ... and it finds a match. Now we want to extract the text that - ;; it matched on, and save it into KEYNAME and VARNAME. + ;; @r{@dots{} and it finds a match. Now we want to extract the} + ;; @r{text that it matched on, and save it into @code{keyname}} + ;; @r{and @code{varname}.} (setq keyname (match-string 1) - varname (match-string 2)) - ;; ... and then do something with those values. + varname (match-string 2)) + ;; @r{@dots{} and then do something with those values.} (list keyname varname)) -;; Here's something for it to match, so you can try it with `C-x C-e'. +;; @r{Here's something for it to match, so you can try it with} +;; @kbd{C-x C-e} ;; while ( j ) do ... @end group @end example -Here you can see that if the regular expression returned by -@samp{regexp-opt} did not use @samp{\(?: @dots{} \)} for grouping, and +Here you should see that if the regular expression returned by +@code{regexp-opt} did not use @samp{\(?: @dots{} \)} for grouping, and instead used @samp{\( @dots{} \)}, it would be necessary to count the -number of opening parentheses in the @samp{keys-regexp} and to use that +number of opening parentheses in the @code{keys-regexp} and to use that figure to calculate which match number is matched by the -@code{varname-regexp}. It is much more convienient to be able to just +@code{varname-regexp}. It is much more convenient to be able to just ask for the second match string. @c This is used to good advantage by the font-locking code.... @@ -1145,7 +1153,7 @@ If @var{count} is zero, then the value is the position of the start of the entire match. Otherwise, @var{count} specifies a subexpression in -the regular expresion, and the value of the function is the starting +the regular expression, and the value of the function is the starting position of the match for that subexpression. The value is @code{nil} for a subexpression inside a @samp{\|}