[gtksourceview] css.lang: Numbers and units fixes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] css.lang: Numbers and units fixes
- Date: Wed, 9 May 2018 09:23:29 +0000 (UTC)
commit 896e22d6b6ebf172823f249235c28f36482f7ed1
Author: Jeffery To <jeffery to gmail com>
Date: Thu Apr 26 00:34:08 2018 +0800
css.lang: Numbers and units fixes
* Unify number and float contexts, adding a number regex that more
closely follows the CSS definition of a number[1]
* Use the number regex for dimension and resolution contexts
* Add the turn unit to the dimension context
* Make resolutions strictly positive (allowing for an optional plus
sign)[2]
* Add a ratio context for aspect ratio media queries[3]
Note that the ratio context doesn't use the number regex, because ratios
only allow (strictly positive) integers for their numerators and
denominators.
https://bugzilla.gnome.org/show_bug.cgi?id=795923
[1] https://developer.mozilla.org/en-US/docs/Web/CSS/number
[2] https://developer.mozilla.org/en-US/docs/Web/CSS/resolution
[3] https://developer.mozilla.org/en-US/docs/Web/CSS/ratio
data/language-specs/css.lang | 23 +++++++++--------------
tests/syntax-highlighting/file.css | 8 ++++++++
2 files changed, 17 insertions(+), 14 deletions(-)
---
diff --git a/data/language-specs/css.lang b/data/language-specs/css.lang
index ead6947..eca4197 100644
--- a/data/language-specs/css.lang
+++ b/data/language-specs/css.lang
@@ -303,25 +303,22 @@
<keyword>yellow</keyword>
</context>
+ <define-regex id="number-regex">(\d+|\d*\.\d+)(e[+-]?\d+)?</define-regex>
+
<context id="dimension" style-ref="dimension">
-
<match>[\+-]?([0-9]+|[0-9]*\.[0-9]+)(%|e(m|x)|(v(h|w|min|max))|ch|fr|rem|p(x|t|c)|in|ft|(m|c)m|k?Hz|deg|g?rad|m?s)</match>
+
<match>[+-]?\%{number-regex}(%|e(m|x)|(v(h|w|min|max))|ch|fr|rem|p(x|t|c)|in|ft|(m|c)m|k?Hz|deg|g?rad|turn|m?s)</match>
</context>
<context id="resolution" style-ref="dimension">
- <match>[\+-]?([0-9]+|[0-9]*\.[0-9]+)(dpi|dpcm|dppx)</match>
+ <match>\+?\%{number-regex}dp(i|cm|px)</match>
</context>
- <context id="number" style-ref="decimal">
- <match>\b(0|[\+-]?[1-9][0-9]*)</match>
+ <context id="ratio" style-ref="dimension">
+ <match>\+?\d+\s*/\s*\+?\d+</match>
</context>
- <define-regex id="float" extended="true">
- ( (\d+)?\.\d+ | \d+\. ) |
- ( (\d+|(\d+)?\.\d+|\d+\.)[eE][+-]?\d+ )
- </define-regex>
-
- <context id="float-number" style-ref="dimension">
- <match>(?<![\w\.])\%{float}(?![\w\.])</match>
+ <context id="number" style-ref="decimal">
+ <match>(?<![\w\.])[+-]?\%{number-regex}(?![\w\.])</match>
</context>
<context id="unicode-range" style-ref="others-2">
@@ -1104,7 +1101,6 @@
<context ref="named-color"/>
<context ref="function"/>
<context ref="dimension"/>
- <context ref="float-number"/>
<context ref="number"/>
<context ref="unicode-range"/>
<context ref="importance-modifier"/>
@@ -1144,7 +1140,6 @@
<context ref="hexadecimal-color"/>
<context ref="resolution"/>
<context ref="dimension"/>
- <context ref="float-number"/>
<context ref="number"/>
<context ref="function"/>
</include>
@@ -1194,7 +1189,7 @@
<context ref="hexadecimal-color"/>
<context ref="resolution"/>
<context ref="dimension"/>
- <context ref="float-number"/>
+ <context ref="ratio"/>
<context ref="number"/>
</include>
</context>
diff --git a/tests/syntax-highlighting/file.css b/tests/syntax-highlighting/file.css
index 1776246..74ed9b4 100644
--- a/tests/syntax-highlighting/file.css
+++ b/tests/syntax-highlighting/file.css
@@ -9,6 +9,11 @@ p + div {
.someclass,
.otherclass {
font-size: 20px;
+ opacity: .5;
+}
+
+#headline:after {
+ transform: scaleX(-1.75) rotate(+33.333e+3deg);
}
ul::before {}
@@ -33,3 +38,6 @@ link:hover {}
}
}
+@media (min-resolution: +2.54dpcm) {}
+
+@media (min-aspect-ratio: 16/9) {}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]