From: Chong Yidong <cyd@stupidchicken.com>
To: "Edward O'Connor" <ted@oconnor.cx>
Cc: 679@emacsbugs.donarmstrong.com
Subject: bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec
Date: Tue, 12 Aug 2008 23:42:26 -0400 [thread overview]
Message-ID: <87r68th97h.fsf@stupidchicken.com> (raw)
Hi Edward,
Could you take a look at this bug report?
Thanks.
---------------
In json.el, the 'json-read-number' function is intended to read the
textual representation of Javascript numbers.
(defun json-read-number ()
"Read the JSON number following point.
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
(goto-char (match-end 0))
(string-to-number (match-string 0)))
(signal 'json-number-format (list (point))))))
The Javascript spec
(http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals#Floating-Point_Literals)
says the following about floating-point numbers:
| A floating-point literal can have the following parts:
|
| * A decimal integer which can be signed (preceded by "+" or "-"),
| * A decimal point ("."),
| * A fraction (another decimal number),
| * An exponent.
|
| The exponent part is an "e" or "E" followed by an integer, which can
| be signed (preceded by "+" or "-"). A floating-point literal must have
| at least one digit and either a decimal point or "e" (or "E").
This means that
1.
is a valid floating point-literal per the spec, but the regular
expression above does not match the complete text---the regular
expression requires digits after the decimal point. This ends up
matched as a simple integer, leaving the decimal point in the input
stream and causing a later syntax error. Similarly
.1
is a valid floating point-literal illegal that Emacs rejects, because
the regular expression requires digits before the decimal point.
Testing with the error console in Firefox confirms that the two
examples above are valid syntax.
The parser function needs to be fixed to handle the complete syntax.
next reply other threads:[~2008-08-13 3:42 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-13 3:42 Chong Yidong [this message]
2008-08-13 5:11 ` bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec Edward O'Connor
2008-08-14 2:25 ` Kevin Rodgers
2008-08-19 5:37 ` Edward O'Connor
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=87r68th97h.fsf@stupidchicken.com \
--to=cyd@stupidchicken.com \
--cc=679@emacsbugs.donarmstrong.com \
--cc=ted@oconnor.cx \
/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.