From 060475ce4d2ed1f7a235bae5d8c2eecf6386a8ec Mon Sep 17 00:00:00 2001 From: Kevin Locke Date: Thu, 9 Jan 2020 16:59:04 -0700 Subject: [PATCH] Only highlight control escapes in RegExp The `\\c + ASCII letter` escape sequence is not specified as part of the [EscapeSequence] production in the grammar for strings. It behaves like any other unspecified character by ignoring the backslash. The escape sequence is only specified as part of the [CharacterEscape] production in the grammar for RegExp patterns, where it matches a character with the letter's codepoint mod 32 (which is the same for uppercase and lowercase ASCII letters). Update the syntax to highlight both uppercase and lowercase letters in RegExp and neither in strings. [CharacterEscape]: https://www.ecma-international.org/ecma-262/#prod-CharacterEscape [EscapeSequence]: https://www.ecma-international.org/ecma-262/#prod-EscapeSequence Signed-off-by: Kevin Locke --- syntax/javascript.vim | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/syntax/javascript.vim b/syntax/javascript.vim index c8daec93..9f4d7ef1 100644 --- a/syntax/javascript.vim +++ b/syntax/javascript.vim @@ -59,9 +59,10 @@ syntax keyword jsNumber Infinity syntax match jsFloat /\c\<\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%(e[+-]\=\d\+\)\=\>/ " Regular Expressions -syntax match jsSpecial contained "\v\\%(x\x\x|u%(\x{4}|\{\x{4,5}})|c\u|.)" +syntax match jsSpecial contained "\v\\%(x\x\x|u%(\x{4}|\{\x{4,5}})|.)" +syntax match jsSpecialRegexp contained "\v\\c\a" syntax region jsTemplateExpression contained matchgroup=jsTemplateBraces start=+${+ end=+}+ contains=@jsExpression keepend -syntax region jsRegexpCharClass contained start=+\[+ skip=+\\.+ end=+\]+ contains=jsSpecial extend +syntax region jsRegexpCharClass contained start=+\[+ skip=+\\.+ end=+\]+ contains=jsSpecial,jsSpecialRegexp extend syntax match jsRegexpBoundary contained "\v\c[$^]|\\b" syntax match jsRegexpBackRef contained "\v\\[1-9]\d*" syntax match jsRegexpQuantifier contained "\v[^\\]%([?*+]|\{\d+%(,\d*)?})\??"lc=1 @@ -69,7 +70,7 @@ syntax match jsRegexpOr contained "|" syntax match jsRegexpMod contained "\v\(\?[:=!>]"lc=1 syntax region jsRegexpGroup contained start="[^\\]("lc=1 skip="\\.\|\[\(\\.\|[^]]\+\)\]" end=")" contains=jsRegexpCharClass,@jsRegexpSpecial keepend syntax region jsRegexpString start=+\%(\%(\= 508 || !exists("did_javascript_syn_inits") HiLink jsRepeatBraces Noise HiLink jsSwitchBraces Noise HiLink jsSpecial Special + HiLink jsSpecialRegexp Special HiLink jsTemplateBraces Noise HiLink jsGlobalObjects Constant HiLink jsGlobalNodeObjects Constant