[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xr 09fe373: More careful error handling of \s and \c
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/xr 09fe373: More careful error handling of \s and \c |
Date: |
Wed, 13 Feb 2019 08:11:51 -0500 (EST) |
branch: externals/xr
commit 09fe37383ba81358fe9680c1bbf679b00da1d07d
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
More careful error handling of \s and \c
\s and \c without a character following is an error, and should
not result in a literal s or c.
---
xr-test.el | 10 +++++++---
xr.el | 22 ++++++++++++++--------
2 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/xr-test.el b/xr-test.el
index 87ae21a..e9aee46 100644
--- a/xr-test.el
+++ b/xr-test.el
@@ -93,6 +93,8 @@
(should (equal (xr "\\S-\\S<")
'(seq (not (syntax whitespace))
(not (syntax comment-start)))))
+ (should-error (xr "\\s"))
+ (should-error (xr "\\S"))
)
(ert-deftest xr-category ()
@@ -125,11 +127,13 @@
'(seq (not (category upper-diacritical-mark))
(not (category combining-diacritic)))))
(should (equal (xr "\\cR\\C.\\cL\\C ")
- '(seq (category strong-right-to-left)
- (not (category base)) (category strong-left-to-right)
- (not (category space-for-indent)))))
+ '(seq (category strong-right-to-left)
+ (not (category base)) (category strong-left-to-right)
+ (not (category space-for-indent)))))
(should (equal (xr "\\c%\\C+")
'(seq (regexp "\\c%") (regexp "\\C+"))))
+ (should-error (xr "\\c"))
+ (should-error (xr "\\C"))
)
(ert-deftest xr-lazy ()
diff --git a/xr.el b/xr.el
index 9ad19c7..35e10d0 100644
--- a/xr.el
+++ b/xr.el
@@ -86,7 +86,7 @@
'(ascii alnum alpha blank cntrl digit graph
lower multibyte nonascii print punct space
unibyte upper word xdigit)))
- (error "No such character class: %s" sym))
+ (error "No character class `%s'" sym))
(push sym set)
(goto-char (match-end 0))))
;; character range
@@ -226,7 +226,7 @@
(?| . string-delimiter)
(?! . comment-delimiter)))))
(when (not sym)
- (error "Unknown syntax code: %c" syntax-code))
+ (error "Unknown syntax code `%c'" syntax-code))
(let ((item (list 'syntax (cdr sym))))
(if negated (list 'not item) item))))
@@ -383,18 +383,24 @@
sequence)))
;; character syntax
- ((looking-at (rx "\\" (group (any "sS")) (group anything)))
+ ((looking-at (rx "\\" (group (any "sS")) (opt (group anything))))
(let ((negated (string-equal (match-string 1) "S"))
- (syntax-code (string-to-char (match-string 2))))
+ (syntax-code (match-string 2)))
+ (unless syntax-code
+ (error "Incomplete \\%s sequence" (match-string 1)))
(goto-char (match-end 0))
- (push (xr--char-syntax negated syntax-code) sequence)))
+ (push (xr--char-syntax negated (string-to-char syntax-code))
+ sequence)))
;; character categories
- ((looking-at (rx "\\" (group (any "cC")) (group anything)))
+ ((looking-at (rx "\\" (group (any "cC")) (opt (group anything))))
(let ((negated (string-equal (match-string 1) "C"))
- (category-code (string-to-char (match-string 2))))
+ (category-code (match-string 2)))
+ (unless category-code
+ (error "Incomplete \\%s sequence" (match-string 1)))
(goto-char (match-end 0))
- (push (xr--char-category negated category-code) sequence)))
+ (push (xr--char-category negated (string-to-char category-code))
+ sequence)))
;; Escaped character. Only \*+?.^$[ really need escaping, but we accept
;; any not otherwise handled character after the backslash since
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/xr 09fe373: More careful error handling of \s and \c,
Mattias Engdegård <=