all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Edward O'Connor" <hober0@gmail.com>
To: emacs-devel@gnu.org
Cc: 679@emacsbugs.donarmstrong.com,
	Kevin Rodgers <kevin.d.rodgers@gmail.com>
Subject: bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec
Date: Mon, 18 Aug 2008 22:37:27 -0700	[thread overview]
Message-ID: <3b31caf90808182237g265b239fgfb4a365686eac490__45118.9162712128$1219124927$gmane$org@mail.gmail.com> (raw)
In-Reply-To: <48A39781.6030606@gmail.com>

[-- 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.")
 

  reply	other threads:[~2008-08-19  5:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13  3:42 bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec Chong Yidong
2008-08-13  5:11 ` Edward O'Connor
2008-08-14  2:25   ` Kevin Rodgers
2008-08-19  5:37     ` Edward O'Connor [this message]
2008-08-19  5:37     ` Edward O'Connor
  -- strict thread matches above, loose matches on Subject: below --
2008-08-09  7:05 sand
2008-08-09 10:57 ` OFFICE ZERO
2008-08-09 14:14 ` OFFICE ZERO
2008-08-13  3:11 ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='3b31caf90808182237g265b239fgfb4a365686eac490__45118.9162712128$1219124927$gmane$org@mail.gmail.com' \
    --to=hober0@gmail.com \
    --cc=679@emacsbugs.donarmstrong.com \
    --cc=emacs-devel@gnu.org \
    --cc=kevin.d.rodgers@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.