Improve highlighting

This commit is contained in:
E Dunbar 2025-05-09 16:19:32 -05:00
parent bec797778d
commit 5faca0e2a8
2 changed files with 71 additions and 42 deletions

View file

@ -8,10 +8,10 @@
(#lua-match? @type "^[A-Z].*[a-z]")) (#lua-match? @type "^[A-Z].*[a-z]"))
((symbol) @constant ((symbol) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) (#lua-match? @constant "^[A-Z][A-Z0-9_-]*$"))
((symbol) @constant.builtin ((symbol) @constant.builtin
(#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) (#lua-match? @constant.builtin "^__[a-zA-Z0-9_-]*__$"))
((symbol) @constant.builtin ((symbol) @constant.builtin
(#any-of? @constant.builtin (#any-of? @constant.builtin
@ -38,7 +38,7 @@
. .
(list (list
(symbol)* @parameter) (symbol)* @parameter)
(#eq? @keyword.function "defn")) (#any-of? @keyword.function "defn" "defmacro"))
(expression (expression
. .
@ -46,7 +46,7 @@
. .
(list (list
(symbol)* @parameter) (symbol)* @parameter)
(#eq? @keyword.function "fn")) (#any-of? @keyword.function "fn" "defreader"))
; Literals ; Literals
((symbol) @constant.builtin ((symbol) @constant.builtin
@ -74,24 +74,6 @@
(discard) (discard)
] @comment ] @comment
; Tokens
((symbol) @operator
(#any-of? @operator
"-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "&=" "%" "%=" "^" "^=" "+" "+=" "<"
"<<" "<<=" "<=" "<>" "=" ">" ">=" ">>" ">>=" "@" "@=" "|" "|="))
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(dotted_identifier
"." @punctuation.delimiter)
; Keywords ; Keywords
(expression (expression
. .
@ -125,7 +107,7 @@
(#any-of? @keyword.import "import" "require")) (#any-of? @keyword.import "import" "require"))
((symbol) @keyword.conditional ((symbol) @keyword.conditional
(#any-of? @keyword.conditional "if" "when" "cond" "else" "match")) (#any-of? @keyword.conditional "if" "when" "cond" "else" "match" "chainc"))
((symbol) @keyword.repeat ((symbol) @keyword.repeat
(#any-of? @keyword.repeat "for" "while" "break" "continue" "lfor" "dfor" "gfor" "sfor")) (#any-of? @keyword.repeat "for" "while" "break" "continue" "lfor" "dfor" "gfor" "sfor"))
@ -137,30 +119,18 @@
(expression (expression
. .
(symbol) @keyword.type (symbol) @keyword.type
(symbol) @type
. .
(list (symbol) @type
(symbol)* @type)
(expression
.
(symbol) @_setv
(symbol) @variable.member
(#eq? @_setv "setv"))
(expression
.
(symbol) @_defn
(symbol)
(list
.
(symbol) @variable.builtin)
(#eq? @_defn "defn"))
(#eq? @keyword.type "defclass")) (#eq? @keyword.type "defclass"))
((symbol) @variable.builtin
(#eq? @variable.builtin "self"))
(expression (expression
. .
(symbol) @_dot (symbol) @_dot
. .
(symbol) (_)
. .
(symbol) @variable.member (symbol) @variable.member
(#eq? @_dot ".")) (#eq? @_dot "."))
@ -185,5 +155,34 @@
(#any-of? @function.macro (#any-of? @function.macro
"do" "do-mac" "eval-and-compile" "eval-when-compile" "py" "pys" "pragma" "quote" "quasiquote" "do" "do-mac" "eval-and-compile" "eval-when-compile" "py" "pys" "pragma" "quote" "quasiquote"
"unquote" "unquote-splice" "setv" "setx" "let" "global" "nonlocal" "del" "annotate" "deftype" "unquote" "unquote-splice" "setv" "setx" "let" "global" "nonlocal" "del" "annotate" "deftype"
"unpack-iterable" "unpack-mapping" "defmacro" "defreader" "get-macro" "local-macros" "export" "." "unpack-iterable" "unpack-mapping" "with" "get-macro" "local-macros" "export" "get" "cut"
"get" "cut")) "assert"))
; Tokens
((symbol) @operator
(#any-of? @operator
"-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "&=" "%" "%=" "^" "^=" "+" "+=" "<"
"<<" "<<=" "<=" "<>" "=" ">" ">=" ">>" ">>=" "@" "@=" "|" "|="))
[
"#("
"("
")"
"["
"]"
"#{"
"{"
"}"
] @punctuation.bracket
[
"'"
"`"
"~"
"~@"
"#*"
"#**"
] @function.macro
(dotted_identifier
"." @punctuation.delimiter)

View file

@ -0,0 +1,30 @@
(setv foobar (+ 2 2))
(setv [tim eric] ["jim" "derrick"])
(setv alpha "a" beta "b")
(sorted "abcBC"
:key (fn [x] (.lower x)))
(defn test [a b [c "x"] #* d]
[a b c d])
(with [o (open "file.txt" "rt")]
(setv buffer [])
(while (< (len buffer) 10)
(.append buffer (next o))))
(lfor
x (range 3)
y (range 3)
:if (= (+ x y) 3)
(* x y))
(defmacro do-while [test #* body]
`(do
~@body
(while ~test
~@body)))
(setv x 0)
(do-while x
(print "Printed once."))