emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/pyim 0519035: Add pyim-cregexp-valid-p and use it.


From: ELPA Syncer
Subject: [elpa] externals/pyim 0519035: Add pyim-cregexp-valid-p and use it.
Date: Tue, 16 Mar 2021 00:01:31 -0400 (EDT)

branch: externals/pyim
commit 051903524d7656a1e31f028fdbf378e6b34297e8
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>

    Add pyim-cregexp-valid-p and use it.
    
    * pyim.el (pyim-cregexp-valid-p): New function.
    (pyim-cregexp-build): Use pyim-cregexp-valid-p.
---
 pyim.el | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/pyim.el b/pyim.el
index bc858cf..9f0cc0f 100644
--- a/pyim.el
+++ b/pyim.el
@@ -3848,24 +3848,32 @@ PUNCT-LIST 格式类似:
   (if (equal string "")
       string
     (let* ((char-level-num (or char-level-num 3))
-           (rx-string (ignore-errors
-                        (rx-to-string (pyim-cregexp-build-from-rx
-                                       (lambda (x)
-                                         (if (stringp x)
-                                             (xr (pyim-cregexp-build-1 x 
char-level-num))
-                                           x))
-                                       (xr string))))))
+           (rx-string
+            (if (= char-level-num 0)
+                string
+              (ignore-errors
+                (rx-to-string
+                 (pyim-cregexp-build-from-rx
+                  (lambda (x)
+                    (if (stringp x)
+                        (xr (pyim-cregexp-build-1 x char-level-num))
+                      x))
+                  (xr string)))))))
       (if (and rx-string (stringp rx-string))
-          ;; NOTE: Emacs seem to can not handle regexp which length is too big,
-          ;; for example: > 6000
-          (if (or (= char-level-num 0)
-                  (length< rx-string 5000))
-              (if (length< rx-string 5000)
-                  rx-string
-                string)
+          (if (pyim-cregexp-valid-p rx-string)
+              rx-string
             (pyim-cregexp-build string (- char-level-num 1)))
         string))))
 
+(defun pyim-cregexp-valid-p (cregexp)
+  "Return t when cregexp is a valid regexp."
+  (and cregexp
+       (stringp cregexp)
+       (condition-case nil
+           (progn (string-match-p cregexp "") t)
+         ;; FIXME: Emacs can't handle regexps whose length is too big :-(
+         (error nil))))
+
 (defun pyim-cregexp-build-from-rx (fn rx-form)
   (pcase rx-form
     ('nil nil)



reply via email to

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