[gtksourceview/gtksourceview-4-2] yaml.lang: improve the highlighting of quoted strings



commit 854fe9e33020edd77a6095b64dfa306448eede29
Author: Роман Донченко <dpb corrigendum ru>
Date:   Tue Apr 30 00:11:56 2019 +0300

    yaml.lang: improve the highlighting of quoted strings
    
    * Allow them to be multiline.
    
    * Add highlighting for escape sequences. This necessitates splitting
      the "string" context into "single-quoted-string" and
      "double-quoted-string", as the escaping rules are different.
    
    * Allow empty quoted strings ("") to be highlighted correctly. The previous
      end regex prevented the closing quote in this case to be recognized
      as such, as it required it to be preceded by at least one character.

 data/language-specs/yaml.lang | 40 ++++++++++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 6 deletions(-)
---
diff --git a/data/language-specs/yaml.lang b/data/language-specs/yaml.lang
index 4578bd66..4534f014 100644
--- a/data/language-specs/yaml.lang
+++ b/data/language-specs/yaml.lang
@@ -29,6 +29,8 @@
     <style id="scalar"    name="Block literal"   map-to="def:string"/>
     <style id="comment"   name="Comment"         map-to="def:comment"/>
     <style id="string"    name="String"          map-to="def:string"/>
+    <style id="escape-sequence"
+                          name="Escape sequence" map-to="def:special-char"/>
     <style id="anchor"    name="Anchor"          map-to="def:identifier"/>
     <style id="tag"       name="Tag"             map-to="def:preprocessor"/>
     <style id="alias"     name="Alias"           map-to="def:type"/>
@@ -79,9 +81,32 @@
       <match>(?&lt;=^|\s)&amp;\%{ischar}+(?=$|\s)</match>
     </context>
 
-    <context id="string" end-at-line-end="true" style-ref="string" class-disabled="no-spell-check">
-      <start>(?&lt;=^|\%{lschar})(?'q'["'])</start>
-      <end>[^\\]\%{q@start}</end>
+    <context id="double-quoted-string" style-ref="string" class-disabled="no-spell-check">
+      <start>(?&lt;=^|\%{lschar})"</start>
+      <end>"</end>
+      <include>
+        <context style-ref="escape-sequence">
+          <match extended="true">
+            \\ (?:
+              [0abt\tnvfre "/\\N_LP] |
+              x [0-9a-fA-F]{2} |
+              u [0-9a-fA-F]{4} |
+              U [0-9a-fA-F]{8} |
+              $
+            )
+          </match>
+        </context>
+      </include>
+    </context>
+
+    <context id="single-quoted-string" style-ref="string" class-disabled="no-spell-check">
+      <start>(?&lt;=^|\%{lschar})'</start>
+      <end>'</end>
+      <include>
+        <context style-ref="escape-sequence">
+          <match>''</match>
+        </context>
+      </include>
     </context>
 
     <context id="unquoted-string" end-at-line-end="true" style-ref="string" class-disabled="no-spell-check">
@@ -140,7 +165,8 @@
         <context ref="alias"/>
         <context ref="tag"/>
         <context ref="anchor"/>
-        <context ref="string"/>
+        <context ref="single-quoted-string"/>
+        <context ref="double-quoted-string"/>
         <context ref="inline-null"/>
         <context ref="inline-bool"/>
         <context ref="inline-int"/>
@@ -162,7 +188,8 @@
         <context ref="alias"/>
         <context ref="tag"/>
         <context ref="anchor"/>
-        <context ref="string"/>
+        <context ref="single-quoted-string"/>
+        <context ref="double-quoted-string"/>
         <context ref="inline-null"/>
         <context ref="inline-bool"/>
         <context ref="inline-int"/>
@@ -223,7 +250,8 @@
         <context ref="alias"/>
         <context ref="tag"/>
         <context ref="anchor"/>
-        <context ref="string"/>
+        <context ref="single-quoted-string"/>
+        <context ref="double-quoted-string"/>
         <context ref="map"/>
         <context ref="unquoted-string"/>
       </include>


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