[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/xr 2a1de75 03/13: Correct parsing of group and backref
From: |
Mattias Engdegård |
Subject: |
[elpa] externals/xr 2a1de75 03/13: Correct parsing of group and backref |
Date: |
Wed, 13 Feb 2019 04:03:27 -0500 (EST) |
branch: externals/xr
commit 2a1de75f192e351cd2ea7e4302756dbb9e995384
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>
Correct parsing of group and backref
Parse groups and backrefs more carefully. In particular, there
is no group 0; (?0:) is illegal and \0 means 0.
---
xr-test.el | 11 +++++++++--
xr.el | 26 +++++++++++++++-----------
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/xr-test.el b/xr-test.el
index ea3d9b4..b0e52d3 100644
--- a/xr-test.el
+++ b/xr-test.el
@@ -61,6 +61,13 @@
(ert-deftest xr-backref ()
(should (equal (xr "\\(ab\\)\\(?3:cd\\)\\1\\3")
'(seq (group "ab") (group-n 3 "cd") (backref 1) (backref 3))))
+ (should (equal (xr "\\01")
+ "01"))
+ (should-error (xr "\\(?abc\\)"))
+ (should-error (xr "\\(?2\\)"))
+ (should-error (xr "\\(?0:xy\\)"))
+ (should (equal (xr "\\(?29:xy\\)")
+ '(group-n 29 "xy")))
)
(ert-deftest xr-misc ()
@@ -191,8 +198,8 @@
'(or "*a" (seq "*b" (group "*c")))))
(should (equal (xr "+a\\|+b\\(+c\\)")
'(or "+a" (seq "+b" (group "+c")))))
- (should (equal (xr "?a\\|?b\\(?c\\)")
- '(or "?a" (seq "?b" (group "?c")))))
+ (should (equal (xr "?a\\|?b\\(^?c\\)")
+ '(or "?a" (seq "?b" (group bol "?c")))))
(should (equal (xr "^**")
'(seq bol (zero-or-more "*"))))
(should (equal (xr "^+")
diff --git a/xr.el b/xr.el
index 6ad306f..e28b986 100644
--- a/xr.el
+++ b/xr.el
@@ -313,12 +313,16 @@
(push (xr--parse-char-alt negated) sequence)))
;; group
- ((looking-at (rx "\\("
- (opt (group "?" (group (zero-or-more digit)) ":"))))
+ ((looking-at (rx "\\(" (opt (group "?")
+ (opt (opt (group (any "1-9")
+ (zero-or-more digit)))
+ (group ":")))))
(let ((question (match-string 1))
(number (match-string 2))
- (end (match-end 0)))
- (goto-char end)
+ (colon (match-string 3)))
+ (when (and question (not colon))
+ (error "Invalid \\(? syntax"))
+ (goto-char (match-end 0))
(let* ((group (xr--parse-alt))
;; simplify - group has an implicit seq
(operand (if (and (listp group) (eq (car group) 'seq))
@@ -327,17 +331,17 @@
(when (not (looking-at (rx "\\)")))
(error "Missing \\)"))
(forward-char 2)
- (let ((item (cond ((not question) ; plain subgroup
- (cons 'group operand))
- ((zerop (length number)) ; shy group
- group)
- (t
+ (let ((item (cond (number ; numbered group
(append (list 'group-n (string-to-number
number))
- operand)))))
+ operand))
+ (question ; shy group
+ group)
+ (t ; plain group
+ (cons 'group operand)))))
(push item sequence)))))
;; back-reference
- ((looking-at (rx "\\" (group digit)))
+ ((looking-at (rx "\\" (group (any "1-9"))))
(forward-char 2)
(push (list 'backref (string-to-number (match-string 1)))
sequence))
- [elpa] externals/xr updated (7ba1fc6 -> e1c7734), Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 4e2bd17 04/13: Export xr-pp-rx-to-str and fix a typo, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr c2ede95 08/13: Improved errors for bad \s and \c sequences, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 8425772 01/13: Sync with ELPA: compilation workaround, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr f79d50c 12/13: Add categories L, R, . and SPC, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 2a1de75 03/13: Correct parsing of group and backref,
Mattias Engdegård <=
- [elpa] externals/xr 8d052d6 09/13: Check for errors in \_, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 37b2bcb 06/13: Merge branch 'master' of https://github.com/mattiase/xr, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 41474cb 11/13: Accept unknown character categories, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr e1c7734 13/13: Merge branch 'externals/xr' of elpa.git (no actual change), Mattias Engdegård, 2019/02/13
- [elpa] externals/xr e8ec2d9 07/13: Add reference to the pcre2el package, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 4bf6043 05/13: Export xr-pp-rx-to-str and fix a typo, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 8532df8 02/13: Move tests to separate file, Mattias Engdegård, 2019/02/13
- [elpa] externals/xr 0331e00 10/13: Recognise \sW as alias for \sw, Mattias Engdegård, 2019/02/13