comparison lisp/emacs-lisp/rx.el @ 49598:0d8b17d428b5

Trailing whitepace deleted.
author Juanma Barranquero <lekktu@gmail.com>
date Tue, 04 Feb 2003 13:24:35 +0000
parents 05f00479612c
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49597:e88404e8f2cf 49598:0d8b17d428b5
76 ;; "^;;\\s-*\n\\|^\n" 76 ;; "^;;\\s-*\n\\|^\n"
77 ;; (rx (or (and line-start ";;" (0+ space) ?\n) 77 ;; (rx (or (and line-start ";;" (0+ space) ?\n)
78 ;; (and line-start ?\n))) 78 ;; (and line-start ?\n)))
79 ;; 79 ;;
80 ;; "\\$[I]d: [^ ]+ \\([^ ]+\\) " 80 ;; "\\$[I]d: [^ ]+ \\([^ ]+\\) "
81 ;; (rx (and "$Id: " 81 ;; (rx (and "$Id: "
82 ;; (1+ (not (in " "))) 82 ;; (1+ (not (in " ")))
83 ;; " " 83 ;; " "
84 ;; (submatch (1+ (not (in " ")))) 84 ;; (submatch (1+ (not (in " "))))
85 ;; " ")) 85 ;; " "))
86 ;; 86 ;;
87 ;; "\\\\\\\\\\[\\w+" 87 ;; "\\\\\\\\\\[\\w+"
88 ;; (rx (and ?\\ ?\\ ?\[ (1+ word))) 88 ;; (rx (and ?\\ ?\\ ?\[ (1+ word)))
89 ;; 89 ;;
90 ;; etc. 90 ;; etc.
91 91
92 ;;; History: 92 ;;; History:
93 ;; 93 ;;
94 94
95 ;;; Code: 95 ;;; Code:
96 96
97 97
98 (defconst rx-constituents 98 (defconst rx-constituents
242 (cond ((eq op ? ) (setq op '\?)) 242 (cond ((eq op ? ) (setq op '\?))
243 ((eq op ??) (setq op '\??))) 243 ((eq op ??) (setq op '\??)))
244 (while (and (not (null op)) (symbolp op)) 244 (while (and (not (null op)) (symbolp op))
245 (setq op (cdr (assq op rx-constituents)))) 245 (setq op (cdr (assq op rx-constituents))))
246 op) 246 op)
247 247
248 248
249 (defun rx-check (form) 249 (defun rx-check (form)
250 "Check FORM according to its car's parsing info." 250 "Check FORM according to its car's parsing info."
251 (let* ((rx (rx-info (car form))) 251 (let* ((rx (rx-info (car form)))
252 (nargs (1- (length form))) 252 (nargs (1- (length form)))
394 "\\)")) 394 "\\)"))
395 395
396 (defun rx-kleene (form) 396 (defun rx-kleene (form)
397 "Parse and produce code from FORM. 397 "Parse and produce code from FORM.
398 FORM is `(OP FORM1)', where OP is one of the `zero-or-one', 398 FORM is `(OP FORM1)', where OP is one of the `zero-or-one',
399 `zero-or-more' etc. operators. 399 `zero-or-more' etc. operators.
400 If OP is one of `*', `+', `?', produce a greedy regexp. 400 If OP is one of `*', `+', `?', produce a greedy regexp.
401 If OP is one of `*?', `+?', `??', produce a non-greedy regexp. 401 If OP is one of `*?', `+?', `??', produce a non-greedy regexp.
402 If OP is anything else, produce a greedy regexp if `rx-greedy-flag' 402 If OP is anything else, produce a greedy regexp if `rx-greedy-flag'
403 is non-nil." 403 is non-nil."
404 (rx-check form) 404 (rx-check form)
461 "Check the argument FORM of a `(category FORM)'." 461 "Check the argument FORM of a `(category FORM)'."
462 (unless (or (integerp form) 462 (unless (or (integerp form)
463 (cdr (assq form rx-categories))) 463 (cdr (assq form rx-categories)))
464 (error "Unknown category `%s'" form)) 464 (error "Unknown category `%s'" form))
465 t) 465 t)
466 466
467 467
468 (defun rx-category (form) 468 (defun rx-category (form)
469 "Parse and produce code from FORM, which is `(category SYMBOL ...)'." 469 "Parse and produce code from FORM, which is `(category SYMBOL ...)'."
470 (rx-check form) 470 (rx-check form)
471 (let ((char (if (integerp (cadr form)) 471 (let ((char (if (integerp (cadr form))
509 (let ((info (rx-info form))) 509 (let ((info (rx-info form)))
510 (cond ((stringp info) 510 (cond ((stringp info)
511 info) 511 info)
512 ((null info) 512 ((null info)
513 (error "Unknown Rx form `%s'" form)) 513 (error "Unknown Rx form `%s'" form))
514 (t 514 (t
515 (funcall (nth 0 info) form))))) 515 (funcall (nth 0 info) form)))))
516 ((consp form) 516 ((consp form)
517 (let ((info (rx-info (car form)))) 517 (let ((info (rx-info (car form))))
518 (unless (consp info) 518 (unless (consp info)
519 (error "Unknown Rx form `%s'" (car form))) 519 (error "Unknown Rx form `%s'" (car form)))
547 547
548 `(any SET)' 548 `(any SET)'
549 matches any character in SET. SET may be a character or string. 549 matches any character in SET. SET may be a character or string.
550 Ranges of characters can be specified as `A-Z' in strings. 550 Ranges of characters can be specified as `A-Z' in strings.
551 551
552 '(in SET)' 552 '(in SET)'
553 like `any'. 553 like `any'.
554 554
555 `(not (any SET))' 555 `(not (any SET))'
556 matches any character not in SET 556 matches any character not in SET
557 557
749 `(*? SEXP)' 749 `(*? SEXP)'
750 like `zero-or-more', but always produces a non-greedy regexp. 750 like `zero-or-more', but always produces a non-greedy regexp.
751 751
752 `(one-or-more SEXP)' 752 `(one-or-more SEXP)'
753 matches one or more occurrences of A. 753 matches one or more occurrences of A.
754 754
755 `(1+ SEXP)' 755 `(1+ SEXP)'
756 like `one-or-more'. 756 like `one-or-more'.
757 757
758 `(+ SEXP)' 758 `(+ SEXP)'
759 like `one-or-more', but always produces a greedy regexp. 759 like `one-or-more', but always produces a greedy regexp.
761 `(+? SEXP)' 761 `(+? SEXP)'
762 like `one-or-more', but always produces a non-greedy regexp. 762 like `one-or-more', but always produces a non-greedy regexp.
763 763
764 `(zero-or-one SEXP)' 764 `(zero-or-one SEXP)'
765 matches zero or one occurrences of A. 765 matches zero or one occurrences of A.
766 766
767 `(optional SEXP)' 767 `(optional SEXP)'
768 like `zero-or-one'. 768 like `zero-or-one'.
769 769
770 `(? SEXP)' 770 `(? SEXP)'
771 like `zero-or-one', but always produces a greedy regexp. 771 like `zero-or-one', but always produces a greedy regexp.