[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 9b77d64 15/45: Implement template strings, ignoring substi
From: |
Dmitry Gutov |
Subject: |
[elpa] master 9b77d64 15/45: Implement template strings, ignoring substitutions |
Date: |
Mon, 02 Feb 2015 03:18:38 +0000 |
branch: master
commit 9b77d64ef45d976652b2f296829b60fe96b1afaf
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Implement template strings, ignoring substitutions
Issue #153
---
js2-mode.el | 25 ++++++++++++++++---------
tests/parser.el | 3 +++
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 4ffb4d3..623c3fe 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -664,8 +664,9 @@ which doesn't seem particularly useful, but Rhino permits
it."
(defvar js2-EXTENDS 164)
(defvar js2-STATIC 165)
(defvar js2-SUPER 166)
+(defvar js2-TEMPLATE_STRING 167)
-(defconst js2-num-tokens (1+ js2-SUPER))
+(defconst js2-num-tokens (1+ js2-TEMPLATE_STRING))
(defconst js2-debug-print-trees nil)
@@ -5349,7 +5350,7 @@ into temp buffers."
""
(let ((name (js2-tt-name token)))
(cond
- ((memq token (list js2-STRING js2-REGEXP js2-NAME))
+ ((memq token (list js2-STRING js2-REGEXP js2-NAME js2-TEMPLATE_STRING))
(concat name " `" (js2-current-token-string) "'"))
((eq token js2-NUMBER)
(format "NUMBER %g" (js2-token-number (js2-current-token))))
@@ -5395,6 +5396,7 @@ into temp buffers."
(aset table i 'font-lock-keyword-face))
(aset table js2-STRING 'font-lock-string-face)
(aset table js2-REGEXP 'font-lock-string-face)
+ (aset table js2-TEMPLATE_STRING 'font-lock-string-face)
(aset table js2-COMMENT 'font-lock-comment-face)
(aset table js2-THIS 'font-lock-builtin-face)
(aset table js2-SUPER 'font-lock-builtin-face)
@@ -5722,7 +5724,7 @@ its relevant fields and puts it into `js2-ti-tokens'."
(js2-string-to-number str base)))
(throw 'return js2-NUMBER))
;; is it a string?
- (when (memq c '(?\" ?\'))
+ (when (memq c '(?\" ?\' ?`))
;; We attempt to accumulate a string the fast way, by
;; building it directly out of the reader. But if there
;; are any escaped characters in the string, we revert to
@@ -5733,11 +5735,14 @@ its relevant fields and puts it into `js2-ti-tokens'."
(catch 'break
(while (/= c quote-char)
(catch 'continue
- (when (or (eq c ?\n) (eq c js2-EOF_CHAR))
+ (when (eq c js2-EOF_CHAR)
(js2-unget-char)
- (setf (js2-token-end token) js2-ts-cursor)
(js2-report-error "msg.unterminated.string.lit")
- (throw 'return js2-STRING))
+ (throw 'break nil))
+ (when (and (eq c ?\n) (not (eq quote-char ?`)))
+ (js2-unget-char)
+ (js2-report-error "msg.unterminated.string.lit")
+ (throw 'break nil))
(when (eq c ?\\)
;; We've hit an escaped character
(setq c (js2-get-char))
@@ -5819,7 +5824,9 @@ its relevant fields and puts it into `js2-ti-tokens'."
(js2-add-to-string c)
(setq c (js2-get-char)))))
(js2-set-string-from-buffer token)
- (throw 'return js2-STRING))
+ (throw 'return (if (eq quote-char ?`)
+ js2-TEMPLATE_STRING
+ js2-STRING)))
(js2-ts-return token
(case c
(?\;
@@ -9346,9 +9353,9 @@ array-literals, array comprehensions and regular
expressions."
(js2-parse-name tt))
((= tt js2-NUMBER)
(make-js2-number-node))
- ((= tt js2-STRING)
+ ((or (= tt js2-STRING) (= tt js2-TEMPLATE_STRING))
(prog1
- (make-js2-string-node)
+ (make-js2-string-node :type tt)
(js2-record-face 'font-lock-string-face)))
((or (= tt js2-DIV) (= tt js2-ASSIGN_DIV))
;; Got / or /= which in this context means a regexp literal
diff --git a/tests/parser.el b/tests/parser.el
index ade10d8..8bf051f 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -343,6 +343,9 @@ the test."
(js2-deftest-parse object-get-string-literal
"var x = {y: 5};\nvar z = x[\"y\"];")
+(js2-deftest-parse template-string
+ "var x = `${a + b}`, y = `\\u0000`;")
+
;;; Classes
(js2-deftest-parse parse-harmony-class-statement
- [elpa] master 926cb45 05/45: Support ES6 computed property names., (continued)
- [elpa] master 926cb45 05/45: Support ES6 computed property names., Dmitry Gutov, 2015/02/01
- [elpa] master 30249fa 07/45: Support parsing the ES6 'static' keyword., Dmitry Gutov, 2015/02/01
- [elpa] master c79d426 06/45: Support ES6 class statements/expressions., Dmitry Gutov, 2015/02/01
- [elpa] master 2b0f5ba 08/45: Support parsing the ES6 'super' keyword., Dmitry Gutov, 2015/02/01
- [elpa] master dd344ff 01/45: Support short-hand object literals {foo, bar} everywhere., Dmitry Gutov, 2015/02/01
- [elpa] master b1f7e6c 11/45: Simplify parsing of destructuring literals, Dmitry Gutov, 2015/02/01
- [elpa] master 68b4abd 02/45: Add ES6 class externs, Dmitry Gutov, 2015/02/01
- [elpa] master ee17084 13/45: js2-parse-plain-property: Disallow numbers as abbreviated props, Dmitry Gutov, 2015/02/01
- [elpa] master b19ea52 12/45: js2-parse-named-prop: Highlight externals in abbreviated props, Dmitry Gutov, 2015/02/01
- [elpa] master 31c49e0 14/45: js2-imenu-extension-styles: Turn into defvar, Dmitry Gutov, 2015/02/01
- [elpa] master 9b77d64 15/45: Implement template strings, ignoring substitutions,
Dmitry Gutov <=
- [elpa] master 7b3d590 17/45: No need to explicitly apply face to string nodes, Dmitry Gutov, 2015/02/01
- [elpa] master 3f09ff3 09/45: Fix string literals in parser.el test harness., Dmitry Gutov, 2015/02/01
- [elpa] master d0c6bf3 18/45: Comment the new token types, Dmitry Gutov, 2015/02/01
- [elpa] master 9525eb3 10/45: Merge branch 'master' of github.com:shicks/js2-mode into shicks-master, Dmitry Gutov, 2015/02/01
- [elpa] master c910d1b 19/45: Parse tagged templates, Dmitry Gutov, 2015/02/01
- [elpa] master 8df508e 16/45: Handle template substitutions, Dmitry Gutov, 2015/02/01
- [elpa] master 92063fe 22/45: Fix js2-visit-tagged-template, Dmitry Gutov, 2015/02/01
- [elpa] master 94c2ec9 20/45: Drop `js2-allow-keywords-as-property-names' and `js2-valid-prop-name-token', Dmitry Gutov, 2015/02/01
- [elpa] master ab82544 23/45: Do not declare fn expression's name in the enclosing scope, Dmitry Gutov, 2015/02/01
- [elpa] master e6dc986 24/45: Limit the scope of `with-silent-modifications', Dmitry Gutov, 2015/02/01