[gtksourceview: 10/13] scss.lang: Improve declaration value detection
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview: 10/13] scss.lang: Improve declaration value detection
- Date: Wed, 11 Dec 2019 15:46:44 +0000 (UTC)
commit 03ed54da5252a9ab898c12f606d36c0104972308
Author: Jeffery To <jeffery to gmail com>
Date: Wed Dec 4 05:15:55 2019 +0800
scss.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/scss.lang | 130 ++++++++++++++++++++++++++++++++++--
tests/syntax-highlighting/file.scss | 71 +++++++++++++++-----
2 files changed, 179 insertions(+), 22 deletions(-)
---
diff --git a/data/language-specs/scss.lang b/data/language-specs/scss.lang
index 76646576..d52b325c 100644
--- a/data/language-specs/scss.lang
+++ b/data/language-specs/scss.lang
@@ -408,34 +408,150 @@
<context id="scss-declaration-value">
<start extended="true">
+ (?(DEFINE) (?<escape_interpolation_start> (?: \\ \#{ )+ ) )
+ (?(DEFINE) (?<escape_comment_start> (?: \\ /\* )+ ) )
+ (?(DEFINE) (?<escape> (?: \\ . )+ ) )
+
+ (?(DEFINE)
+ (?<interpolation_start_chars>
+ (?: (?: \# (?! { ) )+ | (?: (?<! \# ) { )+ )
+ )
+ )
+ (?(DEFINE)
+ (?<comment_start_chars>
+ (?: (?: / (?! \* ) )+ | (?: (?<! / ) \* )+ )
+ )
+ )
+ (?(DEFINE)
+ (?<comment_end_chars>
+ (?: (?: \* (?! / ) )+ | (?: (?<! \* ) / )+ )
+ )
+ )
+
(?(DEFINE)
(?<interpolation> # recursive subpattern to find matching brackets
\#{
(?:
(?>
(?:
- [^#{}]+ |
- (?! \#{ | } ) .
+ [^\\}#{(/*"']+ |
+ (?&escape_interpolation_start) |
+ (?&escape_comment_start) |
+ (?&escape) |
+ (?&interpolation_start_chars) |
+ (?&comment_start_chars)
)+
) |
- (?&interpolation)
+ (?&interpolation) |
+ (?&parentheses) |
+ (?&comment) |
+ (?&double_quotes) |
+ (?&single_quotes)
)*
}
)
)
+ (?(DEFINE)
+ (?<parentheses> # recursive subpattern to find matching parentheses
+ \(
+ (?:
+ (?>
+ (?:
+ [^\\)(#{/*"']+ |
+ (?&escape_interpolation_start) |
+ (?&escape_comment_start) |
+ (?&escape) |
+ (?&interpolation_start_chars) |
+ (?&comment_start_chars)
+ )+
+ ) |
+ (?&interpolation) |
+ (?&parentheses) |
+ (?&comment) |
+ (?&double_quotes) |
+ (?&single_quotes)
+ )*
+ \)
+ )
+ )
+ (?(DEFINE)
+ (?<comment> # subpattern to find matching comment delimiters
+ /\*
+ (?:
+ (?>
+ (?:
+ [^*/#{]+ |
+ # no escapes
+ (?&comment_end_chars) |
+ (?&interpolation_start_chars)
+ )+
+ ) |
+ (?&interpolation)
+ )*
+ \*/
+ )
+ )
+ (?(DEFINE)
+ (?<double_quotes> # subpattern to find matching double quotes
+ "
+ (?:
+ (?>
+ (?:
+ [^\\"#{]+ |
+ (?&escape_interpolation_start) |
+ (?&escape) |
+ (?&interpolation_start_chars)
+ )+
+ ) |
+ (?&interpolation)
+ )*
+ "
+ )
+ )
+ (?(DEFINE)
+ (?<single_quotes> # subpattern to find matching single quotes
+ '
+ (?:
+ (?>
+ (?:
+ [^\\'#{]+ |
+ (?&escape_interpolation_start) |
+ (?&escape) |
+ (?&interpolation_start_chars)
+ )+
+ ) |
+ (?&interpolation)
+ )*
+ '
+ )
+ )
+
:
(?:
(?! # not the start of a
\%{css:single-identifier-char} | # pseudo-class
[:\\] | # pseudo-element, escape
- \#{ # interpolation
+ \#{ | # interpolation
+ /\* # comment
) | # or
(?= # ends like a normal declaration
(?>
(?:
- [^;}{#]+ |
- (?&interpolation)+ |
- \#+
+ (?>
+ (?:
+ [^\\;}{#(/*"']+ |
+ (?&escape_interpolation_start) |
+ (?&escape_comment_start) |
+ (?&escape) |
+ (?: \# (?! { ) )+ | # interpolation_start_chars allows {
+ (?&comment_start_chars)
+ )+
+ ) |
+ (?&interpolation) |
+ (?&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.scss b/tests/syntax-highlighting/file.scss
index f7444094..fc4dfcdb 100644
--- a/tests/syntax-highlighting/file.scss
+++ b/tests/syntax-highlighting/file.scss
@@ -410,8 +410,10 @@ div {
.declarations-or-selectors {
// declarations
+
display:block;
font-family:arial;
+
font: {
family: fantasy;
weight: bold;
@@ -420,33 +422,72 @@ div {
size: 20px;
style: italic;
}
+
#{$property}:block;
#{$property}: {
color: red;
}
+
color:#000;
width:#{$width};
+ background-image:url( \( \) \{ { );
+ background-image:url( url( { ) );
+ background-image:url( #{ \) ')' '{' } );
+ background-image:url( /* ) { */ );
+ background-image:url( " ) { " );
+ background-image:url( ' ) { ' );
+
+ margin:#{ \#\{ \} \{ '{' } 10px;
+ margin:#{ url( } { ) } 10px;
+ margin:#{ #{ '{' } } 10px;
+ margin:#{ /* } { */ } 10px;
+ margin:#{ " } { " } 10px;
+ margin:#{ ' } { ' } 10px;
+
+ display:/* { */block;
+ display:/* #{ \*\/ '{' } */block;
+
+ font-family:" \" \{ { ", serif;
+ font-family:" #{ \" "" '{' } ", serif;
+
+ font-family:' \' \{ { ', serif;
+ font-family:' #{ \' '' '{' } ', serif;
+
// incorrectly highlighted declarations
display:block
;
// selectors
- input:focus {
- opacity: 0.5;
- }
- div:nth-child(2n+1) {
- background-color: gray;
- }
- div:-moz-full-screen {
- display: block;
- }
- a:#{$state} {
- color: blue;
- }
- #{$selector}:focus {
- 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=#{ \] "]" ";" }] { color: blue; }
+ a:focus[id=/* ] ; */] { color: blue; }
+ a:focus[id=" ] ; "] { color: blue; }
+ a:focus[id=' ] ; '] { color: blue; }
+
+ a:#{ \#\{ \} \; ';' } { color: blue; }
+ a:#{ url( } ; ) } { color: blue; }
+ a:#{ #{ ';' } } { color: blue; }
+ a:#{ /* } ; */ } { color: blue; }
+ a:#{ " } ; " } { color: blue; }
+ a:#{ ' } ; ' } { color: blue; }
+
+ a:/* ; */focus { color: blue; }
+ a:/* #{ \*\/ ';' } */focus { color: blue; }
+
+ a:focus[id=" ] \" \; ; "] { color: blue; }
+ a:focus[id=" #{ \" "" ';' } "] { color: blue; }
+
+ a:focus[id=' ] \' \; ; '] { color: blue; }
+ a:focus[id=' #{ \' '' ';' } '] { color: blue; }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]