[gtksourceview: 12/13] less.lang: Improve declaration value detection
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview: 12/13] less.lang: Improve declaration value detection
- Date: Wed, 11 Dec 2019 15:46:54 +0000 (UTC)
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) (?<escape_comment_start> (?: \\ /\* )+ ) )
+ (?(DEFINE) (?<escape> (?: \\ . )+ ) )
+
+ (?(DEFINE) (?<escape_not_interpolation_start> (?: \\ (?! @{ ) . )+ ) )
+
+ (?(DEFINE)
+ (?<interpolation_start_chars>
+ (?: (?: @ (?! { ) )+ | (?: (?<! @ ) { )+ )
+ )
+ )
+ (?(DEFINE)
+ (?<comment_start_chars>
+ (?: (?: / (?! \* ) )+ | (?: (?<! / ) \* )+ )
+ )
+ )
+ (?(DEFINE)
+ (?<comment_end_chars>
+ (?: (?: \* (?! / ) )+ | (?: (?<! \* ) / )+ )
+ )
+ )
+
(?(DEFINE)
(?<interpolation> # recursive subpattern to find matching brackets
@{
(?:
(?>
(?:
- [^@{}]+ |
- (?! @{ | } ) .
+ [^}@{]+ |
+ # no escapes
+ (?&interpolation_start_chars)
)+
) |
(?&interpolation)
@@ -412,6 +434,74 @@
}
)
)
+ (?(DEFINE)
+ (?<parentheses> # recursive subpattern to find matching parentheses
+ \(
+ (?:
+ (?>
+ (?:
+ [^\\)(/*"']+ |
+ (?&escape_comment_start) |
+ (?&escape) |
+ (?&comment_start_chars)
+ )+
+ ) |
+ (?&parentheses) |
+ (?&comment) |
+ (?&double_quotes) |
+ (?&single_quotes)
+ )*
+ \)
+ )
+ )
+ (?(DEFINE)
+ (?<comment> # subpattern to find matching comment delimiters
+ /\*
+ (?:
+ (?>
+ (?:
+ [^*/]+ |
+ # no escapes
+ (?&comment_end_chars)
+ )+
+ )
+ )*
+ \*/
+ )
+ )
+ (?(DEFINE)
+ (?<double_quotes> # subpattern to find matching double quotes
+ "
+ (?:
+ (?>
+ (?:
+ [^\\"@{]+ |
+ (?&escape_not_interpolation_start) |
+ (?&interpolation_start_chars)
+ )+
+ ) |
+ (?&interpolation)
+ )*
+ "
+ )
+ )
+ (?(DEFINE)
+ (?<single_quotes> # subpattern to find matching single quotes
+ '
+ (?:
+ (?>
+ (?:
+ [^\\'@{]+ |
+ (?&escape_not_interpolation_start) |
+ (?&interpolation_start_chars)
+ )+
+ ) |
+ (?&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
- (?>
- (?:
- [^;}{@]+ |
- (?&interpolation)+ |
- \@+
- )*
- )
+ (?:
+ (?>
+ (?:
+ [^\\;}{(/*"']+ |
+ (?&escape_comment_start) |
+ (?&escape) |
+ (?&comment_start_chars)
+ )+
+ ) |
+ (?&parentheses) |
+ (?&comment) |
+ (?&double_quotes) |
+ (?&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]