emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/num3-mode cfd0203976 4/4: Add support for hexadecimal f


From: Michał Nazarewicz
Subject: [elpa] externals/num3-mode cfd0203976 4/4: Add support for hexadecimal floating point literals
Date: Thu, 4 Aug 2022 15:57:44 -0400 (EDT)

branch: externals/num3-mode
commit cfd02039760b28ba5af8b12d8613afe26f32d560
Author: Michal Nazarewicz <mina86@mina86.com>
Commit: Michal Nazarewicz <mina86@mina86.com>

    Add support for hexadecimal floating point literals
    
    Hexadecimal floating-point literal is of the form ‘0x1b3d.f7p0’ with
    the exponent part required.  The integer and fraction parts use grouping
    of four digits and highlighting is mirrored just like with decimal
    floating-point numbers.  The power is formatted like a decimal integer.
    
    * num3-mode.el (num3--number-re): add alternations for hexadecimal
    floating-point literals
    (num3--matcher): handle hexadecimal fraction
---
 num3-mode.el | 20 ++++++++++++--------
 test.el      | 11 +++++++++++
 2 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/num3-mode.el b/num3-mode.el
index 284d4e9908..87d8a57b01 100644
--- a/num3-mode.el
+++ b/num3-mode.el
@@ -5,7 +5,7 @@
 ;; Author: Felix Lee <felix8a@gmail.com>, Michal Nazarewicz <mina86@mina86.com>
 ;; Maintainer: Michal Nazarewicz <mina86@mina86.com>
 ;; Keywords: faces, minor-mode
-;; Version: 1.3
+;; Version: 1.4
 
 ;; GNU Emacs is free software: you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
@@ -110,12 +110,15 @@ the (place where) decimal point (would be) is."
   ;; grouping.
   (eval-when-compile
     (concat
-        "[0#][xX]\\([[:xdigit:]]+\\)"       ; 1 = hexadecimal
-     "\\|[0#][bB]\\(?1:[01]+\\)"            ; 1 = binary
-     "\\|\\(?1:\\b\\(?:[0-9]+[a-fA-F]\\|"   ; 1 = hexadecimal w/o prefix
-               "[a-fA-F]+[0-9]\\)[[:xdigit:]]*\\b\\)"
-     "\\|\\([0-9]+\\)"                      ; 2 = decimal
-     "\\|\\.\\([0-9]+\\)")))                ; 3 = fraction
+         "#[xX]\\(?1:[[:xdigit:]]+\\)"       ; 1 = hexadecimal
+      "\\|0[xX]\\(?1:[[:xdigit:]]+\\)?"      ; 1 - hexadecimal
+              "\\(?:\\.\\(?4:[[:xdigit:]]+\\)" ; 4 - hex fraction
+                "[pP][-+]?\\(?2:[0-9]+\\)\\)?" ; 2 - decimal (power)
+      "\\|[0#][bB]\\(?1:[01]+\\)"            ; 1 = binary
+      "\\|\\(?1:\\b\\(?:[0-9]+[a-fA-F]\\|"   ; 1 = hexadecimal w/o prefix
+                "[a-fA-F]+[0-9]\\)[[:xdigit:]]*\\b\\)"
+      "\\|\\(?2:[0-9]+\\)"                   ; 2 = decimal
+      "\\|\\.\\(?3:[0-9]+\\)")))             ; 3 = fraction
 
 (defun num3--matcher (lim)
   "Function used as a font-lock-keywoard handler used in `num3-mode'.
@@ -123,8 +126,9 @@ Performs fontification of numbers from point to LIM."
   (save-excursion
     (while (re-search-forward num3--number-re lim t)
       (num3--int  (match-beginning 1) (match-end 1) 4)
+      (num3--frac (match-beginning 4) (match-end 4) 4)
       (num3--int  (match-beginning 2) (match-end 2) num3-group-size)
-      (num3--frac (match-beginning 3) (match-end 3) num3-group-size)))
+      (num3--frac (match-beginning 3) (match-end 3) num3-group-size) ))
   nil)
 
 (defun num3--int (lo hi n)
diff --git a/test.el b/test.el
index 59d0747f97..65f2f61b96 100644
--- a/test.el
+++ b/test.el
@@ -99,4 +99,15 @@ caret (‘^’).  For example:
   (num3-mode-test "6.28 6.2831 6.28318 23456.28318 .12345"
                   "6.28 6.2831 6.___^^ ^^___.___^^ .___^^"))
 
+(ert-deftest num3-mode-hexadecimal-fractions ()
+  (num3-mode-test
+   "0x6a.2a8p5 0x6a.2b1p5 0x6a.2abc8p5 0x23456.28318p5 0x.12345p5"
+   "0x6a.2a8p5 0x6a.2b1p5 0x6a.____^p5 0x^____.____^p5 0x.____^p5")
+  (num3-mode-test "0x.12345p+5 0x.12345p-5 0x.12345p+12345"
+                  "0x.____^p+5 0x.____^p-5 0x.____^p+^^___")
+  ;; Exponent is required in the notation.  Without it those are two
+  ;; literals: a hexadecimal integer, a dot token and decimal integer.
+  (num3-mode-test "0x6a.12345 0x23456.28318"
+                  "0x6a.___^^ 0x^____.___^^"))
+
 ;;; test.el ends here



reply via email to

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