[gtksourceview/gnome-3-18] Add highlighting for ES6 Template Strings
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/gnome-3-18] Add highlighting for ES6 Template Strings
- Date: Sat, 23 Apr 2016 12:35:07 +0000 (UTC)
commit 4ecd0e6c08a3ddfe3ad8e7328cff9f924326b68f
Author: Tobias Schönberg <tobias47n9e gmail com>
Date: Sun Jan 31 14:42:04 2016 +0100
Add highlighting for ES6 Template Strings
Template strings are part of ES6 and are currently not
highlighted as strings. This patch adds a context that
gives template strings the same color as single-quoted
and double-quoted strings. The brackets of the template
expressions are given the color of functions. The
expressions themselves are highlighted as functions
too.
https://bugzilla.gnome.org/show_bug.cgi?id=758024
Fixes #758024
data/language-specs/javascript.lang | 12 ++++++++++++
tests/syntax-highlighting/file.js | 12 ++++++++++++
2 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/data/language-specs/javascript.lang b/data/language-specs/javascript.lang
index 4ac3406..c9cdc88 100644
--- a/data/language-specs/javascript.lang
+++ b/data/language-specs/javascript.lang
@@ -309,6 +309,17 @@
<keyword>static</keyword>
</context>
+ <context id="template-string" style-ref="string">
+ <start>`</start>
+ <end>`</end>
+ <include>
+ <context id="template-expression" style-ref="function">
+ <start>\$\{</start>
+ <end>\}</end>
+ </context>
+ </include>
+ </context>
+
<!--main context-->
<context id="js" class="no-spell-check">
<include>
@@ -317,6 +328,7 @@
<context ref="def:c-like-close-comment-outside-comment"/>
<context ref="def:string" style-ref="string"/>
<context ref="def:single-quoted-string" style-ref="string"/>
+ <context ref="template-string"/>
<context ref="def:float"/>
<context ref="def:decimal"/>
<context ref="def:octal"/>
diff --git a/tests/syntax-highlighting/file.js b/tests/syntax-highlighting/file.js
index 4480c4e..78cf4ef 100644
--- a/tests/syntax-highlighting/file.js
+++ b/tests/syntax-highlighting/file.js
@@ -13,3 +13,15 @@ var matches = /abc/.exec('Alphabet ... that should contain abc, right?');
a = [thing / thing, thing / thing];
x = a /b/ c / d;
+// Template strings
+// ----------------
+// Template strings are delimited by back-ticks (grave accent) and
+// can span multiple lines. They allow for expressions that inside
+// of a dollar-sign plus curly-bracket construct (${...}).
+
+console.log(`The sum of 2 and 2 is ${2 + 2}`);
+
+let y = 8;
+let my_string = `This is a multiline
+string that also contains
+a template ${y + (4.1 - 2.2)}`;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]