[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] scratch/org-edna 6ec67b8 10/72: Improved org-bat-parse-form to ha
From: |
Ian Dunn |
Subject: |
[elpa] scratch/org-edna 6ec67b8 10/72: Improved org-bat-parse-form to handle new argument types |
Date: |
Sun, 21 May 2017 21:11:19 -0400 (EDT) |
branch: scratch/org-edna
commit 6ec67b8dd91b1a9505b8e810b01b514e97329010
Author: Ian D <address@hidden>
Commit: Ian D <address@hidden>
Improved org-bat-parse-form to handle new argument types
Includes quoted arguments, nested parentheses, and arguments with spaces.
* org-bat.el (org-bat-parse-form): Rewrote to use `read-from-string'.
---
org-bat.el | 46 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 39 insertions(+), 7 deletions(-)
diff --git a/org-bat.el b/org-bat.el
index e3ca976..d360732 100644
--- a/org-bat.el
+++ b/org-bat.el
@@ -13,13 +13,45 @@
(require 'subr-x)
(defun org-bat-parse-form (form)
- "Form should be KEY(ARGS)."
- (when (string-match "^\\([!]\\)?\\([a-zA-Z-]+\\)\\(?:(\\([^)]+\\))\\)?" form)
- (list (intern (match-string 2 form))
- (when-let (args (match-string 3 form))
- (save-match-data (split-string args ",")))
- (match-string 1 form)
- (match-end 0))))
+ (pcase-let* ((`(,token . ,pos) (read-from-string form))
+ (modifier nil)
+ (args nil))
+ (unless token
+ (signal 'invalid-read-syntax (substring form pos)))
+ ;; Check for either end of string or an opening parenthesis
+ (unless (or (equal pos (length form))
+ (equal (string-match-p "(" form pos) pos))
+ (signal 'invalid-read-syntax (substring form pos 1)))
+ ;; Parse arguments if we have any
+ (when (equal (string-match-p "(" form pos) pos)
+ ;; Move past the parenthesis
+ (cl-incf pos)
+ (while (and (< pos (length form))
+ (not (= (string-match-p ")" form pos) pos)))
+ (pcase-let* ((`(,arg . ,new-pos) (read-from-string form pos)))
+ (unless arg
+ (signal 'invalid-read-syntax (substring form pos)))
+ (let ((new-arg (if (stringp arg) arg (symbol-name arg))))
+ (push new-arg args))
+ (setq pos new-pos)
+ ;; Move past whitespace
+ (when (eq (string-match "\\w+" form pos) pos)
+ (setq pos (match-end 0)))
+ ;; The next character should either be a ',' or a ')'
+ (unless (equal (string-match-p "[,)]" form pos) pos)
+ (signal 'invalid-read-syntax (substring form pos 1)))
+ ;; Move past a comma if there is one
+ (when (equal (string-match-p "," form pos) pos)
+ (cl-incf pos))))
+ (unless (equal (string-match-p ")" form pos) pos)
+ (signal 'invalid-read-syntax (substring form pos 1)))
+ (setq args (seq-reverse args))
+ ;; Move past the closing parenthesis
+ (cl-incf pos))
+ (when (string-match "^\\([!]\\)\\(.*\\)" (symbol-name token))
+ (setq modifier (intern (match-string 1 (symbol-name token))))
+ (setq token (intern (match-string 2 (symbol-name token)))))
+ (list token args modifier pos)))
(defconst org-bat--types
'(finder action condition)
- [elpa] branch scratch/org-edna created (now 901a84a), Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 352d95c 06/72: Added has-property condition, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 69cc5d4 07/72: Added package requirements, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 0273bf1 02/72: Make all finders return lists of markers, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 03a6a95 03/72: Added Makefile., Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 5e69f84 04/72: Added .bzrignore., Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 6ec67b8 10/72: Improved org-bat-parse-form to handle new argument types,
Ian Dunn <=
- [elpa] scratch/org-edna 8b58c07 14/72: Clarified use of case-fold-search in `org-bat--handle-planning', Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 00ef89a 11/72: Added tests for org-bat-parse-form, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 8aeb66c 08/72: Added more custom IDs to documentation, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 89baba4 13/72: Added chain action, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna e2db4dc 19/72: Remove duplicate targets, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 68b01b8 16/72: Fixed bug in Makefile, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna dc320fe 17/72: Use existing org-xor instead of new function, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 0977b83 20/72: Don't assume arguments will be symbols or strings, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna 8a8cfd6 12/72: Cleaned up condition handling, Ian Dunn, 2017/05/21
- [elpa] scratch/org-edna b40f7f0 05/72: Added initial documentation, Ian Dunn, 2017/05/21