summaryrefslogtreecommitdiff
path: root/rc/base/javascript.kak
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-07-01 19:53:35 +1000
committerMaxime Coste <mawww@kakoune.org>2018-07-05 07:54:28 +1000
commit9ea6b88c1fa67ef417d1dc6de65bc31e6f77d300 (patch)
tree5be8c8ef5e12101b85178521712bf7da02f3ce14 /rc/base/javascript.kak
parent6993b0f347733aa24354af520789c1cefd5ff576 (diff)
Fix remaining kak scripts to use the new highlighter syntax
Diffstat (limited to 'rc/base/javascript.kak')
-rw-r--r--rc/base/javascript.kak73
1 files changed, 32 insertions, 41 deletions
diff --git a/rc/base/javascript.kak b/rc/base/javascript.kak
index 0c7d68b3..e30e1936 100644
--- a/rc/base/javascript.kak
+++ b/rc/base/javascript.kak
@@ -43,66 +43,57 @@ define-command -hidden init-javascript-filetype -params 1 %~
# Highlighters
# ‾‾‾‾‾‾‾‾‾‾‾‾
- add-highlighter shared/ regions -default code %arg{1} \
- double_string '"' (?<!\\)(\\\\)*" '' \
- single_string "'" (?<!\\)(\\\\)*' '' \
- literal "`" (?<!\\)(\\\\)*` '' \
- comment // '$' '' \
- comment /\* \*/ '' \
- shebang ^#! $ '' \
- regex / (?<!\\)(\\\\)*/[gimuy]* '' \
- jsx (?<![\w<])<[a-zA-Z][\w:.-]*(?!\hextends)(?=[\s/>])(?!>\()) (</.*?>|/>) (?<![\w<])<[a-zA-Z][\w:.-]* \
- division '[\w\)\]]\K(/|(\h+/\h+))' '(?=\w)' '' # Help Kakoune to better detect /…/ literals
+ add-highlighter "shared/%arg{1}" regions
+ add-highlighter "shared/%arg{1}/code" default-region group
+ add-highlighter "shared/%arg{1}/double_string" region '"' (?<!\\)(\\\\)*" '' fill string
+ add-highlighter "shared/%arg{1}/single_string" region "'" (?<!\\)(\\\\)*' '' fill string
+ add-highlighter "shared/%arg{1}/literal" region "`" (?<!\\)(\\\\)*` '' group
+ add-highlighter "shared/%arg{1}/comment_line" region // '$' '' fill comment
+ add-highlighter "shared/%arg{1}/comment" region /\* \*/ '' fill comment
+ add-highlighter "shared/%arg{1}/shebang" region ^#! $ '' fill meta
+ add-highlighter "shared/%arg{1}/regex" region / (?<!\\)(\\\\)*/[gimuy]* '' fill meta
+ add-highlighter "shared/%arg{1}/jsx" region (?<![\w<])<[a-zA-Z][\w:.-]*(?!\hextends)(?=[\s/>])(?!>\()) (</.*?>|/>) (?<![\w<])<[a-zA-Z][\w:.-]* regions
+ add-highlighter "shared/%arg{1}/division" region '[\w\)\]]\K(/|(\h+/\h+))' '(?=\w)' '' group # Help Kakoune to better detect /…/ literals
# Regular expression flags are: g → global match, i → ignore case, m → multi-lines, u → unicode, y → sticky
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
- add-highlighter "shared/%arg{1}/double_string" fill string
- add-highlighter "shared/%arg{1}/single_string" fill string
- add-highlighter "shared/%arg{1}/regex" fill meta
- add-highlighter "shared/%arg{1}/comment" fill comment
- add-highlighter "shared/%arg{1}/shebang" fill meta
+ add-highlighter "shared/%arg{1}/literal/" fill string
+ add-highlighter "shared/%arg{1}/literal/" regex \$\{.*?\} 0:value
- add-highlighter "shared/%arg{1}/literal" fill string
- add-highlighter "shared/%arg{1}/literal" regex \$\{.*?\} 0:value
-
- add-highlighter "shared/%arg{1}/code" regex [^$_]\b(document|false|null|parent|self|this|true|undefined|window)\b 1:value
- add-highlighter "shared/%arg{1}/code" regex "-?\b[0-9]*\.?[0-9]+" 0:value
- add-highlighter "shared/%arg{1}/code" regex \b(Array|Boolean|Date|Function|Number|Object|RegExp|String|Symbol)\b 0:type
+ add-highlighter "shared/%arg{1}/code/" regex [^$_]\b(document|false|null|parent|self|this|true|undefined|window)\b 1:value
+ add-highlighter "shared/%arg{1}/code/" regex "-?\b[0-9]*\.?[0-9]+" 0:value
+ add-highlighter "shared/%arg{1}/code/" regex \b(Array|Boolean|Date|Function|Number|Object|RegExp|String|Symbol)\b 0:type
# jsx: In well-formed xml the number of opening and closing tags match up regardless of tag name.
#
# We inline a small XML highlighter here since it anyway need to recurse back up to the starting highlighter.
# To make things simple we assume that jsx is always enabled.
- add-highlighter "shared/%arg{1}/jsx" regions content \
- tag <(?=[/a-zA-Z]) (?<!=)> < \
- expr \{ \} \{
-
- add-highlighter "shared/%arg{1}/jsx/content/expr" ref %arg{1}
-
- add-highlighter "shared/%arg{1}/jsx/content/tag" regex (\w+) 1:attribute
+ add-highlighter "shared/%arg{1}/jsx/tag" region <(?=[/a-zA-Z]) (?<!=)> < regions
+ add-highlighter "shared/%arg{1}/jsx/expr" region \{ \} \{ ref %arg{1}
+
- add-highlighter "shared/%arg{1}/jsx/content/tag" regex </?([\w-$]+) 1:keyword
- add-highlighter "shared/%arg{1}/jsx/content/tag" regex (</?|/?>) 0:meta
+ add-highlighter "shared/%arg{1}/jsx/tag/base" default-region group
+ add-highlighter "shared/%arg{1}/jsx/tag/double_string" region =\K" (?<!\\)(\\\\)*" '' fill string
+ add-highlighter "shared/%arg{1}/jsx/tag/single_string" region =\K' (?<!\\)(\\\\)*' '' fill string
+ add-highlighter "shared/%arg{1}/jsx/tag/expr" region \{ \} \{ group
- add-highlighter "shared/%arg{1}/jsx/content/tag" regions content \
- string =\K" (?<!\\)(\\\\)*" '' \
- string =\K' (?<!\\)(\\\\)*' '' \
- expr \{ \} \{
+ add-highlighter "shared/%arg{1}/jsx/tag/base/" regex (\w+) 1:attribute
+ add-highlighter "shared/%arg{1}/jsx/tag/base/" regex </?([\w-$]+) 1:keyword
+ add-highlighter "shared/%arg{1}/jsx/tag/base/" regex (</?|/?>) 0:meta
- add-highlighter "shared/%arg{1}/jsx/content/tag/content/string" fill string
- add-highlighter "shared/%arg{1}/jsx/content/tag/content/expr" fill default,default+e
- add-highlighter "shared/%arg{1}/jsx/content/tag/content/expr" ref %arg{1}
+ add-highlighter "shared/%arg{1}/jsx/tag/expr/" fill default,default+e
+ add-highlighter "shared/%arg{1}/jsx/tag/expr/" ref %arg{1}
# Keywords are collected at
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#Keywords
- add-highlighter "shared/%arg{1}/code" regex \b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|of|return|static|super|switch|throw|try|typeof|var|void|while|with|yield)\b 0:keyword
+ add-highlighter "shared/%arg{1}/code/" regex \b(async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|export|extends|finally|for|function|if|import|in|instanceof|let|new|of|return|static|super|switch|throw|try|typeof|var|void|while|with|yield)\b 0:keyword
# Initialization
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾
- hook -group "%arg{1}-highlight" global WinSetOption "filetype=%arg{1}" "add-highlighter window ref %arg{1}"
+ hook -group "%arg{1}-highlight" global WinSetOption "filetype=%arg{1}" "add-highlighter window/%arg{1} ref %arg{1}"
hook global WinSetOption "filetype=%arg{1}" "
hook window ModeChange insert:.* -group %arg{1}-hooks javascript-filter-around-selections
@@ -123,7 +114,7 @@ init-javascript-filetype typescript
# Highlighting specific to TypeScript
# ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
-add-highlighter shared/typescript/code regex \b(array|boolean|date|number|object|regexp|string|symbol)\b 0:type
+add-highlighter shared/typescript/code/ regex \b(array|boolean|date|number|object|regexp|string|symbol)\b 0:type
# Keywords grabbed from https://github.com/Microsoft/TypeScript/issues/2536
-add-highlighter shared/typescript/code regex \b(as|constructor|declare|enum|from|implements|interface|module|namespace|package|private|protected|public|readonly|static|type)\b 0:keyword
+add-highlighter shared/typescript/code/ regex \b(as|constructor|declare|enum|from|implements|interface|module|namespace|package|private|protected|public|readonly|static|type)\b 0:keyword