[gtksourceview] css.lang: Add highlighting for @charset, @import, and @namespace calls
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] css.lang: Add highlighting for @charset, @import, and @namespace calls
- Date: Fri, 18 May 2018 09:26:14 +0000 (UTC)
commit 425b4205d2321035c99388fe97b60ff343414eca
Author: Jeffery To <jeffery to gmail com>
Date: Fri May 11 06:17:22 2018 +0800
css.lang: Add highlighting for @charset, @import, and @namespace calls
This adds contexts for @charset, @import, and @namespace calls, to
highlight the valid data types for each call, and an error context for
invalid @charset calls, since it has stricter syntactic requirements.
https://bugzilla.gnome.org/show_bug.cgi?id=796130
data/language-specs/css.lang | 81 +++++++++++++++++++++++++++++++++++-
tests/syntax-highlighting/file.css | 14 +++++-
2 files changed, 91 insertions(+), 4 deletions(-)
---
diff --git a/data/language-specs/css.lang b/data/language-specs/css.lang
index 9e91988..b9b02c2 100644
--- a/data/language-specs/css.lang
+++ b/data/language-specs/css.lang
@@ -33,6 +33,7 @@
<styles>
<style id="error" name="Error" map-to="def:error"/>
+ <style id="namespace" name="Namespace" map-to="def:keyword"/>
<style id="others-2" name="Others 2"/>
<style id="string" name="String" map-to="def:string"/>
<style id="color" name="Color" map-to="def:base-n-integer"/>
@@ -385,6 +386,17 @@
<keyword>to</keyword>
</context>
+ <context id="url">
+ <start>url\(</start>
+ <end>\)</end>
+ <include>
+ <context sub-pattern="0" where="start" style-ref="function"/>
+ <context sub-pattern="0" where="end" style-ref="function"/>
+ <context ref="comment"/>
+ <context ref="string"/>
+ </include>
+ </context>
+
<context id="function-arguments-list">
<include>
<context ref="all-functions"/>
@@ -419,6 +431,7 @@
<context id="all-functions">
<include>
<context ref="vendor-specific-function"/>
+ <context ref="url"/>
<context ref="function"/>
</include>
</context>
@@ -1382,6 +1395,7 @@
<keyword>font-face</keyword>
<keyword>font-feature-values</keyword>
<keyword>keyframes</keyword>
+ <keyword>namespace</keyword>
<keyword>ornaments</keyword>
<keyword>styleset</keyword>
<keyword>stylistic</keyword>
@@ -1407,6 +1421,47 @@
</include>
</context>
+ <context id="at-rule-general-delimiter" end-parent="true" style-ref="others-3">
+ <match>;</match>
+ </context>
+
+ <context id="at-charset-call" first-line-only="true">
+ <start case-sensitive="true">(?<=^@charset )(?="[^"]*";)</start>
+ <include>
+ <context ref="def:string"/>
+ <context ref="at-rule-general-delimiter"/>
+ </include>
+ </context>
+
+ <context id="at-charset-call-error" style-ref="error">
+ <start extended="true">
+ (
+ (?<=@charset\ ) | # match if at-charset-call context did not match, or
+ (?<=@charset) # match if after @charset
+ (?! # the next character is not
+ ( # either
+ \ | # a space, or
+ \%{identifier-char-regex} # an identifier character
+ ) # (making this another at-rule, not @charset)
+ )
+ )
+ </start>
+ <include>
+ <context ref="at-rule-general-delimiter"/>
+ </include>
+ </context>
+
+ <context id="at-import-call">
+ <start>(?<=@import)</start>
+ <include>
+ <context ref="comment"/>
+ <context ref="url"/>
+ <context ref="string"/>
+ <context ref="media-queries"/>
+ <context ref="at-rule-general-delimiter"/>
+ </include>
+ </context>
+
<context id="keyframe-selector" style-ref="function">
<keyword>from</keyword>
<keyword>to</keyword>
@@ -1444,6 +1499,17 @@
</include>
</context>
+ <context id="at-namespace-call">
+ <start>(?<=@namespace)</start>
+ <include>
+ <context ref="comment"/>
+ <context ref="url"/>
+ <context ref="string"/>
+ <context ref="name" style-ref="namespace"/>
+ <context ref="at-rule-general-delimiter"/>
+ </include>
+ </context>
+
<context id="at-supports-test">
<start>\(</start>
<end>\)</end>
@@ -1482,8 +1548,12 @@
<context ref="vendor-specific-at-rules"/>
<context ref="css3-at-rules"/>
<context ref="at-rules"/>
+ <context ref="at-charset-call"/>
+ <context ref="at-charset-call-error"/>
+ <context ref="at-import-call"/>
<context ref="at-keyframes-call"/>
<context ref="at-media-call"/>
+ <context ref="at-namespace-call"/>
<context ref="at-supports-call"/>
</include>
</context>
@@ -1491,6 +1561,14 @@
<!-- selectors -->
+ <context id="namespace-qualifier">
+ <match>(\%{identifier-regex}|\*)?(\|)</match>
+ <include>
+ <context sub-pattern="1" style-ref="namespace"/>
+ <context sub-pattern="2" style-ref="others-3"/>
+ </include>
+ </context>
+
<context id="selector-id" style-ref="selector-id">
<match>#\%{identifier-regex}</match>
</context>
@@ -1599,6 +1677,7 @@
<context id="all-selectors">
<include>
+ <context ref="namespace-qualifier"/>
<context ref="selector-grammar"/>
<context ref="selector-id"/>
<context ref="selector-class"/>
@@ -1619,9 +1698,7 @@
<context id="css" class="no-spell-check">
<include>
<context ref="comment"/>
- <context ref="string"/>
<context ref="all-at-rules"/>
- <context ref="all-functions"/>
<context ref="all-selectors"/>
<context ref="style-block"/>
</include>
diff --git a/tests/syntax-highlighting/file.css b/tests/syntax-highlighting/file.css
index 18c00c6..6945156 100644
--- a/tests/syntax-highlighting/file.css
+++ b/tests/syntax-highlighting/file.css
@@ -1,3 +1,12 @@
+@charset "UTF-8";
+
+@import URL("fineprint.css");
+@import 'custom.css';
+@import url('landscape.css') screen and (orientation: landscape), print;
+
+@namespace "http://www.w3.org/1999/xhtml";
+@namespace svg url(http://www.w3.org/2000/svg);
+
@font-face {
font-family: MyHelvetica;
src: local("Helvetica Neue"),
@@ -47,6 +56,9 @@ input[type=number] {
-moz-appearance: textfield;
}
+svg|a {}
+*|a {}
+
#-- .--hello-world, /* two hyphens: https://stackoverflow.com/a/30822662 */
.-❤#-español.♫#你好, /* leading hyphen, non-ASCII */
span.\. + .\+\ space\@\>, /* special character escape */
@@ -58,8 +70,6 @@ div#\E9 dition .\0000E9dition .motion_\e9motion, /* Unicode character escape */
background: \u\72\l("unicode.png");
}
-@import URL("fineprint.css");
-
@-webkit-keyframes myanim {
from { opacity: 0.0; }
50% { opacity: 0.5; }
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]