[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/shell-command+ 07e86dc 2/6: Improve token parsing in sh
From: |
ELPA Syncer |
Subject: |
[elpa] externals/shell-command+ 07e86dc 2/6: Improve token parsing in shell-command+-tokenize |
Date: |
Wed, 4 Aug 2021 10:58:08 -0400 (EDT) |
branch: externals/shell-command+
commit 07e86dc220243f7fb18ddde043eb0614e7157fc6
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Improve token parsing in shell-command+-tokenize
---
shell-command+.el | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/shell-command+.el b/shell-command+.el
index 3c875ea..9fa25a2 100644
--- a/shell-command+.el
+++ b/shell-command+.el
@@ -138,21 +138,35 @@ the command string"
+(defconst shell-command+-token-regexp
+ (rx bos (* space)
+ (or (: ?\"
+ (group-n 1 (* (or (: ?\\ anychar) (not (any ?\\ ?\")))))
+ ?\")
+ (: ?\'
+ (group-n 1 (* (or (: ?\\ anychar) (not (any ?\\ ?\')))))
+ ?\')
+ (group (+ (not (any space ?\\ ?\" ?\')))
+ (* ?\\ anychar (* (not (any space ?\\ ?\" ?\')))))))
+ "Regular expression for tokenizing shell commands.")
+
(defun shell-command+-tokenize (command &optional expand)
"Return list of tokens of COMMAND.
If EXPAND is non-nil, expand wildcards."
(let ((pos 0) tokens)
- (while (string-match
- (rx bos (* space)
- (or (: ?\" (group (* (not ?\"))) ?\")
- (: (group (+ (not (any ?\" space)))))))
- (substring command pos))
+ (while (string-match shell-command+-token-regexp (substring command pos))
(push (let ((tok (match-string 2 (substring command pos))))
(if (and expand tok)
(or (file-expand-wildcards tok) (list tok))
- (list (or (match-string 2 (substring command pos))
- (match-string 1 (substring command pos))))))
+ (list (replace-regexp-in-string
+ (rx (* ?\\ ?\\) (group ?\\ (group anychar)))
+ "\\2"
+ (or (match-string 2 (substring command pos))
+ (match-string 1 (substring command pos)))
+ nil nil 1))))
tokens)
+ (when (= (match-end 0) 0)
+ (error "Zero-width token parsed"))
(setq pos (+ pos (match-end 0))))
(unless (= pos (length command))
(error "Tokenization error at %s" (substring command pos)))
- [elpa] externals/shell-command+ updated (50cec1e -> 6ec5ed6), ELPA Syncer, 2021/08/04
- [elpa] externals/shell-command+ 3b51514 3/6: Use full name as author, ELPA Syncer, 2021/08/04
- [elpa] externals/shell-command+ 1081933 1/6: Fix checkdoc complaints in shell-command+-tests.el, ELPA Syncer, 2021/08/04
- [elpa] externals/shell-command+ 07e86dc 2/6: Improve token parsing in shell-command+-tokenize,
ELPA Syncer <=
- [elpa] externals/shell-command+ 6ec5ed6 6/6: Add more testcases to sc+-tokenize, ELPA Syncer, 2021/08/04
- [elpa] externals/shell-command+ 2f16957 5/6: Fix checkdoc complaint in shell-command+ group definition, ELPA Syncer, 2021/08/04
- [elpa] externals/shell-command+ 3a4546c 4/6: Explicitly require diff and info, ELPA Syncer, 2021/08/04