Significantly improve highlights

This commit is contained in:
E Dunbar 2025-04-21 13:36:47 -05:00
parent 8cd6c4e65d
commit bec797778d

View file

@ -1,26 +1,189 @@
; highlights.scm ; Variables
; identifiers
(symbol) @variable (symbol) @variable
; literals
(string) @string
(bracket_string) @string
(integer) @number
(complex) @number
(float) @number.float
; types
(keyword) @property (keyword) @property
; functions ; Symbol naming conventions
((symbol) @type
(#lua-match? @type "^[A-Z].*[a-z]"))
((symbol) @constant
(#lua-match? @constant "^[A-Z][A-Z_0-9]*$"))
((symbol) @constant.builtin
(#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$"))
((symbol) @constant.builtin
(#any-of? @constant.builtin
; https://docs.python.org/3/library/constants.html
"NotImplemented" "Ellipsis" "quit" "exit" "copyright" "credits" "license"))
((symbol) @character.special
(#eq? @character.special "_"))
; Function calls
(expression
.
(symbol) @function.call)
(expression
.
(dotted_identifier) @function.method.call)
;Function definitions
(expression
.
(symbol) @keyword.function
(symbol) @function
.
(list
(symbol)* @parameter)
(#eq? @keyword.function "defn"))
(expression
.
(symbol) @keyword.function
.
(list
(symbol)* @parameter)
(#eq? @keyword.function "fn"))
; Literals
((symbol) @constant.builtin
(#eq? @constant.builtin "None"))
((symbol) @boolean
(#any-of? @boolean "True" "False"))
[
(integer)
(complex)
] @number
(float) @number.float
[
(string)
(bracket_string)
] @string
; keywords
(shebang) @keyword.directive (shebang) @keyword.directive
; punctuation [
(dotted_identifier "." @punctuation.delimiter) (comment)
["(" ")" "[" "]" "{" "}"] @punctuation.bracket (discard)
] @comment
; comments ; Tokens
(comment) @comment ((symbol) @operator
(#any-of? @operator
"-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "&=" "%" "%=" "^" "^=" "+" "+=" "<"
"<<" "<<=" "<=" "<>" "=" ">" ">=" ">>" ">>=" "@" "@=" "|" "|="))
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(dotted_identifier
"." @punctuation.delimiter)
; Keywords
(expression
.
(symbol) @keyword.operator
(#any-of? @keyword.operator "and" "in" "is" "not" "or" "del" "is-not" "not-in"))
((symbol) @keyword
(#any-of? @keyword "assert" "exec" "global" "nonlocal" "pass" "print" "with" "as"))
((symbol) @keyword.type
(#eq? @keyword.type "type"))
((symbol) @keyword.coroutine
(#eq? @keyword.coroutine "await"))
((symbol) @keyword.return
(#any-of? @keyword.return "return" "yield"))
(expression
.
(symbol) @keyword.import
.
[
(symbol)
(dotted_identifier)
] @module
((keyword) @keyword
.
(symbol) @module
(#eq? @keyword ":as"))?
(#any-of? @keyword.import "import" "require"))
((symbol) @keyword.conditional
(#any-of? @keyword.conditional "if" "when" "cond" "else" "match"))
((symbol) @keyword.repeat
(#any-of? @keyword.repeat "for" "while" "break" "continue" "lfor" "dfor" "gfor" "sfor"))
((symbol) @keyword.exception
(#any-of? @keyword.exception "raise" "try"))
; Classes
(expression
.
(symbol) @keyword.type
(symbol) @type
.
(list
(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"))
(expression
.
(symbol) @_dot
.
(symbol)
.
(symbol) @variable.member
(#eq? @_dot "."))
; Builtin functions
(expression
.
(symbol) @function.builtin
(#any-of? @function.builtin
"abs" "all" "any" "ascii" "bin" "bnot" "bool" "breakpoint" "bytearray" "bytes" "callable" "chr"
"classmethod" "compile" "complex" "delattr" "dict" "dir" "divmod" "enumerate" "eval" "exec"
"filter" "float" "format" "frozenset" "getattr" "globals" "hasattr" "hash" "help" "hex" "id"
"input" "int" "isinstance" "issubclass" "iter" "len" "list" "locals" "map" "max" "memoryview"
"min" "next" "object" "oct" "open" "ord" "pow" "print" "property" "range" "repr" "reversed"
"round" "set" "setattr" "slice" "sorted" "staticmethod" "str" "sum" "super" "tuple" "type"
"vars" "zip" "__import__"))
; Builtin macros
(expression
.
(symbol) @function.macro
(#any-of? @function.macro
"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"
"unpack-iterable" "unpack-mapping" "defmacro" "defreader" "get-macro" "local-macros" "export"
"get" "cut"))