ini syntax definition highlights floats inside of string
When using the ini syntax highlighter, floats are highlighted inside of strings. For example, for this code:
[Section]
Field = "something-v4.2.4.yaml"
You get this highlighting treatment:
Note the "2.4" highlighted as a float rather than preserving the string highlighting color.
This was originally discovered when using the skylighting Haskell library (see https://github.com/jgm/skylighting/issues/126) but you can see the same behavior in Kate:
I am not well versed in KDE syntax definitions but was able to come up with this patch based on looking at the JSON definition:
From e0a57f5284ba76b58ce301479adfa6f7603f6bad Mon Sep 17 00:00:00 2001
From: JJ Allaire <jj@rstudio.com>
Date: Wed, 16 Jun 2021 06:00:12 -0400
Subject: [PATCH] handle strings
---
ini-kde.xml | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/ini-kde.xml b/ini-kde.xml
index 8b36a56..a84389b 100644
--- a/ini-kde.xml
+++ b/ini-kde.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE language SYSTEM "language.dtd">
-<language name="INI Files" section="Configuration" extensions="*.ini;*.pls;*.kcfgc" mimetype="" version="8" kateversion="5.0" author="Jan Janssen (medhefgo@web.de)" license="LGPL">
+<language name="INI Files" section="Configuration" extensions="*.ini;*.pls;*.kcfgc" mimetype="" version="9" kateversion="5.0" author="Jan Janssen (medhefgo@web.de)" license="LGPL">
<highlighting>
<list name="keywords">
@@ -40,11 +40,17 @@
</context>
<context name="Value" attribute="Value" lineEndContext="#pop" >
+ <DetectChar char=""" context="String_Value" attribute="Style_String_Value" />
<Float attribute="Float" />
<Int attribute="Int" />
<keyword attribute="Keyword" String="keywords" />
</context>
+ <context name="String_Value" lineEndContext="#stay" attribute="Style_String_Value">
+ <DetectChar char=""" context="#pop" attribute="Style_String_Value" />
+ <RegExpr String="\\(?:["\\/bfnrt]|u[0-9a-fA-f]{4})" context="#stay" insensitive="false" minimal="false" attribute="Style_String_Value_Char" />
+ </context>
+
<context name="Comment" attribute="Comment" lineEndContext="#pop">
<DetectSpaces />
<IncludeRules context="##Comments" />
@@ -59,6 +65,7 @@
<itemData name="Comment" defStyleNum="dsComment" />
<itemData name="Assignment" defStyleNum="dsOthers" />
<itemData name="Value" defStyleNum="dsString" />
+ <itemData name="Style_String_Value" defStyleNum="dsString" />
<itemData name="Float" defStyleNum="dsFloat" />
<itemData name="Int" defStyleNum="dsDecVal" />
<itemData name="Keyword" defStyleNum="dsKeyword" />
--
2.29.2
This seemed to yield the correct behavior for my simple text case, however I'm not fully confident that this is the "correct" fix given my lack of context on KDE syntax definitions.
Revised syntax definition file is attached here: ini.xml