From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.bugs Subject: bug#679: 23.0.60; Function json-read-number does not handle complete Javascript spec Date: Wed, 13 Aug 2008 20:25:05 -0600 Message-ID: <48A39781.6030606@gmail.com> References: <87r68th97h.fsf@stupidchicken.com> <3b31caf90808122211p3354755td198047ad90064a4@mail.gmail.com> Reply-To: Kevin Rodgers , 679@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1218682062 28053 80.91.229.12 (14 Aug 2008 02:47:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 14 Aug 2008 02:47:42 +0000 (UTC) To: "Edward O'Connor" , 679@emacsbugs.donarmstrong.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Aug 14 04:48:32 2008 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KTSt5-0002Y6-U6 for geb-bug-gnu-emacs@m.gmane.org; Thu, 14 Aug 2008 04:48:32 +0200 Original-Received: from localhost ([127.0.0.1]:49038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTSs9-0005Mo-IA for geb-bug-gnu-emacs@m.gmane.org; Wed, 13 Aug 2008 22:47:33 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KTSs5-0005LD-2X for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 22:47:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KTSs3-0005Jl-Tj for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 22:47:28 -0400 Original-Received: from [199.232.76.173] (port=60221 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KTSs3-0005JW-KL for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 22:47:27 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:37390) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1KTSs2-00049q-W0 for bug-gnu-emacs@gnu.org; Wed, 13 Aug 2008 22:47:27 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m7E2lP2Y031722; Wed, 13 Aug 2008 19:47:25 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.13.8/8.13.8/Submit) id m7E2Z4rW027533; Wed, 13 Aug 2008 19:35:04 -0700 X-Loop: don@donarmstrong.com Resent-From: Kevin Rodgers Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs Resent-Date: Thu, 14 Aug 2008 02:35:04 +0000 Resent-Message-ID: Resent-Sender: don@donarmstrong.com X-Emacs-PR-Message: report 679 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by 679-submit@emacsbugs.donarmstrong.com id=B679.121868070924946 (code B ref 679); Thu, 14 Aug 2008 02:35:04 +0000 Original-Received: (at 679) by emacsbugs.donarmstrong.com; 14 Aug 2008 02:25:09 +0000 Original-Received: from QMTA03.westchester.pa.mail.comcast.net (qmta03.westchester.pa.mail.comcast.net [76.96.62.32]) by rzlab.ucr.edu (8.13.8/8.13.8/Debian-3) with ESMTP id m7E2P4UV024499 for <679@emacsbugs.donarmstrong.com>; Wed, 13 Aug 2008 19:25:05 -0700 Original-Received: from OMTA02.westchester.pa.mail.comcast.net ([76.96.62.19]) by QMTA03.westchester.pa.mail.comcast.net with comcast id 1mPM1a00J0QuhwU532R0sS; Thu, 14 Aug 2008 02:25:00 +0000 Original-Received: from The-Rodgers-Computer.local ([67.161.145.183]) by OMTA02.westchester.pa.mail.comcast.net with comcast id 22Qz1a00X3xeCvX3N2R01R; Thu, 14 Aug 2008 02:25:00 +0000 X-Authority-Analysis: v=1.0 c=1 a=Rf54RsIPLVAA:10 a=lCceZqWG-t4A:10 a=pQs5aej7AAAA:8 a=BRmnWfZUI4stbulexeIA:9 a=npvESc7elH_1MDb65F75wRDLJmcA:4 a=tXPUrm4B3N8A:10 User-Agent: Thunderbird 2.0.0.16 (Macintosh/20080707) In-Reply-To: <3b31caf90808122211p3354755td198047ad90064a4@mail.gmail.com> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Resent-Date: Wed, 13 Aug 2008 22:47:28 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:19413 Archived-At: Edward O'Connor wrote: > Hi, > >> Could you take a look at this bug report? > > Sure. I'll have a fix to you in the next few days. 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 (b) correctly fails to recognize more than 1 leading sign (e.g. --, ++, +-, -+) (c) correctly fails to recognize exponent forms without a preceding number. I hope you'll use it. (defun json-read-number (&optional sign base) "Read the JSON number following point. The optional SIGN and BASE arguments are for internal use. N.B.: Only numbers which can fit in Emacs Lisp's native number representation will be parsed correctly." ;; If SIGN is non-nil, the number is explicitly signed. ;; If BASE is null, read a decimal integer or floating point; ;; if BASE is 16, read a hexadecimal integer; ;; if BASE is 8, read an octal integer. (let ((number-regexp (cond ((null base) "\\([0-9]+\\)?\\(\\.[0-9]+\\)?\\([Ee][+-]?[0-9]+\\)?") ((equal base 8) "[0-7]+") ((equal base 16) "[0-9A-Fa-f]+")))) (cond ((and (null sign) (char-equal (json-peek) ?-)) (json-advance) (- (json-read-number t base))) ((and (null sign) (char-equal (json-peek) ?+)) (json-advance) (json-read-number t base)) ((and (null base) (looking-at "0[Xx]")) (json-advance 2) (json-read-number t 16)) ((and (null base) (looking-at "0[0-7]")) (json-advance 1) (json-read-number t 8)) ((and (looking-at number-regexp) (or base (match-beginning 1) (match-beginning 2))) (goto-char (match-end 0)) (string-to-number (match-string 0) base)) (t (signal 'json-number-format (list (point))))))) Thanks, -- Kevin Rodgers Denver, Colorado, USA