summaryrefslogtreecommitdiff
path: root/pygments/lexers/javascript.py
diff options
context:
space:
mode:
authorChristian Hammond <christian@beanbaginc.com>2017-01-20 12:34:14 -0800
committerChristian Hammond <christian@beanbaginc.com>2017-01-20 12:34:14 -0800
commit92548bffdfcd6f26c4f957d807d29d3173febd38 (patch)
treee77fdf39e676e0820deb52bb5191236383076047 /pygments/lexers/javascript.py
parentf7aac3cab93586036b66c7a05f6a33db96bfb1b1 (diff)
downloadpygments-92548bffdfcd6f26c4f957d807d29d3173febd38.tar.gz
Add support for string literals to TypeScriptLexer.
This introduces support for string literals to the TypeScript lexer. The rules are consistent with those in JavascriptLexer, helping to ensure the same behavior and capabilities between the two.
Diffstat (limited to 'pygments/lexers/javascript.py')
-rw-r--r--pygments/lexers/javascript.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py
index 4b47b15a..b379fc02 100644
--- a/pygments/lexers/javascript.py
+++ b/pygments/lexers/javascript.py
@@ -511,9 +511,26 @@ class TypeScriptLexer(RegexLexer):
(r'[0-9]+', Number.Integer),
(r'"(\\\\|\\"|[^"])*"', String.Double),
(r"'(\\\\|\\'|[^'])*'", String.Single),
+ (r'`', String.Backtick, 'interp'),
# Match stuff like: Decorators
(r'@\w+', Keyword.Declaration),
- ]
+ ],
+
+ # The 'interp*' rules match those in JavascriptLexer. Changes made
+ # there should be reflected here as well.
+ 'interp': [
+ (r'`', String.Backtick, '#pop'),
+ (r'\\\\', String.Backtick),
+ (r'\\`', String.Backtick),
+ (r'\$\{', String.Interpol, 'interp-inside'),
+ (r'\$', String.Backtick),
+ (r'[^`\\$]+', String.Backtick),
+ ],
+ 'interp-inside': [
+ # TODO: should this include single-line comments and allow nesting strings?
+ (r'\}', String.Interpol, '#pop'),
+ include('root'),
+ ],
}