[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 9314e6c: Embed JSON readtable into json-read
From: |
Mark Oteiza |
Subject: |
[Emacs-diffs] master 9314e6c: Embed JSON readtable into json-read |
Date: |
Mon, 4 Sep 2017 03:51:04 -0400 (EDT) |
branch: master
commit 9314e6c56e248a5060a6c125e2088c4fbffe123b
Author: Mark Oteiza <address@hidden>
Commit: Mark Oteiza <address@hidden>
Embed JSON readtable into json-read
Also unroll dispatch into a cond.
* lisp/json.el (json-readtable): Remove.
(json-readtable-dispatch): New macro. Assimilate json-readtable.
(json-read): Use the macro.
---
lisp/json.el | 22 +++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)
diff --git a/lisp/json.el b/lisp/json.el
index 6448625..025a77d 100644
--- a/lisp/json.el
+++ b/lisp/json.el
@@ -669,19 +669,22 @@ become JSON objects."
;;; JSON reader.
-(defvar json-readtable
+(defmacro json-readtable-dispatch (char)
+ "Dispatch reader function for CHAR."
+ (declare (debug (symbolp)))
(let ((table
'((?t json-read-keyword "true")
(?f json-read-keyword "false")
(?n json-read-keyword "null")
(?{ json-read-object)
(?\[ json-read-array)
- (?\" json-read-string))))
- (mapc (lambda (char)
- (push (list char 'json-read-number) table))
- '(?- ?+ ?. ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
- table)
- "Readtable for JSON reader.")
+ (?\" json-read-string)))
+ res)
+ (dolist (c '(?- ?+ ?. ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
+ (push (list c 'json-read-number) table))
+ (pcase-dolist (`(,c . ,rest) table)
+ (push `((eq ,char ,c) (,@rest)) res))
+ `(cond ,@res (t (signal 'json-readtable-error ,char)))))
(defun json-read ()
"Parse and return the JSON object following point.
@@ -690,10 +693,7 @@ Advances point just past JSON object."
(let ((char (json-peek)))
(if (zerop char)
(signal 'json-end-of-file nil)
- (let ((record (cdr (assq char json-readtable))))
- (if (functionp (car record))
- (apply (car record) (cdr record))
- (signal 'json-readtable-error record))))))
+ (json-readtable-dispatch char))))
;; Syntactic sugar for the reader
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 9314e6c: Embed JSON readtable into json-read,
Mark Oteiza <=