emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] trunk r116816: lisp/progmodes/hideif.el (hif-tokenize): Un


From: Juanma Barranquero
Subject: [Emacs-diffs] trunk r116816: lisp/progmodes/hideif.el (hif-tokenize): Understand non-decimal floats.
Date: Thu, 20 Mar 2014 18:22:29 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 116816
revision-id: address@hidden
parent: address@hidden
committer: Juanma Barranquero <address@hidden>
branch nick: trunk
timestamp: Thu 2014-03-20 19:22:17 +0100
message:
  lisp/progmodes/hideif.el (hif-tokenize): Understand non-decimal floats.
modified:
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/progmodes/hideif.el       hideif.el-20091113204419-o5vbwnq5f7feedwu-39
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-03-20 18:16:47 +0000
+++ b/lisp/ChangeLog    2014-03-20 18:22:17 +0000
@@ -1,5 +1,8 @@
 2014-03-20  Juanma Barranquero  <address@hidden>
 
+       * progmodes/hideif.el (hif-string-to-number): New function.
+       (hif-tokenize): Use it to understand non-decimal floats.
+
        * emacs-lisp/cl-extra.el (cl--map-overlays): Remove obsolete code.
 
        * skeleton.el (skeleton-autowrap): Mark as obsolete.  Doc fix.

=== modified file 'lisp/progmodes/hideif.el'
--- a/lisp/progmodes/hideif.el  2014-03-14 00:22:33 +0000
+++ b/lisp/progmodes/hideif.el  2014-03-20 18:22:17 +0000
@@ -407,6 +407,14 @@
 
 (defconst hif-string-literal-regexp  "\\(\"\\(?:[^\"\\]\\|\\\\.\\)*\"\\)")
 
+(defun hif-string-to-number (string &optional base)
+  "Like `string-to-number', but it understands non-decimal floats."
+  (if (or (not base) (= base 10))
+      (string-to-number string base)
+    (let* ((parts (split-string string "\\." t "[ \t]+"))
+          (frac (cadr parts))
+          (quot (expt (* base 1.0) (length frac))))
+      (/ (string-to-number (concat (car parts) frac) base) quot))))
 
 (defun hif-tokenize (start end)
   "Separate string between START and END into a list of tokens."
@@ -433,15 +441,12 @@
                    ;; TODO:
                    ;; 1. postfix 'l', 'll', 'ul' and 'ull'
                    ;; 2. floating number formats
-                   ;; 3. hexadecimal/octal floats
-                   ;; 4. 098 is interpreted as octal conversion error
-                   ;; FIXME: string-to-number does not convert hex floats
+                   ;; 3. 098 is interpreted as octal conversion error
                    (if (string-match "0x\\([0-9a-fA-F]+\\.?[0-9a-fA-F]*\\)"
                                      token)
-                       (string-to-number (match-string 1 token) 16)) ;; hex
-                   ;; FIXME: string-to-number does not convert octal floats
+                       (hif-string-to-number (match-string 1 token) 16)) ;; hex
                    (if (string-match "\\`0[0-9]+\\(\\.[0-9]+\\)?\\'" token)
-                       (string-to-number token 8)) ;; octal
+                       (hif-string-to-number token 8)) ;; octal
                    (if (string-match "\\`[1-9][0-9]*\\(\\.[0-9]+\\)?\\'"
                                      token)
                        (string-to-number token)) ;; decimal


reply via email to

[Prev in Thread] Current Thread [Next in Thread]