[gtksourceview] css.lang, less.lang, scss.lang: Update @charset handling



commit d384c842d6f05950f3db70f9196a1d29d4284b4c
Author: Jeffery To <jeffery to gmail com>
Date:   Sat Jul 21 04:49:36 2018 +0800

    css.lang, less.lang, scss.lang: Update @charset handling
    
    * css.lang: Use the CSS double quoted string context instead of
    def:string
    * less.lang: Add a more lenient at-charset context to match Less'
    behaviour
    * scss.lang: Add a note to file.scss to describe Sass' behaviour

 data/language-specs/css.lang        |  2 +-
 data/language-specs/less.lang       | 12 ++++++++++++
 tests/syntax-highlighting/file.css  |  2 +-
 tests/syntax-highlighting/file.less |  5 +++++
 tests/syntax-highlighting/file.scss |  4 ++++
 5 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/data/language-specs/css.lang b/data/language-specs/css.lang
index 4d9812de..79c05ec5 100644
--- a/data/language-specs/css.lang
+++ b/data/language-specs/css.lang
@@ -1773,7 +1773,7 @@
       <start case-sensitive="true">^@charset(?= "[^"]*";)</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
-        <context ref="def:string"/>
+        <context ref="double-quoted-string"/>
         <context ref="at-rule-delimiter"/>
       </include>
     </context>
diff --git a/data/language-specs/less.lang b/data/language-specs/less.lang
index 07f003f6..a74288aa 100644
--- a/data/language-specs/less.lang
+++ b/data/language-specs/less.lang
@@ -492,6 +492,17 @@
 
     <!-- at-rules -->
 
+    <context id="less-at-charset">
+      <start case-sensitive="true">@charset\%]</start>
+      <include>
+        <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:comment"/>
+        <!-- though Less preserves quote type, which may be invalid -->
+        <context ref="css:string"/>
+        <context ref="css:at-rule-delimiter"/>
+      </include>
+    </context>
+
     <context id="less-font-feature-type-value">
       <include>
         <context ref="variable-interpolation-value"/>
@@ -573,6 +584,7 @@
 
     <replace id="css:at-rule-style-block-content" ref="less-style-block-content"/>
     <replace id="css:at-rule-css-block-content" ref="less-style-block-content"/>
+    <replace id="css:at-charset" ref="less-at-charset"/>
     <replace id="css:font-feature-type-value" ref="less-font-feature-type-value"/>
     <replace id="css:font-feature-value-declaration-name" ref="less-font-feature-value-declaration-name"/>
     <replace id="css:font-feature-value-declaration-value-content" 
ref="less-font-feature-value-declaration-value-content"/>
diff --git a/tests/syntax-highlighting/file.css b/tests/syntax-highlighting/file.css
index 04c96786..d1d45378 100644
--- a/tests/syntax-highlighting/file.css
+++ b/tests/syntax-highlighting/file.css
@@ -5,7 +5,7 @@
    * be lowercase
    * followed by one space
    * have a double quoted encoding name (encoding is case insensitive)
-   * be terminated by semicolon
+   * be terminated by semicolon, with no preceding space
 */
 
 
diff --git a/tests/syntax-highlighting/file.less b/tests/syntax-highlighting/file.less
index 9f5a305a..de60b8c0 100644
--- a/tests/syntax-highlighting/file.less
+++ b/tests/syntax-highlighting/file.less
@@ -426,6 +426,11 @@ div {
 
 // from file.css
 
+@charset "UTF-8";
+// Less will move the first @charset rule to the top
+// and ignore any other @charset rules
+
+
 /*
  * general
  */
diff --git a/tests/syntax-highlighting/file.scss b/tests/syntax-highlighting/file.scss
index 6e56bb88..76dbd223 100644
--- a/tests/syntax-highlighting/file.scss
+++ b/tests/syntax-highlighting/file.scss
@@ -452,6 +452,10 @@ div {
 
 // from file.css
 
+//@charset "UTF-8";
+// Sass follows the CSS spec when reading stylesheets,
+// so any @charset rule must be at the top of the document
+
 /*
  * general
  */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]