[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lisp/json.el,v
From: |
Chong Yidong |
Subject: |
[Emacs-diffs] Changes to emacs/lisp/json.el,v |
Date: |
Thu, 28 Aug 2008 20:19:17 +0000 |
CVSROOT: /sources/emacs
Module name: emacs
Changes by: Chong Yidong <cyd> 08/08/28 20:19:17
Index: json.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/json.el,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- json.el 8 May 2008 03:37:07 -0000 1.5
+++ json.el 28 Aug 2008 20:19:17 -0000 1.6
@@ -221,19 +221,27 @@
;; Number parsing
-(defun json-read-number ()
+(defun json-read-number (&optional sign)
"Read the JSON number following point.
+The optional SIGN argument is for internal use.
+
N.B.: Only numbers which can fit in Emacs Lisp's native number
representation will be parsed correctly."
- (if (char-equal (json-peek) ?-)
- (progn
- (json-advance)
- (- 0 (json-read-number)))
- (if (looking-at "[0-9]+\\([.][0-9]+\\)?\\([eE][+-]?[0-9]+\\)?")
- (progn
+ ;; If SIGN is non-nil, the number is explicitly signed.
+ (let ((number-regexp
+ "\\([0-9]+\\)?\\(\\.[0-9]+\\)?\\([Ee][+-]?[0-9]+\\)?"))
+ (cond ((and (null sign) (char-equal (json-peek) ?-))
+ (json-advance)
+ (- (json-read-number t)))
+ ((and (null sign) (char-equal (json-peek) ?+))
+ (json-advance)
+ (json-read-number t))
+ ((and (looking-at number-regexp)
+ (or (match-beginning 1)
+ (match-beginning 2)))
(goto-char (match-end 0))
(string-to-number (match-string 0)))
- (signal 'json-number-format (list (point))))))
+ (t (signal 'json-number-format (list (point)))))))
;; Number encoding
@@ -470,7 +478,7 @@
(?\" json-read-string))))
(mapc (lambda (char)
(push (list char 'json-read-number) table))
- '(?- ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
+ '(?- ?+ ?. ?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
table)
"Readtable for JSON reader.")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] Changes to emacs/lisp/json.el,v,
Chong Yidong <=