From bec797778d8669fa42fe62431e574b1abd03e3d3 Mon Sep 17 00:00:00 2001 From: E Dunbar Date: Mon, 21 Apr 2025 13:36:47 -0500 Subject: [PATCH] Significantly improve highlights --- queries/highlights.scm | 199 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 181 insertions(+), 18 deletions(-) diff --git a/queries/highlights.scm b/queries/highlights.scm index d7e5a43..95d43a9 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -1,26 +1,189 @@ -; highlights.scm - -; identifiers +; Variables (symbol) @variable -; literals -(string) @string -(bracket_string) @string -(integer) @number -(complex) @number -(float) @number.float - -; types (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 -; punctuation -(dotted_identifier "." @punctuation.delimiter) -["(" ")" "[" "]" "{" "}"] @punctuation.bracket +[ + (comment) + (discard) +] @comment -; comments -(comment) @comment +; Tokens +((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"))