diff options
| author | Stefan Monnier | 2004-04-23 21:25:58 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-04-23 21:25:58 +0000 |
| commit | 09c774f7137ab0efacf7858ba4ccd454a7c72bed (patch) | |
| tree | ebdf3bac4286934ec446cacfac504f45bcb58cd4 | |
| parent | ccfbe679888d8c3431b9946ff2e42d4e4c1c0816 (diff) | |
| download | emacs-09c774f7137ab0efacf7858ba4ccd454a7c72bed.tar.gz emacs-09c774f7137ab0efacf7858ba4ccd454a7c72bed.zip | |
(rx-syntax): Move sregex style syntax to code.
(rx-bracket, rx-check-any, rx-any): Clean up name space.
| -rw-r--r-- | lisp/emacs-lisp/rx.el | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/lisp/emacs-lisp/rx.el b/lisp/emacs-lisp/rx.el index 042d711ee3d..d4a10104eea 100644 --- a/lisp/emacs-lisp/rx.el +++ b/lisp/emacs-lisp/rx.el | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; rx.el --- sexp notation for regular expressions | 1 | ;;; rx.el --- sexp notation for regular expressions |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 2001, 03, 2004 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: Gerd Moellmann <gerd@gnu.org> | 5 | ;; Author: Gerd Moellmann <gerd@gnu.org> |
| 6 | ;; Maintainer: FSF | 6 | ;; Maintainer: FSF |
| @@ -235,23 +235,7 @@ all arguments must satisfy PREDICATE.") | |||
| 235 | (comment-start . ?<) | 235 | (comment-start . ?<) |
| 236 | (comment-end . ?>) | 236 | (comment-end . ?>) |
| 237 | (string-delimiter . ?|) | 237 | (string-delimiter . ?|) |
| 238 | (comment-delimiter . ?!) | 238 | (comment-delimiter . ?!)) |
| 239 | ;; sregex compatibility | ||
| 240 | (- . ?-) | ||
| 241 | (\. . ?.) | ||
| 242 | (w . ?w) | ||
| 243 | (_ . ?_) | ||
| 244 | (\( . ?\() | ||
| 245 | (\) . ?\)) | ||
| 246 | (\' . ?\') | ||
| 247 | (\" . ?\") | ||
| 248 | (\$ . ?$) | ||
| 249 | (\\ . ?\\) | ||
| 250 | (/ . ?/) | ||
| 251 | (< . ?<) | ||
| 252 | (> . ?>) | ||
| 253 | (| . ?|) | ||
| 254 | (! . ?!)) | ||
| 255 | "Alist mapping Rx syntax symbols to syntax characters. | 239 | "Alist mapping Rx syntax symbols to syntax characters. |
| 256 | Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid | 240 | Each entry has the form (SYMBOL . CHAR), where SYMBOL is a valid |
| 257 | symbol in `(syntax SYMBOL)', and CHAR is the syntax character | 241 | symbol in `(syntax SYMBOL)', and CHAR is the syntax character |
| @@ -372,7 +356,7 @@ FORM is of the form `(and FORM1 ...)'." | |||
| 372 | "\\)"))) | 356 | "\\)"))) |
| 373 | 357 | ||
| 374 | 358 | ||
| 375 | (defvar bracket) ; dynamically bound in `rx-any' | 359 | (defvar rx-bracket) ; dynamically bound in `rx-any' |
| 376 | 360 | ||
| 377 | (defun rx-check-any (arg) | 361 | (defun rx-check-any (arg) |
| 378 | "Check arg ARG for Rx `any'." | 362 | "Check arg ARG for Rx `any'." |
| @@ -387,7 +371,7 @@ FORM is of the form `(and FORM1 ...)'." | |||
| 387 | ;; Remove ] and set flag for adding it to start of overall result. | 371 | ;; Remove ] and set flag for adding it to start of overall result. |
| 388 | (when (string-match "]" arg) | 372 | (when (string-match "]" arg) |
| 389 | (setq arg (replace-regexp-in-string "]" "" arg) | 373 | (setq arg (replace-regexp-in-string "]" "" arg) |
| 390 | bracket "]"))) | 374 | rx-bracket "]"))) |
| 391 | (when (symbolp arg) | 375 | (when (symbolp arg) |
| 392 | (let ((translation (condition-case nil | 376 | (let ((translation (condition-case nil |
| 393 | (rx-to-string arg 'no-group) | 377 | (rx-to-string arg 'no-group) |
| @@ -406,13 +390,13 @@ FORM is of the form `(and FORM1 ...)'." | |||
| 406 | "Parse and produce code from FORM, which is `(any ARG ...)'. | 390 | "Parse and produce code from FORM, which is `(any ARG ...)'. |
| 407 | ARG is optional." | 391 | ARG is optional." |
| 408 | (rx-check form) | 392 | (rx-check form) |
| 409 | (let* (bracket | 393 | (let* ((rx-bracket nil) |
| 410 | (args (mapcar #'rx-check-any (cdr form)))) ; side-effects `bracket' | 394 | (args (mapcar #'rx-check-any (cdr form)))) ; side-effects `rx-bracket' |
| 411 | ;; If there was a ?- in the form, move it to the front to avoid | 395 | ;; If there was a ?- in the form, move it to the front to avoid |
| 412 | ;; accidental range. | 396 | ;; accidental range. |
| 413 | (if (member "-" args) | 397 | (if (member "-" args) |
| 414 | (setq args (cons "-" (delete "-" args)))) | 398 | (setq args (cons "-" (delete "-" args)))) |
| 415 | (apply #'concat "[" bracket (append args '("]"))))) | 399 | (apply #'concat "[" rx-bracket (append args '("]"))))) |
| 416 | 400 | ||
| 417 | 401 | ||
| 418 | (defun rx-check-not (arg) | 402 | (defun rx-check-not (arg) |
| @@ -595,9 +579,15 @@ of all atomic regexps." | |||
| 595 | (defun rx-syntax (form) | 579 | (defun rx-syntax (form) |
| 596 | "Parse and produce code from FORM, which is `(syntax SYMBOL)'." | 580 | "Parse and produce code from FORM, which is `(syntax SYMBOL)'." |
| 597 | (rx-check form) | 581 | (rx-check form) |
| 598 | (let ((syntax (assq (cadr form) rx-syntax))) | 582 | (let* ((sym (cadr form)) |
| 583 | (syntax (assq sym rx-syntax))) | ||
| 599 | (unless syntax | 584 | (unless syntax |
| 600 | (error "Unknown rx syntax `%s'" (cadr form))) | 585 | ;; Try sregex compatibility. |
| 586 | (let ((name (symbol-name sym))) | ||
| 587 | (if (= 1 (length name)) | ||
| 588 | (setq syntax (rassq (aref name 0) rx-syntax)))) | ||
| 589 | (unless syntax | ||
| 590 | (error "Unknown rx syntax `%s'" (cadr form)))) | ||
| 601 | (format "\\s%c" (cdr syntax)))) | 591 | (format "\\s%c" (cdr syntax)))) |
| 602 | 592 | ||
| 603 | 593 | ||