* Re: bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec
[not found] ` <48A39781.6030606@gmail.com>
@ 2008-08-19 5:37 ` Edward O'Connor
0 siblings, 0 replies; only message in thread
From: Edward O'Connor @ 2008-08-19 5:37 UTC (permalink / raw)
To: emacs-devel; +Cc: 679, Kevin Rodgers
[-- Attachment #1: Type: text/plain, Size: 487 bytes --]
> Here's an improved version: Besides recognizing the D. and .D number
> forms mentioned in the original bug report, and the positive signed
> forms mentioned in my first response, it also
>
> (a) recognizes hexadecimal and octal integers per
> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Integers
JSON disallows octal and hexadecimal notation...
> I hope you'll use it.
I've attached a modified version, which disallows octal & hexadecimal.
Thanks,
Ted
[-- Attachment #2: json-number.diff --]
[-- Type: application/octet-stream, Size: 1875 bytes --]
? json-number.diff
? qed.diff
Index: lisp/json.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/json.el,v
retrieving revision 1.5
diff -u -u -r1.5 json.el
--- lisp/json.el 8 May 2008 03:37:07 -0000 1.5
+++ lisp/json.el 19 Aug 2008 05:35:58 -0000
@@ -221,19 +221,27 @@
;; Number parsing
-(defun json-read-number ()
- "Read the JSON number following point.
+(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.")
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-08-19 5:37 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <87r68th97h.fsf@stupidchicken.com>
[not found] ` <3b31caf90808122211p3354755td198047ad90064a4@mail.gmail.com>
[not found] ` <48A39781.6030606@gmail.com>
2008-08-19 5:37 ` bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec Edward O'Connor
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).