]> git.eshelyaron.com Git - emacs.git/commitdiff
Repair hideif regexp problems
authorMattias Engdegård <mattiase@acm.org>
Fri, 27 Jan 2023 16:21:28 +0000 (17:21 +0100)
committerMattias Engdegård <mattiase@acm.org>
Fri, 27 Jan 2023 16:27:15 +0000 (17:27 +0100)
* lisp/progmodes/hideif.el (hif-white-regexp, hif-tokenize):
Avoid superlinear backtracking behaviour by rewriting regexps
to avoid nested repetitions and make positive progress each time.
Use lazy matching of the innards of /*...*/ comments to avoid
matching too much.

lisp/progmodes/hideif.el

index 4405ce0fe046b1b7cc6f7e2a7bd3671ece977490..836db83c2f37cbcaad1e728a989295965e36aca0 100644 (file)
@@ -555,8 +555,8 @@ that form should be displayed.")
 (defconst hif-line-concat     "\\\\[ \t]*[\n\r]")
 ;; If `hif-white-regexp' is modified, `hif-tokenize' might need to be modified
 ;; accordingly.
-(defconst hif-white-regexp    (concat "\\(?:\\(?:[ \t]\\|/\\*.*\\*/\\)*"
-                                      "\\(?:" hif-line-concat "\\)?\\)*"))
+(defconst hif-white-regexp    (concat "\\(?:[ \t]\\|/\\*.*?\\*/"
+                                      "\\|\\(?:" hif-line-concat "\\)\\)*"))
 (defconst hif-define-regexp   (concat hif-cpp-prefix "\\(define\\|undef\\)"))
 (defconst hif-id-regexp       (concat "[[:alpha:]_][[:alnum:]_]*"))
 (defconst hif-etc-regexp      "\\.\\.\\.")
@@ -946,8 +946,8 @@ Assuming we've just performed a `hif-token-regexp' lookup."
   (let ((token-list nil)
         ;; Similar to `hif-white-regexp' but keep the spaces if there are
         (white-regexp (concat "\\(?:"
-                              "\\(?:\\([ \t]+\\)\\|\\(?:/\\*.*\\*/\\)?\\)*"
-                              "\\(?:" hif-line-concat "\\)?"
+                              "\\([ \t]+\\)\\|/\\*.*?\\*/"
+                              "\\|\\(?:" hif-line-concat "\\)"
                               "\\)*"))
         token)
     (setq hif-simple-token-only t)