diff options
| author | Eli Zaretskii | 2004-02-16 16:51:39 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2004-02-16 16:51:39 +0000 |
| commit | 740b7c2dbb94f18c3dc1f5dfde6b72211d7e03c1 (patch) | |
| tree | f1414e632738c0b8633cf59adf84db29046727df | |
| parent | fe088644a609a9319c53a0d221e63dc7c552d1f1 (diff) | |
| download | emacs-740b7c2dbb94f18c3dc1f5dfde6b72211d7e03c1.tar.gz emacs-740b7c2dbb94f18c3dc1f5dfde6b72211d7e03c1.zip | |
(rx-check, rx-check-any, rx-check-not)
(rx-repeat, rx-check-backref, rx-syntax, rx-to-string): Use
lower-case "rx" in all error message.
(rx-or): Put group around result.
(rx-constituents): Add backref.
(rx-syntax): Add string-delimiter, comment-delimiter.
(rx-categories): Add combining-diacritic.
(rx-check-not, rx-greedy, rx): Doc fix.
(rx-backref, rx-check-backref): New.
| -rw-r--r-- | lisp/ChangeLog | 15 | ||||
| -rw-r--r-- | lisp/emacs-lisp/rx.el | 55 |
2 files changed, 51 insertions, 19 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a6bc343eced..f01e902bd1b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,18 @@ | |||
| 1 | 2004-02-16 Eli Zaretskii <eliz@elta.co.il> | ||
| 2 | |||
| 3 | * emacs-lisp/rx.el (rx-check, rx-check-any, rx-check-not) | ||
| 4 | (rx-repeat, rx-check-backref, rx-syntax, rx-to-string): Use | ||
| 5 | lower-case "rx" in all error message. | ||
| 6 | |||
| 7 | 2004-02-16 Dave Love <fx@gnu.org> | ||
| 8 | |||
| 9 | * emacs-lisp/rx.el (rx-or): Put group around result. | ||
| 10 | (rx-constituents): Add backref. | ||
| 11 | (rx-syntax): Add string-delimiter, comment-delimiter. | ||
| 12 | (rx-categories): Add combining-diacritic. | ||
| 13 | (rx-check-not, rx-greedy, rx): Doc fix. | ||
| 14 | (rx-backref, rx-check-backref): New. | ||
| 15 | |||
| 1 | 2004-02-16 Jesper Harder <harder@ifa.au.dk> | 16 | 2004-02-16 Jesper Harder <harder@ifa.au.dk> |
| 2 | 17 | ||
| 3 | * newcomment.el (uncomment-region): Allow eob as comment end. | 18 | * newcomment.el (uncomment-region): Allow eob as comment end. |
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index c6f9ce6f4a6..86673441fe7 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el | |||
| @@ -120,6 +120,7 @@ | |||
| 120 | (optional . zero-or-one) | 120 | (optional . zero-or-one) |
| 121 | (minimal-match . (rx-greedy 1 1)) | 121 | (minimal-match . (rx-greedy 1 1)) |
| 122 | (maximal-match . (rx-greedy 1 1)) | 122 | (maximal-match . (rx-greedy 1 1)) |
| 123 | (backref . (rx-backref 1 1 rx-check-backref)) | ||
| 123 | (line-start . "^") | 124 | (line-start . "^") |
| 124 | (line-end . "$") | 125 | (line-end . "$") |
| 125 | (string-start . "\\`") | 126 | (string-start . "\\`") |
| @@ -175,7 +176,9 @@ all arguments must satisfy PREDICATE.") | |||
| 175 | (escape . ?\\) | 176 | (escape . ?\\) |
| 176 | (character-quote . ?/) | 177 | (character-quote . ?/) |
| 177 | (comment-start . ?<) | 178 | (comment-start . ?<) |
| 178 | (comment-end . ?>)) | 179 | (comment-end . ?>) |
| 180 | (string-delimiter . ?|) | ||
| 181 | (comment-delimiter . ?!)) | ||
| 179 | "Alist mapping Rx syntax symbols to syntax characters. | 182 | "Alist mapping Rx syntax symbols to syntax characters. |
| 180 | Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid | 183 | Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid |
| 181 | symbol in `(syntax SYMBOL)', and CHAR is the syntax character | 184 | symbol in `(syntax SYMBOL)', and CHAR is the syntax character |
| @@ -204,6 +207,7 @@ regular expressions.") | |||
| 204 | (japanese-katakana-two-byte . ?K) | 207 | (japanese-katakana-two-byte . ?K) |
| 205 | (korean-hangul-two-byte . ?N) | 208 | (korean-hangul-two-byte . ?N) |
| 206 | (cyrillic-two-byte . ?Y) | 209 | (cyrillic-two-byte . ?Y) |
| 210 | (combining-diacritic . ?^) | ||
| 207 | (ascii . ?a) | 211 | (ascii . ?a) |
| 208 | (arabic . ?b) | 212 | (arabic . ?b) |
| 209 | (chinese . ?c) | 213 | (chinese . ?c) |
| @@ -255,16 +259,16 @@ See also `rx-constituents'." | |||
| 255 | (type-pred (nth 3 rx))) | 259 | (type-pred (nth 3 rx))) |
| 256 | (when (and (not (null min-args)) | 260 | (when (and (not (null min-args)) |
| 257 | (< nargs min-args)) | 261 | (< nargs min-args)) |
| 258 | (error "Rx form `%s' requires at least %d args" | 262 | (error "rx form `%s' requires at least %d args" |
| 259 | (car form) min-args)) | 263 | (car form) min-args)) |
| 260 | (when (and (not (null max-args)) | 264 | (when (and (not (null max-args)) |
| 261 | (> nargs max-args)) | 265 | (> nargs max-args)) |
| 262 | (error "Rx form `%s' accepts at most %d args" | 266 | (error "rx form `%s' accepts at most %d args" |
| 263 | (car form) max-args)) | 267 | (car form) max-args)) |
| 264 | (when (not (null type-pred)) | 268 | (when (not (null type-pred)) |
| 265 | (dolist (sub-form (cdr form)) | 269 | (dolist (sub-form (cdr form)) |
| 266 | (unless (funcall type-pred sub-form) | 270 | (unless (funcall type-pred sub-form) |
| 267 | (error "Rx form `%s' requires args satisfying `%s'" | 271 | (error "rx form `%s' requires args satisfying `%s'" |
| 268 | (car form) type-pred)))))) | 272 | (car form) type-pred)))))) |
| 269 | 273 | ||
| 270 | 274 | ||
| @@ -310,10 +314,10 @@ If STRING starts with a '^', move it to the end." | |||
| 310 | "Check arg ARG for Rx `any'." | 314 | "Check arg ARG for Rx `any'." |
| 311 | (cond ((integerp arg) t) | 315 | (cond ((integerp arg) t) |
| 312 | ((and (stringp arg) (zerop (length arg))) | 316 | ((and (stringp arg) (zerop (length arg))) |
| 313 | (error "String arg for Rx `any' must not be empty")) | 317 | (error "String arg for rx `any' must not be empty")) |
| 314 | ((stringp arg) t) | 318 | ((stringp arg) t) |
| 315 | (t | 319 | (t |
| 316 | (error "Rx `any' requires string or character arg")))) | 320 | (error "rx `any' requires string or character arg")))) |
| 317 | 321 | ||
| 318 | 322 | ||
| 319 | (defun rx-any (form) | 323 | (defun rx-any (form) |
| @@ -330,15 +334,15 @@ matches anything." | |||
| 330 | (concat "[" (rx-quote-for-set (cadr form)) "]"))))) | 334 | (concat "[" (rx-quote-for-set (cadr form)) "]"))))) |
| 331 | 335 | ||
| 332 | 336 | ||
| 333 | (defun rx-check-not (form) | 337 | (defun rx-check-not (arg) |
| 334 | "Check arguments of FORM. FORM is `(not ...)'." | 338 | "Check arg ARG for Rx `not'." |
| 335 | (unless (or (memq form | 339 | (unless (or (memq form |
| 336 | '(digit control hex-digit blank graphic printing | 340 | '(digit control hex-digit blank graphic printing |
| 337 | alphanumeric letter ascii nonascii lower | 341 | alphanumeric letter ascii nonascii lower |
| 338 | punctuation space upper word)) | 342 | punctuation space upper word)) |
| 339 | (and (consp form) | 343 | (and (consp form) |
| 340 | (memq (car form) '(not any in syntax category:)))) | 344 | (memq (car form) '(not any in syntax category:)))) |
| 341 | (error "Rx `not' syntax error: %s" form)) | 345 | (error "rx `not' syntax error: %s" form)) |
| 342 | t) | 346 | t) |
| 343 | 347 | ||
| 344 | 348 | ||
| @@ -376,14 +380,14 @@ FORM is either `(repeat N FORM1)' or `(repeat N M FORM1)'." | |||
| 376 | (cond ((= (length form) 3) | 380 | (cond ((= (length form) 3) |
| 377 | (unless (and (integerp (nth 1 form)) | 381 | (unless (and (integerp (nth 1 form)) |
| 378 | (> (nth 1 form) 0)) | 382 | (> (nth 1 form) 0)) |
| 379 | (error "Rx `repeat' requires positive integer first arg")) | 383 | (error "rx `repeat' requires positive integer first arg")) |
| 380 | (format "%s\\{%d\\}" (rx-to-string (nth 2 form)) (nth 1 form))) | 384 | (format "%s\\{%d\\}" (rx-to-string (nth 2 form)) (nth 1 form))) |
| 381 | ((or (not (integerp (nth 2 form))) | 385 | ((or (not (integerp (nth 2 form))) |
| 382 | (< (nth 2 form) 0) | 386 | (< (nth 2 form) 0) |
| 383 | (not (integerp (nth 1 form))) | 387 | (not (integerp (nth 1 form))) |
| 384 | (< (nth 1 form) 0) | 388 | (< (nth 1 form) 0) |
| 385 | (< (nth 2 form) (nth 1 form))) | 389 | (< (nth 2 form) (nth 1 form))) |
| 386 | (error "Rx `repeat' range error")) | 390 | (error "rx `repeat' range error")) |
| 387 | (t | 391 | (t |
| 388 | (format "%s\\{%d,%d\\}" (rx-to-string (nth 3 form)) | 392 | (format "%s\\{%d,%d\\}" (rx-to-string (nth 3 form)) |
| 389 | (nth 1 form) (nth 2 form))))) | 393 | (nth 1 form) (nth 2 form))))) |
| @@ -396,6 +400,16 @@ FORM is either `(repeat N FORM1)' or `(repeat N M FORM1)'." | |||
| 396 | (cdr form) nil) | 400 | (cdr form) nil) |
| 397 | "\\)")) | 401 | "\\)")) |
| 398 | 402 | ||
| 403 | (defun rx-backref (form) | ||
| 404 | "Parse and produce code from FORM, which is `(backref N)'." | ||
| 405 | (rx-check form) | ||
| 406 | (format "\\%d" (nth 1 form))) | ||
| 407 | |||
| 408 | (defun rx-check-backref (arg) | ||
| 409 | "Check arg ARG for Rx `backref'." | ||
| 410 | (or (and (integerp arg) (>= arg 1) (<= arg 9)) | ||
| 411 | (error "rx `backref' requires numeric 1<=arg<=9: %s" arg))) | ||
| 412 | |||
| 399 | (defun rx-kleene (form) | 413 | (defun rx-kleene (form) |
| 400 | "Parse and produce code from FORM. | 414 | "Parse and produce code from FORM. |
| 401 | FORM is `(OP FORM1)', where OP is one of the `zero-or-one', | 415 | FORM is `(OP FORM1)', where OP is one of the `zero-or-one', |
| @@ -484,10 +498,10 @@ of all atomic regexps." | |||
| 484 | 498 | ||
| 485 | 499 | ||
| 486 | (defun rx-greedy (form) | 500 | (defun rx-greedy (form) |
| 487 | "Parse and produce code from FORM. If FORM is '(minimal-match | 501 | "Parse and produce code from FORM. |
| 488 | FORM1)', non-greedy versions of `*', `+', and `?' operators will be | 502 | If FORM is '(minimal-match FORM1)', non-greedy versions of `*', |
| 489 | used in FORM1. If FORM is '(maximal-match FORM1)', greedy operators | 503 | `+', and `?' operators will be used in FORM1. If FORM is |
| 490 | will be used." | 504 | '(maximal-match FORM1)', greedy operators will be used." |
| 491 | (rx-check form) | 505 | (rx-check form) |
| 492 | (let ((rx-greedy-flag (eq (car form) 'maximal-match))) | 506 | (let ((rx-greedy-flag (eq (car form) 'maximal-match))) |
| 493 | (rx-to-string (cadr form)))) | 507 | (rx-to-string (cadr form)))) |
| @@ -513,19 +527,19 @@ NO-GROUP non-nil means don't put shy groups around the result." | |||
| 513 | (cond ((stringp info) | 527 | (cond ((stringp info) |
| 514 | info) | 528 | info) |
| 515 | ((null info) | 529 | ((null info) |
| 516 | (error "Unknown Rx form `%s'" form)) | 530 | (error "Unknown rx form `%s'" form)) |
| 517 | (t | 531 | (t |
| 518 | (funcall (nth 0 info) form))))) | 532 | (funcall (nth 0 info) form))))) |
| 519 | ((consp form) | 533 | ((consp form) |
| 520 | (let ((info (rx-info (car form)))) | 534 | (let ((info (rx-info (car form)))) |
| 521 | (unless (consp info) | 535 | (unless (consp info) |
| 522 | (error "Unknown Rx form `%s'" (car form))) | 536 | (error "Unknown rx form `%s'" (car form))) |
| 523 | (let ((result (funcall (nth 0 info) form))) | 537 | (let ((result (funcall (nth 0 info) form))) |
| 524 | (if (or no-group (string-match "\\`\\\\[(]" result)) | 538 | (if (or no-group (string-match "\\`\\\\[(]" result)) |
| 525 | result | 539 | result |
| 526 | (concat "\\(?:" result "\\)"))))) | 540 | (concat "\\(?:" result "\\)"))))) |
| 527 | (t | 541 | (t |
| 528 | (error "Rx syntax error at `%s'" form)))) | 542 | (error "rx syntax error at `%s'" form)))) |
| 529 | 543 | ||
| 530 | 544 | ||
| 531 | ;;;###autoload | 545 | ;;;###autoload |
| @@ -666,6 +680,8 @@ CHAR | |||
| 666 | `character-quote' (\\s/) | 680 | `character-quote' (\\s/) |
| 667 | `comment-start' (\\s<) | 681 | `comment-start' (\\s<) |
| 668 | `comment-end' (\\s>) | 682 | `comment-end' (\\s>) |
| 683 | `string-delimiter' (\\s|) | ||
| 684 | `comment-delimiter' (\\s!) | ||
| 669 | 685 | ||
| 670 | `(not (syntax SYNTAX))' | 686 | `(not (syntax SYNTAX))' |
| 671 | matches a character that has not syntax SYNTAX. | 687 | matches a character that has not syntax SYNTAX. |
| @@ -694,6 +710,7 @@ CHAR | |||
| 694 | `japanese-katakana-two-byte' (\\cK) | 710 | `japanese-katakana-two-byte' (\\cK) |
| 695 | `korean-hangul-two-byte' (\\cN) | 711 | `korean-hangul-two-byte' (\\cN) |
| 696 | `cyrillic-two-byte' (\\cY) | 712 | `cyrillic-two-byte' (\\cY) |
| 713 | `combining-diacritic' (\\c^) | ||
| 697 | `ascii' (\\ca) | 714 | `ascii' (\\ca) |
| 698 | `arabic' (\\cb) | 715 | `arabic' (\\cb) |
| 699 | `chinese' (\\cc) | 716 | `chinese' (\\cc) |
| @@ -733,7 +750,7 @@ CHAR | |||
| 733 | 750 | ||
| 734 | `(minimal-match SEXP)' | 751 | `(minimal-match SEXP)' |
| 735 | produce a non-greedy regexp for SEXP. Normally, regexps matching | 752 | produce a non-greedy regexp for SEXP. Normally, regexps matching |
| 736 | zero or more occurrances of something are \"greedy\" in that they | 753 | zero or more occurrences of something are \"greedy\" in that they |
| 737 | match as much as they can, as long as the overall regexp can | 754 | match as much as they can, as long as the overall regexp can |
| 738 | still match. A non-greedy regexp matches as little as possible. | 755 | still match. A non-greedy regexp matches as little as possible. |
| 739 | 756 | ||