[gtksourceview: 2/4] css.lang (and family): Add embedded-lang-hook contexts



commit 0cb8ec3b94056b566495b9cddf073f5e188d27c9
Author: Jeffery To <jeffery to gmail com>
Date:   Fri Nov 29 06:57:01 2019 +0800

    css.lang (and family): Add embedded-lang-hook contexts
    
    This allows CSS highlighting inside <style> elements of HTML files to
    end wherever a </style> tag is present, and allows PHP code (<?php ...
    ?>) inside of PHP files to be properly highlighted inside <style>
    elements.

 data/language-specs/css.lang        | 49 ++++++++++++++++++++++++++++++++++++-
 data/language-specs/html.lang       | 14 ++++++++++-
 data/language-specs/less.lang       | 40 ++++++++++++++++++++++++++++--
 data/language-specs/scss.lang       | 39 ++++++++++++++++++++++++++++-
 tests/syntax-highlighting/file.html | 14 +++++++++++
 tests/syntax-highlighting/file.php  | 33 +++++++++++++++++++++++++
 6 files changed, 184 insertions(+), 5 deletions(-)
---
diff --git a/data/language-specs/css.lang b/data/language-specs/css.lang
index 9382f764..7518a206 100644
--- a/data/language-specs/css.lang
+++ b/data/language-specs/css.lang
@@ -7,7 +7,7 @@
  Copyright (C) 2004 Scott Martin <scott coffeeblack org>
  Copyright (C) 2010 Patryk Zawadzki <patrys pld-linux org>
  Copyright (C) 2016 Tobias Schönberg <tobias47n9e gmail com>
- Copyright (C) 2018 Jeffery To <jeffery to gmail com>
+ Copyright (C) 2018-2019 Jeffery To <jeffery to gmail com>
 
  GtkSourceView is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -192,10 +192,13 @@
 
     <define-regex id="test-value-end">(?=\))</define-regex>
 
+    <context id="embedded-lang-hook"/>
+
     <context id="multiline-comment" style-ref="comment" class-disabled="no-spell-check" class="comment">
       <start>/\*</start>
       <end>\*/</end>
       <include>
+        <context ref="embedded-lang-hook"/>
         <context ref="def:in-comment"/>
       </include>
     </context>
@@ -254,6 +257,8 @@
       <start>"</start>
       <end>"</end>
       <include>
+        <context ref="embedded-lang-hook"/>
+        <!-- no comment here -->
         <context ref="string-content"/>
       </include>
     </context>
@@ -262,6 +267,8 @@
       <start>'</start>
       <end>'</end>
       <include>
+        <context ref="embedded-lang-hook"/>
+        <!-- no comment here -->
         <context ref="string-content"/>
       </include>
     </context>
@@ -567,6 +574,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="function"/>
         <context sub-pattern="0" where="end" style-ref="function"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="string-value"/>
       </include>
@@ -579,6 +587,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="function"/>
         <context sub-pattern="0" where="end" style-ref="function"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="custom-property-name"/>
         <context ref="function-content"/>
@@ -598,6 +607,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="vendor-specific"/>
         <context sub-pattern="0" where="end" style-ref="vendor-specific"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="function-content"/>
       </include>
@@ -609,6 +619,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="function"/>
         <context sub-pattern="0" where="end" style-ref="function"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="function-content"/>
       </include>
@@ -1550,6 +1561,7 @@
       <end>\%{declaration-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="modifier"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="modifier-content"/>
       </include>
@@ -1575,6 +1587,7 @@
       <end>\%{declaration-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="declaration-value-content"/>
       </include>
@@ -1601,6 +1614,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="style-block-content"/>
       </include>
@@ -1705,6 +1719,7 @@
       <end>\%{test-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="media-feature-test-value-content"/>
       </include>
@@ -1724,6 +1739,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="test-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="test-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="media-feature-test-content"/>
       </include>
@@ -1753,6 +1769,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="at-rule-style-block-content"/>
       </include>
@@ -1772,6 +1789,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="at-rule-css-block-content"/>
       </include>
@@ -1795,6 +1813,7 @@
       <start>@\%{vendor-specific-identifier}</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="vendor-specific"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="at-rule-css-block"/>
         <context ref="at-rule-delimiter"/>
@@ -1809,6 +1828,8 @@
       <start case-sensitive="true">^@charset(?= "[^"]*";)</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
+        <context ref="comment"/>
         <context ref="double-quoted-string"/>
         <context ref="at-rule-delimiter"/>
       </include>
@@ -1817,6 +1838,8 @@
     <context id="at-charset-error" style-ref="error">
       <start>@charset\%]</start>
       <include>
+        <context ref="embedded-lang-hook"/>
+        <!-- no comment here -->
         <context ref="at-rule-delimiter"/>
       </include>
     </context>
@@ -1829,6 +1852,7 @@
       <start>@font-face\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="at-rule-style-block"/>
       </include>
@@ -1875,6 +1899,7 @@
       <end>\%{declaration-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="font-feature-value-declaration-value-content"/>
       </include>
@@ -1886,6 +1911,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="font-feature-value-declaration-name"/>
         <context ref="font-feature-value-declaration-value"/>
@@ -1899,6 +1925,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="font-feature-type-value"/>
         <context ref="at-font-feature-values-feature-value-block"/>
@@ -1909,6 +1936,7 @@
       <start>@font-feature-values\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="string-value"/>
         <context ref="name-value"/>
@@ -1924,6 +1952,7 @@
       <start>@import\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="url"/>
         <context ref="media-queries"/>
@@ -1956,6 +1985,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="keyframe-selector-value"/>
         <context ref="style-block"/>
@@ -1966,6 +1996,7 @@
       <start>@\%{vendor-specific-prefix}keyframes\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="vendor-specific"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="string-value"/>
         <context ref="name-value"/>
@@ -1977,6 +2008,7 @@
       <start>@keyframes\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="string-value"/>
         <context ref="name-value"/>
@@ -1992,6 +2024,7 @@
       <start>@media\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="media-queries"/>
         <context ref="at-rule-css-block"/>
@@ -2012,6 +2045,7 @@
       <start>@namespace\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="url"/>
         <context ref="string-value"/>
@@ -2061,6 +2095,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="block-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="declaration"/>
         <context ref="page-margin-box-types"/>
@@ -2072,6 +2107,7 @@
       <start>@page\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="pseudo-pages"/>
         <context ref="name-value"/>
@@ -2102,6 +2138,7 @@
       <end>\%{at-supports-declaration-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="declaration-value-content"/>
       </include>
@@ -2112,6 +2149,7 @@
       <end>\%{at-supports-declaration-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="modifier"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="modifier-content"/>
       </include>
@@ -2123,6 +2161,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="test-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="test-delimiter"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="at-supports-test"/>
         <context ref="at-supports-operators"/>
@@ -2136,6 +2175,7 @@
       <start>@supports\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="at-rule"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="at-supports-test"/>
         <context ref="at-supports-operators"/>
@@ -2218,6 +2258,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="attribute-selector"/>
         <context sub-pattern="0" where="end" style-ref="attribute-selector"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="attribute-selector-content"/>
       </include>
@@ -2332,6 +2373,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="pseudo-class"/>
         <context sub-pattern="0" where="end" style-ref="pseudo-class"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="lang-pseudo-class-argument-content"/>
       </include>
@@ -2341,6 +2383,8 @@
       <start>:not\(</start>
       <end>\)</end>
       <include>
+        <context ref="embedded-lang-hook"/>
+        <context ref="comment"/>
         <context ref="pseudo-class-argument"/>
       </include>
     </context>
@@ -2359,6 +2403,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="pseudo-class"/>
         <context sub-pattern="0" where="end" style-ref="pseudo-class"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="not-pseudo-class-nested-not-error"/>
         <context ref="not-pseudo-class-nested-pseudo-element-error"/>
@@ -2405,6 +2450,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="pseudo-class"/>
         <context sub-pattern="0" where="end" style-ref="pseudo-class"/>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="nth-pseudo-class-argument-content"/>
       </include>
@@ -2437,6 +2483,7 @@
 
     <context id="css" class="no-spell-check">
       <include>
+        <context ref="embedded-lang-hook"/>
         <context ref="comment"/>
         <context ref="at-rule"/>
         <context ref="selector"/>
diff --git a/data/language-specs/html.lang b/data/language-specs/html.lang
index 38539caf..191fe00a 100644
--- a/data/language-specs/html.lang
+++ b/data/language-specs/html.lang
@@ -308,13 +308,25 @@
           <include>
             <context sub-pattern="0" where="start" style-ref="tag"/>
             <context sub-pattern="0" where="end" style-ref="tag"/>
-            <context ref="embedded-lang-hook"/>
             <context ref="css:css"/>
           </include>
         </context>
       </include>
     </context>
 
+    <context id="css-embedded-lang-hook">
+      <include>
+        <context end-parent="true">
+          <start>(?=&lt;/style(?:&gt;|\s|$))</start>
+          <end>\%{def:always-match}</end>
+        </context>
+        <context ref="embedded-lang-hook"/>
+        <context ref="css:embedded-lang-hook" original="true"/>
+      </include>
+    </context>
+
+    <replace id="css:embedded-lang-hook" ref="css-embedded-lang-hook"/>
+
     <context id="script" class="no-spell-check">
       <start>&lt;script\%]</start>
       <include>
diff --git a/data/language-specs/less.lang b/data/language-specs/less.lang
index 00f18921..b310f33c 100644
--- a/data/language-specs/less.lang
+++ b/data/language-specs/less.lang
@@ -4,7 +4,7 @@
  This file is part of GtkSourceView
 
  Author: Jeffery To <jeffery to gmail com>
- Copyright (C) 2018 Jeffery To <jeffery to gmail com>
+ Copyright (C) 2018-2019 Jeffery To <jeffery to gmail com>
 
  GtkSourceView is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -65,9 +65,19 @@
       (?: ; | (?= } ) )
     </define-regex>
 
+    <context id="embedded-lang-hook"/>
+
+    <context id="less-embedded-lang-hook">
+      <include>
+        <context ref="embedded-lang-hook"/>
+        <context ref="css:embedded-lang-hook" original="true"/>
+      </include>
+    </context>
+
     <context id="single-line-comment" style-ref="css:comment" end-at-line-end="true" 
class-disabled="no-spell-check" class="comment">
       <start>//</start>
       <include>
+        <context ref="css:embedded-lang-hook"/>
         <!-- line continuations not allowed -->
         <context ref="def:in-comment"/>
       </include>
@@ -80,6 +90,7 @@
       </include>
     </context>
 
+    <replace id="css:embedded-lang-hook" ref="less-embedded-lang-hook"/>
     <replace id="css:comment" ref="less-comment"/>
 
 
@@ -97,6 +108,8 @@
       <start>@{</start>
       <end>}</end>
       <include>
+        <context ref="css:embedded-lang-hook"/>
+        <!-- no comment here -->
         <!-- nested interpolations are not documented but appear to work
              (functions as variable reference / indirection) -->
         <context ref="variable-interpolation-value"/>
@@ -164,6 +177,8 @@
       <start>~"</start>
       <end>"</end>
       <include>
+        <context ref="css:embedded-lang-hook"/>
+        <!-- no comment here -->
         <context ref="css:string-content"/>
       </include>
     </context>
@@ -172,6 +187,8 @@
       <start>~'</start>
       <end>'</end>
       <include>
+        <context ref="css:embedded-lang-hook"/>
+        <!-- no comment here -->
         <context ref="css:string-content"/>
       </include>
     </context>
@@ -189,6 +206,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="css:block-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:style-block-content"/>
       </include>
@@ -204,7 +222,8 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="variable"/>
         <context sub-pattern="0" where="end" style-ref="css:delimiter"/>
-        <!-- no comments allowed -->
+        <context ref="css:embedded-lang-hook"/>
+        <!-- no comment here -->
         <context ref="detached-ruleset-call-close-paren"/>
       </include>
     </context>
@@ -215,6 +234,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="group-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="group-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:data-value"/>
       </include>
@@ -226,6 +246,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="group-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="group-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
       </include>
@@ -253,6 +274,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:function"/>
         <context sub-pattern="0" where="end" style-ref="css:function"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:function-content"/>
       </include>
@@ -267,6 +289,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:function"/>
         <context sub-pattern="0" where="end" style-ref="css:function"/>
+        <context ref="css:embedded-lang-hook"/>
         <!-- only accept multi-line comments because // is part of urls -->
         <context ref="css:comment" original="true"/>
         <context ref="css:string-value"/>
@@ -417,6 +440,7 @@
       <end>\%{css:declaration-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:declaration-value-content"/>
       </include>
@@ -468,6 +492,7 @@
       <include>
         <context sub-pattern="1" where="start" style-ref="group-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="group-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <!-- options are passed to the plugin directly, not parsed by Less -->
       </include>
@@ -477,6 +502,7 @@
       <start>@plugin\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="at-plugin-options"/>
         <context ref="css:url"/>
@@ -492,6 +518,7 @@
       <end>\%{statement-end}</end>
       <include>
         <context sub-pattern="0" where="end" style-ref="css:delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:function-call"/>
       </include>
@@ -504,6 +531,7 @@
       <start case-sensitive="true">@charset\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <!-- though Less preserves quote type, which may be invalid -->
         <context ref="css:string"/>
@@ -552,6 +580,7 @@
       <include>
         <context sub-pattern="1" where="start" style-ref="group-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="group-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="less-at-import-options-keyword"/>
         <context ref="css:comma"/>
@@ -562,6 +591,7 @@
       <start>@import\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="less-at-import-options"/>
         <context ref="css:url"/>
@@ -613,6 +643,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="mixin-parameters-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="mixin-parameters-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
         <context ref="variable-arguments"/>
@@ -640,6 +671,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:test-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="css:test-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
         <context ref="guard-comparison-operator"/>
@@ -651,6 +683,7 @@
       <end>(?={)</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="guard-operator"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="guard-test"/>
         <context ref="guard-logical-operator"/>
@@ -688,6 +721,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:pseudo-class"/>
         <context sub-pattern="0" where="end" style-ref="css:pseudo-class"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="extend-pseudo-class-argument-keyword"/>
         <context ref="css:selector"/>
@@ -699,6 +733,7 @@
       <end>\%{statement-end}</end>
       <include>
         <context sub-pattern="0" where="end" style-ref="css:delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:selector"/>
       </include>
@@ -799,6 +834,7 @@
 
     <context id="less" class="no-spell-check">
       <include>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:at-rule"/> <!-- because Less variables look like at-rules -->
         <context ref="detached-ruleset-call"/>
diff --git a/data/language-specs/scss.lang b/data/language-specs/scss.lang
index b2c7bca7..32d7978c 100644
--- a/data/language-specs/scss.lang
+++ b/data/language-specs/scss.lang
@@ -4,7 +4,7 @@
  This file is part of GtkSourceView
 
  Author: Jeffery To <jeffery to gmail com>
- Copyright (C) 2018 Jeffery To <jeffery to gmail com>
+ Copyright (C) 2018-2019 Jeffery To <jeffery to gmail com>
 
  GtkSourceView is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
@@ -64,10 +64,20 @@
 
     <!-- global -->
 
+    <context id="embedded-lang-hook"/>
+
+    <context id="scss-embedded-lang-hook">
+      <include>
+        <context ref="embedded-lang-hook"/>
+        <context ref="css:embedded-lang-hook" original="true"/>
+      </include>
+    </context>
+
     <context id="scss-multiline-comment" style-ref="css:comment" class-disabled="no-spell-check" 
class="comment">
       <start>/\*</start>
       <end>\*/</end>
       <include>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="interpolation"/>
         <context ref="def:in-comment"/>
       </include>
@@ -76,6 +86,7 @@
     <context id="single-line-comment" style-ref="css:comment" end-at-line-end="true" 
class-disabled="no-spell-check" class="comment">
       <start>//</start>
       <include>
+        <context ref="css:embedded-lang-hook"/>
         <!-- line continuations not allowed -->
         <context ref="def:in-comment"/>
       </include>
@@ -88,6 +99,7 @@
       </include>
     </context>
 
+    <replace id="css:embedded-lang-hook" ref="scss-embedded-lang-hook"/>
     <replace id="css:multiline-comment" ref="scss-multiline-comment"/>
     <replace id="css:comment" ref="scss-comment"/>
 
@@ -100,6 +112,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="interpolation"/>
         <context sub-pattern="0" where="end" style-ref="interpolation"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
       </include>
@@ -165,6 +178,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="list-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="list-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
       </include>
@@ -177,6 +191,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="group-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="group-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:string-value"/>
       </include>
@@ -188,6 +203,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="group-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="group-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:data-value"/>
       </include>
@@ -203,6 +219,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="group-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="group-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
         <context ref="css:colon"/> <!-- for maps -->
@@ -234,6 +251,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:function"/>
         <context sub-pattern="0" where="end" style-ref="css:function"/>
+        <context ref="css:embedded-lang-hook"/>
         <!-- only accept multi-line comments because // is part of urls -->
         <context ref="css:comment" original="true"/>
         <context ref="css:string-value"/>
@@ -365,6 +383,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:block-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="css:block-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:declaration"/>
       </include>
@@ -423,6 +442,7 @@
       <end>\%{css:declaration-value-end}</end> <!-- nested-properties has end-parent="true" -->
       <include>
         <context sub-pattern="0" where="start" style-ref="css:delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:declaration-value-content"/>
       </include>
@@ -483,6 +503,7 @@
       <start>@extend\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:selector"/>
         <context ref="css:modifier"/>
@@ -511,6 +532,7 @@
       <end>\%{css:test-value-end}</end>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="interpolation"/>
         <context ref="variable"/>
@@ -524,6 +546,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:test-delimiter"/>
         <context sub-pattern="0" where="end" style-ref="css:test-delimiter"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="interpolation"/>
         <context ref="variable"/>
@@ -536,6 +559,7 @@
       <start>@at-root\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:selector"/>
         <context ref="at-at-root-query"/>
@@ -553,6 +577,7 @@
       <start>@(debug|warn|error)\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
         <context ref="css:at-rule-delimiter"/>
@@ -569,6 +594,7 @@
       <start>@(if|else\s+if)\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
         <context ref="css:at-rule-css-block"/>
@@ -579,6 +605,7 @@
       <start>@else\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:at-rule-css-block"/>
       </include>
@@ -598,6 +625,7 @@
       <start>@for\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="at-for-keyword"/>
         <context ref="variable"/>
@@ -618,6 +646,7 @@
       <start>@each\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="at-each-keyword"/>
         <context ref="variable"/>
@@ -635,6 +664,7 @@
       <start>@while\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
         <context ref="css:at-rule-css-block"/>
@@ -651,6 +681,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="mixin-name"/>
         <context sub-pattern="0" where="end" style-ref="mixin-name"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:function-content"/>
       </include>
@@ -660,6 +691,7 @@
       <start>@mixin\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:name" style-ref="mixin-name"/>
         <context ref="mixin-parameters"/>
@@ -675,6 +707,7 @@
       <start>@include\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:name" style-ref="mixin-name"/>
         <context ref="mixin-parameters"/>
@@ -691,6 +724,7 @@
       <start>@content\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:at-rule-delimiter"/>
       </include>
@@ -706,6 +740,7 @@
       <include>
         <context sub-pattern="0" where="start" style-ref="css:function"/>
         <context sub-pattern="0" where="end" style-ref="css:function"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:function-content"/>
       </include>
@@ -715,6 +750,7 @@
       <start>@function\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <!-- we define it this way because there can be whitespace
              between the function name and the parentheses -->
@@ -732,6 +768,7 @@
       <start>@return\%]</start>
       <include>
         <context sub-pattern="0" where="start" style-ref="css:at-rule"/>
+        <context ref="css:embedded-lang-hook"/>
         <context ref="css:comment"/>
         <context ref="css:any-value"/>
         <context ref="css:at-rule-delimiter"/>
diff --git a/tests/syntax-highlighting/file.html b/tests/syntax-highlighting/file.html
index 0183fbb1..f23f2538 100644
--- a/tests/syntax-highlighting/file.html
+++ b/tests/syntax-highlighting/file.html
@@ -4,17 +4,30 @@
   <head>
     <title>Hi there!</title>
     <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
+
     <style type="text/css">
       a.summary-letter {text-decoration: none}
       pre.display {font-family: serif}
       pre.format {font-family: serif}
     </style>
+
+    <style>body {</style>
+    <style>body[id=</style>
+    <style>body { color:</style>
+    <style>body:after { content: "</style>
+    <style>body { background-image: url(</style>
+    <style>@keyframes foo {</style>
+    <style>@media (</style>
+    <style>@media screen {</style>
+    <style>/*</style>
+
     <script type="text/javascript">
       window.addEventListener('click', function (e) {
         e.preventDefault();
         alert('Hi there!');
       }, false);
     </script>
+
     <script>a = "double-quoted string</script>
     <script>a = 'single-quoted string</script>
     <script>a = /regular expression</script>
@@ -24,6 +37,7 @@
     <script>/** {number </script>
     <script>/** {@link </script>
     <script>/** @param {string} </script>
+
   </head>
   <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF"
         vlink="#800080" alink="#FF0000">
diff --git a/tests/syntax-highlighting/file.php b/tests/syntax-highlighting/file.php
index 992375b8..b60e0f45 100644
--- a/tests/syntax-highlighting/file.php
+++ b/tests/syntax-highlighting/file.php
@@ -24,3 +24,36 @@ a
 b
 ENDING
 END, 'd e f'];
+?>
+
+<!-- PHP embedded: -->
+
+<!-- Inside JavaScript -->
+<script>
+var one = '<?php echo 'Hello World'; ?>';
+var two = '<?php echo "Hello World"; ?>';
+var thr = "<?php echo 'Hello World'; ?>";
+var fou = "<?php echo "Hello World"; ?>";
+
+var num = <?php echo '3'; ?>;
+var re  = /<?php echo 'Hello World'; ?>/;
+var tpl = `<?php echo 'Hello World'; ?>`;
+</script>
+
+<!-- Inside CSS -->
+<style>
+@import url(<?php echo $css_url; ?>);
+@import url('<?php echo $another_url; ?>');
+@import url("<?php echo $some_other_url; ?>");
+
+h1 {
+    border-<?php echo $dir; ?>-color: black;
+    color: <?php echo $color; ?>;
+}
+</style>
+
+<!-- Inside HTML -->
+<img src='<?php echo $Image['one']; ?>' />
+<img src='<?php echo $Image["two"]; ?>' />
+<img src="<?php echo $Image['thr']; ?>" />
+<img src="<?php echo $Image["fou"]; ?>" />


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