[gtksourceview/gnome-3-24] ruby.lang: Update escape sequence highlighting



commit ec30a7e15e2d9b6dbf12c0619e75a15261d1561b
Author: Jeffery To <jeffery to gmail com>
Date:   Wed Jan 8 04:10:48 2020 +0800

    ruby.lang: Update escape sequence highlighting
    
    This updates highlighting to match the allowed escape sequences in Ruby
    2.7.0.
    
    References:
    * https://ruby-doc.org/core-2.7.0/doc/syntax/literals_rdoc.html#label-Strings
    * https://idiosyncratic-ruby.com/61-meta-escape-control.html

 data/language-specs/ruby.lang     | 35 ++++++++++++++++++++++++++++++++++-
 tests/syntax-highlighting/file.rb | 20 ++++++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)
---
diff --git a/data/language-specs/ruby.lang b/data/language-specs/ruby.lang
index 99beeced..abd6cb97 100644
--- a/data/language-specs/ruby.lang
+++ b/data/language-specs/ruby.lang
@@ -59,8 +59,41 @@
 
   <definitions>
 
+    <define-regex id="simple-escape" extended="true">
+      \\ (?: [0-7]{1,3} | x[0-9A-Fa-f]{1,2} | [^cuxCM] )
+    </define-regex>
+
+    <define-regex id="unicode-escape" extended="true">
+      \\u
+      (?:
+        [0-9A-Fa-f]{4} |
+        { \s*
+        (?&gt;
+          (?:
+            [0-9A-Fa-f]{1,6} (?: \s+ [0-9A-Fa-f]{1,6} )*
+          )?
+        )
+        \s* }
+      )
+    </define-regex>
+
+    <define-regex id="meta-control-escape" extended="true">
+      (?&lt;! \\c | \\C- | \\M- )
+      \\
+      (?:
+        c  (?: \\M- )? |
+        C- (?: \\M- )? |
+        M- (?: \\c | \\C- )?
+      )
+      (?: \%{simple-escape} | [^\\] )
+    </define-regex>
+
+    <define-regex id="escape" extended="true">
+      (?: \%{unicode-escape} | \%{meta-control-escape} | \%{simple-escape} )
+    </define-regex>
+
     <context id="escape" style-ref="escape">
-      <match>\\([0-7]{3}|(x[a-fA-F0-9]{2})|(c\S)|([CM]-\S)|(M-C-\S)|.)</match>
+      <match>\%{escape}</match>
     </context>
 
     <context id="multiline-comment" style-ref="comment" class="comment" class-disabled="no-spell-check">
diff --git a/tests/syntax-highlighting/file.rb b/tests/syntax-highlighting/file.rb
index 28c126c8..0d20ea0f 100644
--- a/tests/syntax-highlighting/file.rb
+++ b/tests/syntax-highlighting/file.rb
@@ -5,6 +5,26 @@ puts "\141" # Shows 'a'
 str = 'lorem'
 puts str[1..3] # 'ore'
 
+# Escape sequences
+"\a \b \t \n \v \f \r \e \s" # control characters
+"\\" # backslash
+"\1 \11 \111" # octal
+"\xa \xA1" # hexadecimal
+"\u9aBC \u{1} \u{10FFFF} \u{123 abc DEF}" # unicode
+"\ca     \c"     \c\1     \c\11     \c\111     \c\xa     \c\xA1"     # control characters
+"\C-a    \C-"    \C-\1    \C-\11    \C-\111    \C-\xa    \C-\xA1"    # control characters
+"\M-a    \M-"    \M-\1    \M-\11    \M-\111    \M-\xa    \M-\xA1"    # meta characters
+"\M-\ca  \M-\c"  \M-\c\1  \M-\c\11  \M-\c\111  \M-\c\xa  \M-\c\xA1"  # meta control characters
+"\c\M-a  \c\M-"  \c\M-\1  \c\M-\11  \c\M-\111  \c\M-\xa  \c\M-\xA1"  # meta control characters
+"\M-\C-a \M-\C-" \M-\C-\1 \M-\C-\11 \M-\C-\111 \M-\C-\xa \M-\C-\xA1" # meta control characters
+"\C-\M-a \C-\M-" \C-\M-\1 \C-\M-\11 \C-\M-\111 \C-\M-\xa \C-\M-\xA1" # meta control characters
+
+# Invalid escape sequences
+"\xg"
+"\ug \u{1234567}"
+"\C \c\C-a \C-\ca \c\M-\ca \c\M-\C-a \C-\M-\ca"
+"\M \M-\M-a \M-\c\M-a \M-\C-\M-a"
+
 # Number methods
 puts -11.to_s + ' ' + 0x11.to_s  + ' ' + 1.1.to_s + ' ' + ?a.to_s + ' ' + 1.x
 11.1aa # not a valid method name


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