emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unquoted special characters in regexps


From: martin rudalics
Subject: Unquoted special characters in regexps
Date: Sat, 25 Feb 2006 18:23:04 +0100

Section 34.3.1.1 (Special Characters in Regular Expressions) of the
Elisp manual says:

*Please note:* For historical compatibility, special characters are
treated as ordinary ones if they are in contexts where their special
meanings make no sense. ...  It is poor practice to depend on this
behavior; quote the special character anyway, regardless of where it
appears.

The three patches below eliminate spurious occurrences of such practice:

        * font-lock.el (lisp-font-lock-keywords-2)
        * emacs-lisp/rx.el (rx-check-any, rx-check-not)
        * generic-x.el (reg-generic-mode): Quote "]"s in regexps when
        they have no special meaning.

================================================================================
*** font-lock.el        Wed Feb  1 10:17:44 2006
--- font-lock.el        Thu Feb 16 20:24:48 2006
***************
*** 2120,2126 ****
         ;; Erroneous structures.
         
("(\\(abort\\|assert\\|warn\\|check-type\\|cerror\\|error\\|signal\\)\\>" 1 
font-lock-warning-face)
         ;; Words inside \\[] tend to be for `substitute-command-keys'.
!        ("\\\\\\\\\\[\\(\\sw+\\)]" 1 font-lock-constant-face prepend)
         ;; Words inside `' tend to be symbol names.
         ("`\\(\\sw\\sw+\\)'" 1 font-lock-constant-face prepend)
         ;; Constant values.
--- 2120,2126 ----
         ;; Erroneous structures.
         
("(\\(abort\\|assert\\|warn\\|check-type\\|cerror\\|error\\|signal\\)\\>" 1 
font-lock-warning-face)
         ;; Words inside \\[] tend to be for `substitute-command-keys'.
!        ("\\\\\\\\\\[\\(\\sw+\\)\\]" 1 font-lock-constant-face prepend)
         ;; Words inside `' tend to be symbol names.
         ("`\\(\\sw\\sw+\\)'" 1 font-lock-constant-face prepend)
         ;; Constant values.
================================================================================
*** rx.el       Sat Nov  5 20:44:46 2005
--- rx.el       Thu Feb 16 20:28:18 2006
***************
*** 371,378 ****
       (if (eq ?^ (aref arg 0))
         (setq arg (concat "\\" arg)))
       ;; Remove ] and set flag for adding it to start of overall result.
!      (when (string-match "]" arg)
!        (setq arg (replace-regexp-in-string "]" "" arg)
             rx-bracket "]")))
     (when (symbolp arg)
       (let ((translation (condition-case nil
--- 371,378 ----
       (if (eq ?^ (aref arg 0))
         (setq arg (concat "\\" arg)))
       ;; Remove ] and set flag for adding it to start of overall result.
!      (when (string-match "\\]" arg)
!        (setq arg (replace-regexp-in-string "\\]" "" arg)
             rx-bracket "]")))
     (when (symbolp arg)
       (let ((translation (condition-case nil
***************
*** 404,410 ****
  (defun rx-check-not (arg)
    "Check arg ARG for Rx `not'."
    (unless (or (and (symbolp arg)
!                  (string-match "\\`\\[\\[:[-a-z]:]]\\'"
                                 (condition-case nil
                                     (rx-to-string arg 'no-group)
                                   (error ""))))
--- 404,410 ----
  (defun rx-check-not (arg)
    "Check arg ARG for Rx `not'."
    (unless (or (and (symbolp arg)
!                  (string-match "\\`\\[\\[:[-a-z]:\\]\\]\\'"
                                 (condition-case nil
                                     (rx-to-string arg 'no-group)
                                   (error ""))))
================================================================================
*** generic-x.el        Sat Nov  5 20:44:28 2005
--- generic-x.el        Sat Feb 25 17:22:58 2006
***************
*** 433,439 ****
  (define-generic-mode reg-generic-mode
    '(?\;)
    '("key" "classes_root" "REGEDIT" "REGEDIT4")
!   '(("\\(\\[.*]\\)"          1 font-lock-constant-face)
      ("^\\([^\n\r]*\\)\\s-*=" 1 font-lock-variable-name-face))
    '("\\.[rR][eE][gG]\\'")
    (list
--- 433,439 ----
  (define-generic-mode reg-generic-mode
    '(?\;)
    '("key" "classes_root" "REGEDIT" "REGEDIT4")
!   '(("\\(\\[.*\\]\\)"        1 font-lock-constant-face)
      ("^\\([^\n\r]*\\)\\s-*=" 1 font-lock-variable-name-face))
    '("\\.[rR][eE][gG]\\'")
    (list
================================================================================




reply via email to

[Prev in Thread] Current Thread [Next in Thread]