diff options
-rw-r--r-- | pygments/lexers/javascript.py | 9 | ||||
-rw-r--r-- | pygments/lexers/jvm.py | 19 | ||||
-rw-r--r-- | pygments/lexers/make.py | 2 | ||||
-rw-r--r-- | tests/examplefiles/interp.scala | 10 | ||||
-rw-r--r-- | tests/examplefiles/unicode.js | 5 | ||||
-rw-r--r-- | tests/examplefiles/vpath.mk | 16 |
6 files changed, 55 insertions, 6 deletions
diff --git a/pygments/lexers/javascript.py b/pygments/lexers/javascript.py index 968436ed..8b5f9c76 100644 --- a/pygments/lexers/javascript.py +++ b/pygments/lexers/javascript.py @@ -16,11 +16,18 @@ from pygments.lexer import RegexLexer, include, bygroups, default, \ from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ Number, Punctuation, Other from pygments.util import get_bool_opt, iteritems +import pygments.unistring as uni __all__ = ['JavascriptLexer', 'KalLexer', 'LiveScriptLexer', 'DartLexer', 'TypeScriptLexer', 'LassoLexer', 'ObjectiveJLexer', 'CoffeeScriptLexer', 'MaskLexer'] +JS_IDENT_START = ('(?:[$_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Lo + uni.Nl + + ']|\\\\u[a-fA-F0-9]{4})') +JS_IDENT_PART = ('(?:[$_' + uni.Lu + uni.Ll + uni.Lt + uni.Lm + uni.Lo + uni.Nl + + uni.Mn + uni.Mc + uni.Nd + uni.Pc + + u'\u200c\u200d]|\\\\u[a-fA-F0-9]{4})') +JS_IDENT = JS_IDENT_START + '(?:' + JS_IDENT_PART + ')*' class JavascriptLexer(RegexLexer): """ @@ -72,7 +79,7 @@ class JavascriptLexer(RegexLexer): r'decodeURIComponent|encodeURI|encodeURIComponent|' r'Error|eval|isFinite|isNaN|parseFloat|parseInt|document|this|' r'window)\b', Name.Builtin), - (r'[$a-zA-Z_]\w*', Name.Other), + (JS_IDENT, Name.Other), (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float), (r'0x[0-9a-fA-F]+', Number.Hex), (r'[0-9]+', Number.Integer), diff --git a/pygments/lexers/jvm.py b/pygments/lexers/jvm.py index c5fe49f6..86a45d1e 100644 --- a/pygments/lexers/jvm.py +++ b/pygments/lexers/jvm.py @@ -244,6 +244,7 @@ class ScalaLexer(RegexLexer): u'\ua77d-\ua77e\ua780\ua782\ua784\ua786\ua78b\uff21-\uff3a]') idrest = u'%s(?:%s|[0-9])*(?:(?<=_)%s)?' % (letter, letter, op) + letter_letter_digit = u'%s(?:%s|\d)*' % (letter, letter) tokens = { 'root': [ @@ -268,6 +269,7 @@ class ScalaLexer(RegexLexer): (r'""".*?"""(?!")', String), (r'"(\\\\|\\"|[^"])*"', String), (r"'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'", String.Char), + (r'[fs]"""', String, 'interptriplestring'), # interpolated strings (r'[fs]"', String, 'interpstring'), # interpolated strings (r'raw"(\\\\|\\"|[^"])*"', String), # raw strings # (ur'(\.)(%s|%s|`[^`]+`)' % (idrest, op), bygroups(Operator, @@ -322,18 +324,27 @@ class ScalaLexer(RegexLexer): 'import': [ (u'(%s|\\.)+' % idrest, Name.Namespace, '#pop') ], - 'interpstring': [ - (r'[^"$\\]', String), - (r'\$\{', String.Interpol, 'interpbrace'), + 'interpstringcommon': [ + (r'[^"$\\]+', String), (r'\$\$', String), + (r'\$' + letter_letter_digit, String.Interpol), + (r'\$\{', String.Interpol, 'interpbrace'), (r'\\.', String), + ], + 'interptriplestring': [ + (r'"""(?!")', String, '#pop'), + (r'"', String), + include('interpstringcommon'), + ], + 'interpstring': [ (r'"', String, '#pop'), + include('interpstringcommon'), ], 'interpbrace': [ (r'\}', String.Interpol, '#pop'), (r'\{', String.Interpol, '#push'), include('root'), - ] + ], } diff --git a/pygments/lexers/make.py b/pygments/lexers/make.py index 88957896..76ca7376 100644 --- a/pygments/lexers/make.py +++ b/pygments/lexers/make.py @@ -38,7 +38,7 @@ class MakefileLexer(Lexer): # BSD Make r'\.\s*(include|undef|error|warning|if|else|elif|endif|for|endfor)|' # GNU Make - r'\s*(ifeq|ifneq|ifdef|ifndef|else|endif|-?include|define|endef|:))(?=\s)') + r'\s*(ifeq|ifneq|ifdef|ifndef|else|endif|-?include|define|endef|:|vpath))(?=\s)') r_comment = re.compile(r'^\s*@?#') def get_tokens_unprocessed(self, text): diff --git a/tests/examplefiles/interp.scala b/tests/examplefiles/interp.scala new file mode 100644 index 00000000..4131b75e --- /dev/null +++ b/tests/examplefiles/interp.scala @@ -0,0 +1,10 @@ +val n = 123; +val a = s"n=$n"; +val a2 = s"n=$n''"; +val b = s"""n=$n"""; +val c = f"n=$n%f"; +val d = f"""n=$n%f"""; +val d2 = s"""a""""; +val e = s"abc\u00e9"; +val f = s"a${n}b"; +val g = s"a${n + 1}b"; diff --git a/tests/examplefiles/unicode.js b/tests/examplefiles/unicode.js new file mode 100644 index 00000000..e77bfb80 --- /dev/null +++ b/tests/examplefiles/unicode.js @@ -0,0 +1,5 @@ +var école; +var sinθ; +var เมือง; +var a\u1234b; + diff --git a/tests/examplefiles/vpath.mk b/tests/examplefiles/vpath.mk new file mode 100644 index 00000000..a7f18fc3 --- /dev/null +++ b/tests/examplefiles/vpath.mk @@ -0,0 +1,16 @@ +vpath %.c src +vpath %.h header +EXEC=hello +SRC= hello.c main.c +OBJ= $(SRC:.c=.o) + +all: $(EXEC) + +hello: $(OBJ) + $(CC) -o $@ $^ $(LDFLAGS) + +main.o: hello.h + +%.o: %.c + $(CC) -I header -o $@ \ + -c $< $(CFLAGS) |