diff options
author | Mark Oteiza <mvoteiza@udel.edu> | 2017-09-04 03:40:30 -0400 |
---|---|---|
committer | Mark Oteiza <mvoteiza@udel.edu> | 2017-09-04 03:40:30 -0400 |
commit | 9314e6c56e248a5060a6c125e2088c4fbffe123b (patch) | |
tree | 92d9dc96288ee1114ddd6dfb804503e906c19f98 /lisp/json.el | |
parent | 132f4472f5f066948e69894bac8ff27430e82012 (diff) |
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.
Diffstat (limited to 'lisp/json.el')
-rw-r--r-- | lisp/json.el | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/lisp/json.el b/lisp/json.el index 64486258ccf..025a77d4b08 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 |