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
commit3ad1b2652867b6cefb86c926485ee2548d1fa9bb (patch)
tree50fa824a7146cc0eada599e4d8fd357da643717d /pygments/lexers/javascript.py
parentea95104deb403304e33e2062c75e0aca7be0dc07 (diff)
downloadpygments-git-3ad1b2652867b6cefb86c926485ee2548d1fa9bb.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'),
+ ],
}