[gtksourceview: 12/13] less.lang: Improve declaration value detection



commit 153bbf462249bdc3d163c2a0e899dc4852e76f37
Author: Jeffery To <jeffery to gmail com>
Date:   Tue Dec 10 07:15:32 2019 +0800

    less.lang: Improve declaration value detection
    
    This updates the declaration value lookahead regex to correctly
    handle/ignore comments, quoted strings and (function call) parentheses.

 data/language-specs/less.lang       | 118 +++++++++++++++++++++++++++++++++---
 tests/syntax-highlighting/file.less |  53 ++++++++++++----
 2 files changed, 149 insertions(+), 22 deletions(-)
---
diff --git a/data/language-specs/less.lang b/data/language-specs/less.lang
index f84d43b8..b65ffca5 100644
--- a/data/language-specs/less.lang
+++ b/data/language-specs/less.lang
@@ -397,14 +397,36 @@
 
     <context id="less-declaration-value">
       <start extended="true">
+        (?(DEFINE) (?&lt;escape_comment_start&gt; (?: \\ /\* )+ ) )
+        (?(DEFINE) (?&lt;escape&gt;               (?: \\ .   )+ ) )
+
+        (?(DEFINE) (?&lt;escape_not_interpolation_start&gt; (?: \\ (?! @{ ) . )+ ) )
+
+        (?(DEFINE)
+          (?&lt;interpolation_start_chars&gt;
+            (?: (?: @ (?! { ) )+ | (?: (?&lt;! @ ) { )+ )
+          )
+        )
+        (?(DEFINE)
+          (?&lt;comment_start_chars&gt;
+            (?: (?: / (?! \* ) )+ | (?: (?&lt;! / ) \* )+ )
+          )
+        )
+        (?(DEFINE)
+          (?&lt;comment_end_chars&gt;
+            (?: (?: \* (?! / ) )+ | (?: (?&lt;! \* ) / )+ )
+          )
+        )
+
         (?(DEFINE)
           (?&lt;interpolation&gt;  # recursive subpattern to find matching brackets
             @{
             (?:
               (?&gt;
                 (?:
-                  [^@{}]+ |
-                  (?! @{ | } ) .
+                  [^}@{]+ |
+                  # no escapes
+                  (?&amp;interpolation_start_chars)
                 )+
               ) |
               (?&amp;interpolation)
@@ -412,6 +434,74 @@
             }
           )
         )
+        (?(DEFINE)
+          (?&lt;parentheses&gt;  # recursive subpattern to find matching parentheses
+            \(
+            (?:
+              (?&gt;
+                (?:
+                  [^\\)(/*"']+ |
+                  (?&amp;escape_comment_start) |
+                  (?&amp;escape) |
+                  (?&amp;comment_start_chars)
+                )+
+              ) |
+              (?&amp;parentheses) |
+              (?&amp;comment) |
+              (?&amp;double_quotes) |
+              (?&amp;single_quotes)
+            )*
+            \)
+          )
+        )
+        (?(DEFINE)
+          (?&lt;comment&gt;  # subpattern to find matching comment delimiters
+            /\*
+            (?:
+              (?&gt;
+                (?:
+                  [^*/]+ |
+                  # no escapes
+                  (?&amp;comment_end_chars)
+                )+
+              )
+            )*
+            \*/
+          )
+        )
+        (?(DEFINE)
+          (?&lt;double_quotes&gt;  # subpattern to find matching double quotes
+            "
+            (?:
+              (?&gt;
+                (?:
+                  [^\\"@{]+ |
+                  (?&amp;escape_not_interpolation_start) |
+                  (?&amp;interpolation_start_chars)
+                )+
+              ) |
+              (?&amp;interpolation)
+            )*
+            "
+          )
+        )
+        (?(DEFINE)
+          (?&lt;single_quotes&gt;  # subpattern to find matching single quotes
+            '
+            (?:
+              (?&gt;
+                (?:
+                  [^\\'@{]+ |
+                  (?&amp;escape_not_interpolation_start) |
+                  (?&amp;interpolation_start_chars)
+                )+
+              ) |
+              (?&amp;interpolation)
+            )*
+            '
+          )
+        )
+
         (
           \+_?: |  # property merge
           :
@@ -419,16 +509,24 @@
             (?!                                 # not the start of a
               \%{css:single-identifier-char} |  #   pseudo-class
               [:\\] |                           #   pseudo-element, escape
-              @{                                #   variable interpolation
+              @{ |                              #   variable interpolation
+              /\*                               #   comment
             ) |                                 # or
             (?=                                 # ends like a normal declaration
-              (?&gt;
-                (?:
-                  [^;}{@]+ |
-                  (?&amp;interpolation)+ |
-                  \@+
-                )*
-              )
+              (?:
+                (?&gt;
+                  (?:
+                    [^\\;}{(/*"']+ |
+                    (?&amp;escape_comment_start) |
+                    (?&amp;escape) |
+                    (?&amp;comment_start_chars)
+                  )+
+                ) |
+                (?&amp;parentheses) |
+                (?&amp;comment) |
+                (?&amp;double_quotes) |
+                (?&amp;single_quotes)
+              )*
               \%{css:declaration-value-end}     #   with a semicolon or at the end of a block
             )
           )
diff --git a/tests/syntax-highlighting/file.less b/tests/syntax-highlighting/file.less
index e0ddd211..24a534fe 100644
--- a/tests/syntax-highlighting/file.less
+++ b/tests/syntax-highlighting/file.less
@@ -404,23 +404,52 @@ div {
     font-family:arial;
     @{property}:block;
 
+    background-image:url( \( \) \{ { );
+    background-image:url( url( { ) );
+    background-image:url( @var );
+    background-image:url( /* ) { */ );
+    background-image:url( " ) { " );
+    background-image:url( ' ) { ' );
+
+    margin:@var 10px;
+
+    display:/* { */block;
+
+    font-family:" \" \{ { ", serif;
+    font-family:" @{var} ", serif;
+
+    font-family:' \' \{ { ', serif;
+    font-family:' @{var} ', serif;
+
+
     // incorrectly highlighted declarations
     display:block
     ;
 
     // selectors
-    input:focus {
-        opacity: 0.5;
-    }
-    div:nth-child(2n+1) {
-       background-color: gray;
-    }
-    @{selector}:focus {
-        color: blue;
-    }
-    a:@{state} {
-        color: blue;
-    }
+    input:focus { opacity: 0.5; }
+    div:nth-child(2n+1) { background-color: gray; }
+    div:-moz-full-screen { display: block; }
+
+    @{selector}:focus { color: blue; }
+
+    a:@{state} { color: blue; }
+
+    a:focus[id=\]\;] { color: blue; }
+    a:focus[id=@{var}] { color: blue; }
+    a:focus[id=/* ] ; */] { color: blue; }
+    a:focus[id=" ] ; "] { color: blue; }
+    a:focus[id=' ] ; '] { color: blue; }
+
+    a:@{var} { color: blue; }
+
+    a:/* ; */focus { color: blue; }
+
+    a:focus[id=" ] \" \; ; "] { color: blue; }
+    a:focus[id=" @{var} "] { color: blue; }
+
+    a:focus[id=' ] \' \; ; '] { color: blue; }
+    a:focus[id=' @{var} '] { color: blue; }
 }
 
 


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