diff --git a/src/calibre/gui2/tweak_book/editor/syntax/javascript.py b/src/calibre/gui2/tweak_book/editor/syntax/javascript.py new file mode 100644 index 0000000000..9971e3845c --- /dev/null +++ b/src/calibre/gui2/tweak_book/editor/syntax/javascript.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8 +from __future__ import (unicode_literals, division, absolute_import, + print_function) + +__license__ = 'GPL v3' +__copyright__ = '2014, Kovid Goyal ' + +import re + +from pygments.lexer import RegexLexer, default, include +from pygments.token import Comment, Punctuation, Number, Keyword, Text, String, Operator, Name +import pygments.unistring as uni + +from calibre.gui2.tweak_book.editor.syntax.pygments_highlighter import create_highlighter + +JS_IDENT_START = ('(?:[$_' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl') + + ']|\\\\u[a-fA-F0-9]{4})') +JS_IDENT_PART = ('(?:[$' + uni.combine('Lu', 'Ll', 'Lt', 'Lm', 'Lo', 'Nl', + 'Mn', 'Mc', 'Nd', 'Pc') + + u'\u200c\u200d]|\\\\u[a-fA-F0-9]{4})') +JS_IDENT = JS_IDENT_START + '(?:' + JS_IDENT_PART + ')*' + +class JavascriptLexer(RegexLexer): + + """ + For JavaScript source code. This is based on the pygments JS highlighter, + bu that does not handle multi-line comments in streaming mode, so we had to + modify it. + """ + + flags = re.DOTALL | re.UNICODE | re.MULTILINE + + tokens = { + b'commentsandwhitespace': [ + (r'\s+', Text), + (r'