unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec
@ 2008-08-13  3:42 Chong Yidong
  2008-08-13  5:11 ` Edward O'Connor
  0 siblings, 1 reply; 11+ messages in thread
From: Chong Yidong @ 2008-08-13  3:42 UTC (permalink / raw)
  To: Edward O'Connor; +Cc: 679

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.






^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-08-28 20:30 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87sksoc2kv.fsf@cyd.mit.edu>
2008-08-09  7:05 ` bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec sand
2008-08-09 10:57   ` OFFICE ZERO
     [not found]     ` <handler.679.B679.12182794784103.ackinfo@emacsbugs.donarmstrong.com>
2008-08-09 12:13       ` bug#679: Info received (bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec) OFFICE ZERO
     [not found]         ` <handler.679.B679.121828398627739.ackinfo@emacsbugs.donarmstrong.com>
2008-08-09 13:17           ` bug#679: Info received (bug#679: Info received (bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec)) OFFICE ZERO
2008-08-09 14:14   ` bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec OFFICE ZERO
2008-08-13  3:11   ` Kevin Rodgers
2008-08-28 20:30   ` bug#679: marked as done (23.0.60; Function json-read-number does not handle complete Javascript spec) Emacs bug Tracking System
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

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