[gtksourceview: 1/2] javascript.lang (and family): Add own comment contexts



commit ad918159855d523942004562ad308461d5a122cf
Author: Jeffery To <jeffery to gmail com>
Date:   Sat Nov 30 07:41:01 2019 +0800

    javascript.lang (and family): Add own comment contexts
    
    This adds a multiline-comment context and comment-content context to
    javascript.lang, and updates the other comment contexts to use the new
    comment-content context. (This also renames the other comment contexts.)
    
    This removes the need to override (<replace>) def:in-comment, to avoid
    the issue described in
    https://gitlab.gnome.org/GNOME/gtksourceview/issues/97.

 data/language-specs/javascript.lang     | 77 ++++++++++++++++++---------------
 data/language-specs/objj.lang           |  9 ++--
 data/language-specs/typescript-jsx.lang |  4 +-
 data/language-specs/typescript.lang     |  9 ++--
 4 files changed, 56 insertions(+), 43 deletions(-)
---
diff --git a/data/language-specs/javascript.lang b/data/language-specs/javascript.lang
index 2806283a..42ec61c8 100644
--- a/data/language-specs/javascript.lang
+++ b/data/language-specs/javascript.lang
@@ -320,41 +320,45 @@
 
     <!-- ## Comments -->
 
-    <context id="_in-comment" class-disabled="no-spell-check">
+    <context id="_comment-content" class-disabled="no-spell-check">
       <include>
         <context ref="embedded-lang-hooks"/>
-        <context ref="def:in-comment" original="true"/>
+        <context ref="def:in-comment"/>
       </include>
-    </context> <!-- /_in-comment -->
-
-    <replace id="def:in-comment" ref="_in-comment"/>
+    </context> <!-- /_comment-content -->
 
-    <!-- includes def:in-comment instead of def:in-line-comment,
-         because line continuations are not allowed inside single-line
-         comments -->
-    <context id="_c-like-comment" style-ref="comment" end-at-line-end="true" class-disabled="no-spell-check" 
class="comment">
+    <!-- line continuations are not allowed inside single-line comments -->
+    <context id="_single-line-comments" style-ref="comment" end-at-line-end="true" 
class-disabled="no-spell-check" class="comment">
       <start>//</start>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="_comment-content"/>
       </include>
-    </context> <!-- /_c-like-comment -->
+    </context> <!-- /_single-line-comments -->
 
-    <context id="_c-like-comment-no-extend-parent" style-ref="comment" end-at-line-end="true" 
class-disabled="no-spell-check" class="comment" extend-parent="false">
+    <context id="_multiline-comments" style-ref="comment" class-disabled="no-spell-check" class="comment">
+      <start>/\*</start>
+      <end>\*/</end>
+      <include>
+        <context ref="_comment-content"/>
+      </include>
+    </context> <!-- /_multiline-comments -->
+
+    <context id="_single-line-comments-no-extend-parent" style-ref="comment" end-at-line-end="true" 
class-disabled="no-spell-check" class="comment" extend-parent="false">
       <start>//</start>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="_comment-content"/>
       </include>
-    </context> <!-- /_c-like-comment-no-extend-parent -->
+    </context> <!-- /_single-line-comments-no-extend-parent -->
 
-    <context id="_c-like-comment-multiline-no-extend-parent" style-ref="comment" 
class-disabled="no-spell-check" class="comment" extend-parent="false">
+    <context id="_multiline-comments-no-extend-parent" style-ref="comment" class-disabled="no-spell-check" 
class="comment" extend-parent="false">
       <start>/\*</start>
       <end>\*/</end>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="_comment-content"/>
       </include>
-    </context> <!-- /_c-like-comment-multiline-no-extend-parent -->
+    </context> <!-- /_multiline-comments-no-extend-parent -->
 
-    <context id="jsdoc-embedded-lang-hooks">
+    <context id="_jsdoc-embedded-lang-hooks">
       <include>
         <context ref="embedded-lang-hooks"/>
 
@@ -365,33 +369,38 @@
 
         <context ref="jsdoc:embedded-lang-hooks" original="true"/>
       </include>
-    </context>
+    </context> <!-- /_jsdoc-embedded-lang-hooks -->
+
+    <replace id="jsdoc:embedded-lang-hooks" ref="_jsdoc-embedded-lang-hooks"/>
 
-    <replace id="jsdoc:embedded-lang-hooks" ref="jsdoc-embedded-lang-hooks"/>
+    <context id="_doc-comment-content">
+      <include>
+        <context ref="_comment-content"/>
+        <context ref="jsdoc:jsdoc"/>
+      </include>
+    </context> <!-- /_doc-comment-content -->
 
-    <context id="doc-comment" style-ref="doc-comment" class-disabled="no-spell-check" class="comment">
+    <context id="_doc-comments" style-ref="doc-comment" class-disabled="no-spell-check" class="comment">
       <start>/\*\*(?![\*/])</start>
       <end>\*/</end>
       <include>
-        <context ref="def:in-comment"/>
-        <context ref="jsdoc:jsdoc"/>
+        <context ref="_doc-comment-content"/>
       </include>
-    </context> <!-- /doc-comment -->
+    </context> <!-- /_doc-comments -->
 
-    <context id="doc-comment-no-extend-parent" style-ref="doc-comment" class-disabled="no-spell-check" 
class="comment" extend-parent="false">
+    <context id="_doc-comments-no-extend-parent" style-ref="doc-comment" class-disabled="no-spell-check" 
class="comment" extend-parent="false">
       <start>/\*\*(?![\*/])</start>
       <end>\*/</end>
       <include>
-        <context ref="def:in-comment"/>
-        <context ref="jsdoc:jsdoc"/>
+        <context ref="_doc-comment-content"/>
       </include>
-    </context> <!-- /doc-comment-no-extend-parent -->
+    </context> <!-- /_doc-comments-no-extend-parent -->
 
     <context id="comments">
       <include>
-        <context ref="_c-like-comment"/>
-        <context ref="doc-comment"/>
-        <context ref="def:c-like-comment-multiline" style-ref="comment"/>
+        <context ref="_single-line-comments"/>
+        <context ref="_doc-comments"/>
+        <context ref="_multiline-comments"/>
         <context ref="def:c-like-close-comment-outside-comment" style-ref="error"/>
       </include>
     </context> <!-- /comments -->
@@ -399,9 +408,9 @@
     <!-- for statements that cannot contain line terminators -->
     <context id="comments-no-extend-parent">
       <include>
-        <context ref="_c-like-comment-no-extend-parent"/>
-        <context ref="doc-comment-no-extend-parent"/>
-        <context ref="_c-like-comment-multiline-no-extend-parent"/>
+        <context ref="_single-line-comments-no-extend-parent"/>
+        <context ref="_doc-comments-no-extend-parent"/>
+        <context ref="_multiline-comments-no-extend-parent"/>
         <context ref="def:c-like-close-comment-outside-comment" style-ref="error"/>
       </include>
     </context> <!-- /comments-no-extend-parent -->
diff --git a/data/language-specs/objj.lang b/data/language-specs/objj.lang
index bdc14675..8a0d8381 100644
--- a/data/language-specs/objj.lang
+++ b/data/language-specs/objj.lang
@@ -387,13 +387,14 @@
     <replace id="js:embedded-lang-hooks" ref="_embedded-lang-hooks"/>
 
     <!-- ignore preprocessor directives inside comments -->
-    <context id="_in-comment" class-disabled="no-spell-check">
+    <context id="_comment-content" class-disabled="no-spell-check">
       <include>
-        <context ref="def:in-comment" original="true"/>
+        <context ref="js:embedded-lang-hooks" original="true"/>
+        <context ref="def:in-comment"/>
       </include>
-    </context> <!-- /_in-comment -->
+    </context> <!-- /_comment-content -->
 
-    <replace id="def:in-comment" ref="_in-comment"/>
+    <replace id="js:_comment-content" ref="_comment-content"/>
 
 
     <!-- ## Literals -->
diff --git a/data/language-specs/typescript-jsx.lang b/data/language-specs/typescript-jsx.lang
index bc9dda78..d3a1f4a6 100644
--- a/data/language-specs/typescript-jsx.lang
+++ b/data/language-specs/typescript-jsx.lang
@@ -65,7 +65,7 @@
       </start>
       <end>\*/</end>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="js:_comment-content"/>
       </include>
     </context> <!-- /_jsx-comment-pragmas -->
 
@@ -75,7 +75,7 @@
       </start>
       <end>\*/</end>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="js:_comment-content"/>
       </include>
     </context> <!-- /_jsx-comment-pragmas-no-extend-parent -->
 
diff --git a/data/language-specs/typescript.lang b/data/language-specs/typescript.lang
index 54858210..fc19676e 100644
--- a/data/language-specs/typescript.lang
+++ b/data/language-specs/typescript.lang
@@ -157,7 +157,7 @@
         ///? \%{js:whitespace}* @ts-ignore \%]
       </start>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="js:_comment-content"/>
       </include>
     </context> <!-- /_ts-ignore-comment-pragmas -->
 
@@ -166,7 +166,7 @@
         ///? \%{js:whitespace}* @ts-ignore \%]
       </start>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="js:_comment-content"/>
       </include>
     </context> <!-- /_ts-ignore-comment-pragmas-no-extend-parent -->
 
@@ -184,7 +184,7 @@
         ///? \s* @ts-nocheck \%]
       </start>
       <include>
-        <context ref="def:in-comment"/>
+        <context ref="js:_comment-content"/>
       </include>
     </context> <!-- /_ts-nocheck-comment-pragmas -->
 
@@ -208,6 +208,9 @@
         )
         \%{js:whitespace}
       </start>
+      <include>
+        <context ref="js:_comment-content"/>
+      </include>
     </context> <!-- /_triple-slash-directives -->
 
     <!-- ## Namespace name


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