[gtksourceview] meson.lang: Add highlighting for string escape sequences



commit c546e0236f9fb59b00d57e4710094908680f58fd
Author: Jeffery To <jeffery to gmail com>
Date:   Sun Oct 27 03:57:18 2019 +0800

    meson.lang: Add highlighting for string escape sequences
    
    This adds highlighting for escape sequences, e.g. \n \', in strings.
    (Fixes #61)
    
    This also changes string contexts to use the string style defined in the
    styles section instead of referencing def:string directly.

 data/language-specs/meson.lang        | 27 +++++++++++++++++++++++++--
 tests/syntax-highlighting/meson.build |  1 +
 2 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/data/language-specs/meson.lang b/data/language-specs/meson.lang
index 60c26c7d..0f662647 100644
--- a/data/language-specs/meson.lang
+++ b/data/language-specs/meson.lang
@@ -30,20 +30,43 @@
   <styles>
     <style id="builtin-command" name="Builtin Command" map-to="def:function"/>
     <style id="operator" name="Operator" map-to="def:operator"/>
+    <style id="escape" name="Escape Sequence" map-to="def:special-char" />
     <style id="string" name="String" map-to="def:string" />
     <style id="boolean" name="Boolean" map-to="def:boolean"/>
     <style id="keyword" name="Keyword" map-to="def:keyword"/>
   </styles>
 
   <definitions>
-    <context id="multiline-string" style-ref="def:string">
+    <!--
+    https://mesonbuild.com/Syntax.html#strings
+    also ESCAPE_SEQUENCE_SINGLE_RE in mesonbuild/mparser.py
+    https://github.com/mesonbuild/meson/blob/0.52.0/mesonbuild/mparser.py#L23-L30
+    -->
+    <context id="escape" style-ref="escape">
+      <match extended="true">
+        \\
+        (
+          [\\'abfnrtv] |      # single character escape
+          [0-7]{1,3} |        # octal value
+          x[0-9A-Fa-f]{2} |   # hex value
+          u[0-9A-Fa-f]{4} |   # 16-bit hex value
+          U[0-9A-Fa-f]{8} |   # 32-bit hex value
+          N\{[^}]+\}          # named Unicode character
+        )
+      </match>
+    </context>
+
+    <context id="multiline-string" style-ref="string">
       <start>'''</start>
       <end>'''</end>
     </context>
 
-    <context id="string" style-ref="def:string" end-at-line-end="true">
+    <context id="string" style-ref="string" end-at-line-end="true">
       <start>'</start>
       <end>'</end>
+      <include>
+        <context ref="escape"/>
+      </include>
     </context>
 
     <!-- http://mesonbuild.com/Reference-manual.html -->
diff --git a/tests/syntax-highlighting/meson.build b/tests/syntax-highlighting/meson.build
index 912447f2..da4d6c83 100644
--- a/tests/syntax-highlighting/meson.build
+++ b/tests/syntax-highlighting/meson.build
@@ -1,5 +1,6 @@
 project('gtksourceview', 'c')
 glib = dependency('glib-2.0')
+escapes = 'backslash \\ single quote \' newline \n octal \777 and more'
 executable(
   'hello',
   sources : [


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