[gtksourceview] css.lang: Combine at-rule keyword and call contexts
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] css.lang: Combine at-rule keyword and call contexts
- Date: Sun, 3 Jun 2018 14:20:47 +0000 (UTC)
commit cf3ed47982b497d19b6979325a5d0af41a2f1515
Author: Jeffery To <jeffery to gmail com>
Date: Thu May 17 18:40:43 2018 +0800
css.lang: Combine at-rule keyword and call contexts
This brings the highlighting of each at-rule and its calling syntax
together, removing matching duplication.
This also sets keyword-char-class, primarily so that hyphens are taken
into account when testing for word boundaries (hyphens are valid within
CSS identifiers).
data/language-specs/css.lang | 206 ++++++++++++++++++++++++++++---------------
1 file changed, 137 insertions(+), 69 deletions(-)
---
diff --git a/data/language-specs/css.lang b/data/language-specs/css.lang
index e279bdde..ee671c1f 100644
--- a/data/language-specs/css.lang
+++ b/data/language-specs/css.lang
@@ -90,6 +90,8 @@
<default-regex-options case-sensitive="false"/>
+ <keyword-char-class>[a-z0-9_-]</keyword-char-class>
+
<definitions>
<!-- global -->
@@ -203,7 +205,7 @@
</context>
<context id="hexadecimal-color" style-ref="color">
- <match>#([a-f0-9]{8}|[a-f0-9]{6}|[a-f0-9]{4}|[a-f0-9]{3})\b</match>
+ <match>#([a-f0-9]{8}|[a-f0-9]{6}|[a-f0-9]{4}|[a-f0-9]{3})\%]</match>
</context>
<context id="css3-named-color" style-ref="color">
@@ -1627,67 +1629,96 @@
<!-- at-rules -->
- <context id="vendor-specific-at-rules" style-ref="vendor-specific">
- <match>@\%{vendor-specific-identifier-regex}</match>
+ <context id="at-rule-style-block-content">
+ <include>
+ <context ref="declaration"/>
+ </include>
</context>
- <context id="css3-at-rules" style-ref="at-rule">
- <prefix>@</prefix>
- <keyword>font-face</keyword>
- <keyword>font-feature-values</keyword>
- <keyword>keyframes</keyword>
- <keyword>namespace</keyword>
- <keyword>supports</keyword>
+ <context id="at-rule-style-block" end-parent="true">
+ <start>\{</start>
+ <end>\}</end>
+ <include>
+ <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
+ <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+ <context ref="comment"/>
+ <context ref="at-rule-style-block-content"/>
+ </include>
</context>
- <context id="at-rules" style-ref="at-rule">
- <prefix>@</prefix>
- <keyword>charset</keyword>
- <keyword>import</keyword>
- <keyword>media</keyword>
- <keyword>page</keyword>
+ <context id="at-rule-css-block-content">
+ <include>
+ <context ref="at-rule"/>
+ <context ref="all-selectors"/>
+ <context ref="style-block"/>
+ </include>
</context>
- <context id="at-rule-general-block" end-parent="true">
+ <context id="at-rule-css-block" end-parent="true">
<start>\{</start>
<end>\}</end>
<include>
<context sub-pattern="0" where="start" style-ref="block-delimiter"/>
<context sub-pattern="0" where="end" style-ref="block-delimiter"/>
- <context ref="css"/>
+ <context ref="comment"/>
+ <context ref="at-rule-css-block-content"/>
</include>
</context>
- <context id="at-rule-general-delimiter" end-parent="true" style-ref="delimiter">
+ <context id="at-rule-delimiter" end-parent="true" style-ref="delimiter">
<match>;</match>
</context>
- <context id="at-charset-call" first-line-only="true">
- <start case-sensitive="true">(?<=^@charset )(?="[^"]*";)</start>
+ <context id="vendor-specific-at-rule">
+ <start>@\%{vendor-specific-identifier-regex}</start>
+ <include>
+ <context sub-pattern="0" where="start" style-ref="vendor-specific"/>
+ <context ref="at-rule-css-block"/>
+ <context ref="at-rule-delimiter"/>
+ </include>
+ </context>
+
+ <!--
+ @charset "encoding";
+ -->
+
+ <context id="at-charset" first-line-only="true">
+ <start case-sensitive="true">^@charset(?= "[^"]*";)</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="def:string"/>
- <context ref="at-rule-general-delimiter"/>
+ <context ref="at-rule-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>
+ <context id="at-charset-error" style-ref="error">
+ <start>@charset\%]</start>
<include>
- <context ref="at-rule-general-delimiter"/>
+ <context ref="at-rule-delimiter"/>
</include>
</context>
+ <!--
+ @font-face <style-block>
+ -->
+
+ <context id="at-font-face">
+ <start>@font-face\%]</start>
+ <include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
+ <context ref="comment"/>
+ <context ref="at-rule-style-block"/>
+ </include>
+ </context>
+
+ <!--
+ @font-feature-values <font name|"font name"> {
+ @<font-feature-type> {
+ <custom-name>: <positive-integer>+;
+ }
+ }
+ -->
+
<context id="font-feature-types" style-ref="at-rule-inner-selector">
<prefix>@</prefix>
<keyword>annotation</keyword>
@@ -1751,9 +1782,10 @@
</include>
</context>
- <context id="at-font-feature-values-call">
- <start>(?<=@font-feature-values)</start>
+ <context id="at-font-feature-values">
+ <start>@font-feature-values\%]</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="comment"/>
<context ref="string-value"/>
<context ref="name-value"/>
@@ -1761,17 +1793,28 @@
</include>
</context>
- <context id="at-import-call">
- <start>(?<=@import)</start>
+ <!--
+ @import <url(...)|"url"> <media-queries>?;
+ -->
+
+ <context id="at-import">
+ <start>@import\%]</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="comment"/>
<context ref="url"/>
- <context ref="string-value"/>
<context ref="media-queries"/>
- <context ref="at-rule-general-delimiter"/>
+ <context ref="string-value"/>
+ <context ref="at-rule-delimiter"/>
</include>
</context>
+ <!--
+ @keyframes <custom name|"custom name"> {
+ <from|to|%> <style-block>
+ }
+ -->
+
<context id="keyframe-selector" style-ref="at-rule-inner-selector">
<keyword>from</keyword>
<keyword>to</keyword>
@@ -1796,9 +1839,10 @@
</include>
</context>
- <context id="at-keyframes-call">
- <start>(?<=@keyframes)</start>
+ <context id="at-keyframes">
+ <start>@keyframes\%]</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="comment"/>
<context ref="string-value"/>
<context ref="name-value"/>
@@ -1806,32 +1850,49 @@
</include>
</context>
- <context id="at-media-call">
- <start>(?<=@media)</start>
+ <!--
+ @media <media-queries> <css-block>
+ -->
+
+ <context id="at-media">
+ <start>@media\%]</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="comment"/>
<context ref="media-queries"/>
- <context ref="at-rule-general-block"/>
+ <context ref="at-rule-css-block"/>
</include>
</context>
+ <!--
+ @namespace <namespace>? <url(...)|"url">;
+ -->
+
<context id="namespace-value">
<include>
<context ref="name" style-ref="namespace"/>
</include>
</context>
- <context id="at-namespace-call">
- <start>(?<=@namespace)</start>
+ <context id="at-namespace">
+ <start>@namespace\%]</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="comment"/>
<context ref="url"/>
<context ref="string-value"/>
<context ref="namespace-value"/>
- <context ref="at-rule-general-delimiter"/>
+ <context ref="at-rule-delimiter"/>
</include>
</context>
+ <!--
+ @page <custom name>?<pseudo-page>* (, <custom name>?<pseudo-page>*)* {
+ <declaration>*
+ (@<page-margin-box-type> <style-block>)*
+ }
+ -->
+
<context id="pseudo-pages" style-ref="pseudo-class">
<prefix>:</prefix>
<keyword>blank</keyword>
@@ -1873,9 +1934,10 @@
</include>
</context>
- <context id="at-page-call">
- <start>(?<=@page)</start>
+ <context id="at-page">
+ <start>@page\%]</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="comment"/>
<context ref="pseudo-pages"/>
<context ref="name-value"/>
@@ -1884,6 +1946,10 @@
</include>
</context>
+ <!--
+ @supports <test> <css-block>
+ -->
+
<context id="at-supports-operators" style-ref="at-rule-operator">
<keyword>and</keyword>
<keyword>not</keyword>
@@ -1932,30 +1998,32 @@
</include>
</context>
- <context id="at-supports-call">
- <start>(?<=@supports)</start>
+ <context id="at-supports">
+ <start>@supports\%]</start>
<include>
+ <context sub-pattern="0" where="start" style-ref="at-rule"/>
<context ref="comment"/>
<context ref="at-supports-test"/>
<context ref="at-supports-operators"/>
- <context ref="at-rule-general-block"/>
+ <context ref="at-rule-css-block"/>
</include>
</context>
- <context id="all-at-rules">
+ <!-- all at-rules -->
+
+ <context id="at-rule">
<include>
- <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-font-feature-values-call"/>
- <context ref="at-import-call"/>
- <context ref="at-keyframes-call"/>
- <context ref="at-media-call"/>
- <context ref="at-namespace-call"/>
- <context ref="at-page-call"/>
- <context ref="at-supports-call"/>
+ <context ref="vendor-specific-at-rule"/>
+ <context ref="at-charset"/>
+ <context ref="at-charset-error"/>
+ <context ref="at-font-face"/>
+ <context ref="at-font-feature-values"/>
+ <context ref="at-import"/>
+ <context ref="at-keyframes"/>
+ <context ref="at-media"/>
+ <context ref="at-namespace"/>
+ <context ref="at-page"/>
+ <context ref="at-supports"/>
</include>
</context>
@@ -2191,7 +2259,7 @@
<context id="css" class="no-spell-check">
<include>
<context ref="comment"/>
- <context ref="all-at-rules"/>
+ <context ref="at-rule"/>
<context ref="all-selectors"/>
<context ref="style-block"/>
</include>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]