[gtksourceview/gtksourceview-4-8] json.lang: Fix styles for floating point values



commit 8df9d444a654c6204c1b260892be17d4522a13e0
Author: Timothy Southwick <NickNackGus gmail com>
Date:   Wed Jan 19 12:38:13 2022 -0500

    json.lang: Fix styles for floating point values
    
    This fixes a bug where characters from the start of a floating point
    value up to the second character before the decimal point or exponent
    would be highlighted as integer values. This was noticeable in
    themes that differentiate between the two numeric types.
    
    The json test file has been updated to verify this change.
    
    Fixes #250.

 data/language-specs/json.lang       | 12 ++++++------
 tests/syntax-highlighting/file.json |  1 +
 2 files changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/data/language-specs/json.lang b/data/language-specs/json.lang
index 6f9bc817..338d87c0 100644
--- a/data/language-specs/json.lang
+++ b/data/language-specs/json.lang
@@ -39,8 +39,8 @@
     <style id="null-value"    name="Null Value"            map-to="js:null-value"/>
     <style id="boolean"       name="Boolean Value"         map-to="js:boolean"/>
     <style id="error"         name="Error"                 map-to="def:error"/>
-    <style id="decimal"       name="Decimal"               map-to="def:decimal"/>
     <style id="float"         name="Floating point number" map-to="def:floating-point"/>
+    <style id="decimal"       name="Decimal"               map-to="def:decimal"/>
   </styles>
 
   <definitions>
@@ -92,12 +92,12 @@
       </include>
     </context>
 
-    <context id="decimal" style-ref="decimal">
-      <match>-?(?:[1-9][0-9]*|0)(?![.eE])</match>
+    <context id="float" style-ref="float">
+      <match>(?![+.])-?(?:[1-9][0-9]*|0)(?=\.[0-9]|[eE][+-]?[0-9])(?:\.[0-9]+)?(?:[Ee][+-]?[0-9]+)?</match>
     </context>
 
-    <context id="float" style-ref="float">
-      <match>-?(?:[1-9][0-9]*|0)(?:\.[0-9]+)?(?:[eE][+\-]?[0-9]+)?</match>
+    <context id="decimal" style-ref="decimal">
+      <match>-?(?:[1-9][0-9]*|0)(?![.eE])</match>
     </context>
 
     <context id="catchall" style-ref="error" extend-parent="false">
@@ -108,8 +108,8 @@
       <context ref="object"/>
       <context ref="array"/>
       <context ref="string"/>
-      <context ref="decimal"/>
       <context ref="float"/>
+      <context ref="decimal"/>
       <context ref="js-lit:null-value" style-ref="null-value"/>
       <context ref="js-lit:boolean" style-ref="boolean"/>
       <context ref="catchall"/>
diff --git a/tests/syntax-highlighting/file.json b/tests/syntax-highlighting/file.json
index 3707e739..601f07ad 100644
--- a/tests/syntax-highlighting/file.json
+++ b/tests/syntax-highlighting/file.json
@@ -2,6 +2,7 @@
        "hi": -1.1e1, "b": 2,
        "abc": "hi",
        "dce": [
+               -100.0, 299.79e6,
                1.2, 2e10, -3,
                1, 2,
                "string"


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