branch: externals/pyim
commit 051903524d7656a1e31f028fdbf378e6b34297e8
Author: Feng Shu <[email protected]>
Commit: Feng Shu <[email protected]>
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)