[gtksourceview/gnome-3-18] vala.lang: Add context for regular expressions



commit 7b0db8d676c8f4f9c8518e540c5dd49897d8ec9f
Author: Tobias Schönberg <tobias47n9e gmail com>
Date:   Sun Feb 7 19:05:19 2016 +0100

    vala.lang: Add context for regular expressions
    
    The current lang file for vala is missing a context
    for regular expressions. This patch adds the regex
    definition from the javascript file which is an
    existing and very mature implementation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=697054
    Fixes #697054

 data/language-specs/vala.lang |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/data/language-specs/vala.lang b/data/language-specs/vala.lang
index 7193d54..8d81b55 100644
--- a/data/language-specs/vala.lang
+++ b/data/language-specs/vala.lang
@@ -45,6 +45,8 @@
     <style id="directive" name="Directives" map-to="def:preprocessor"/>
     <style id="attributes" name="Vala Attributes" map-to="def:function"/>
     <style id="string-template" name="Vala String template" map-to="def:function"/>
+    <style id="regex" _name="Regular Expression" map-to="def:string"/>
+    <style id="escape" _name="Escaped Character" map-to="def:special-char"/>
   </styles>
 
   <definitions>
@@ -52,6 +54,40 @@
     <define-regex id="identifier">[_a-zA-Z][_a-zA-Z0-9]*</define-regex>
     <define-regex id="type_name">[_a-zA-Z][_a-zA-Z0-9.]*</define-regex>
 
+    <!--regex-->
+    <define-regex id="regex-opts">[gim]*</define-regex>
+
+    <!--contexts NOT used in the main context-->
+    <context id="escape" style-ref="escape">
+      <match>\\((0-7){3}|(x[a-fA-F0-9]{2})|(c\S)|([CM]-\S)|(M-C-\S)|.)</match>
+    </context>
+
+    <context id="regex-bracketed" style-ref="escape" style-inside="true">
+      <start>(?&lt;!\\)[[]</start>
+      <end>(?&lt;!\\)]</end>
+    </context>
+
+    <!--contexts used in the main context-->
+    <context id="regex-simple" style-ref="regex">
+      <start extended="true">
+        ((?&lt;=([(]|\s))|^)
+        \/
+        (?=
+          ([^/\\]*(\\.))*
+          [^/]*
+          \/
+          \%{regex-opts}
+          \s*
+          ([),;.\/\]:}]|$)
+        )</start>
+      <end>\/\%{regex-opts}</end>
+      <include>
+        <context ref="escape"/>
+        <context ref="def:line-continue"/>
+        <context ref="regex-bracketed"/>
+      </include>
+    </context>
+
     <context id="line-comment" style-ref="comment" end-at-line-end="true" class="comment" 
class-disabled="no-spell-check">
       <start>//</start>
       <include>
@@ -358,6 +394,7 @@
         <context ref="c:octal"/>
         <context ref="if0-comment"/>
         <context ref="directive"/>
+        <context ref="regex-simple"/>
         <!-- <context ref="function"/> -->
       </include>
     </context>


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