From 5faca0e2a8e87327cfa7e62a183e56eaa380db8f Mon Sep 17 00:00:00 2001 From: E Dunbar Date: Fri, 9 May 2025 16:19:32 -0500 Subject: [PATCH] Improve highlighting --- queries/highlights.scm | 83 +++++++++++++++++++------------------- test/highlight_examples.hy | 30 ++++++++++++++ 2 files changed, 71 insertions(+), 42 deletions(-) create mode 100644 test/highlight_examples.hy diff --git a/queries/highlights.scm b/queries/highlights.scm index 95d43a9..83c5000 100644 --- a/queries/highlights.scm +++ b/queries/highlights.scm @@ -8,10 +8,10 @@ (#lua-match? @type "^[A-Z].*[a-z]")) ((symbol) @constant - (#lua-match? @constant "^[A-Z][A-Z_0-9]*$")) + (#lua-match? @constant "^[A-Z][A-Z0-9_-]*$")) ((symbol) @constant.builtin - (#lua-match? @constant.builtin "^__[a-zA-Z0-9_]*__$")) + (#lua-match? @constant.builtin "^__[a-zA-Z0-9_-]*__$")) ((symbol) @constant.builtin (#any-of? @constant.builtin @@ -38,7 +38,7 @@ . (list (symbol)* @parameter) - (#eq? @keyword.function "defn")) + (#any-of? @keyword.function "defn" "defmacro")) (expression . @@ -46,7 +46,7 @@ . (list (symbol)* @parameter) - (#eq? @keyword.function "fn")) + (#any-of? @keyword.function "fn" "defreader")) ; Literals ((symbol) @constant.builtin @@ -74,24 +74,6 @@ (discard) ] @comment -; Tokens -((symbol) @operator - (#any-of? @operator - "-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "&=" "%" "%=" "^" "^=" "+" "+=" "<" - "<<" "<<=" "<=" "<>" "=" ">" ">=" ">>" ">>=" "@" "@=" "|" "|=")) - -[ - "(" - ")" - "[" - "]" - "{" - "}" -] @punctuation.bracket - -(dotted_identifier - "." @punctuation.delimiter) - ; Keywords (expression . @@ -125,7 +107,7 @@ (#any-of? @keyword.import "import" "require")) ((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 (#any-of? @keyword.repeat "for" "while" "break" "continue" "lfor" "dfor" "gfor" "sfor")) @@ -137,30 +119,18 @@ (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")) + (symbol) @type (#eq? @keyword.type "defclass")) +((symbol) @variable.builtin + (#eq? @variable.builtin "self")) + (expression . (symbol) @_dot . - (symbol) + (_) . (symbol) @variable.member (#eq? @_dot ".")) @@ -185,5 +155,34 @@ (#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")) + "." "unpack-iterable" "unpack-mapping" "with" "get-macro" "local-macros" "export" "get" "cut" + "assert")) + +; Tokens +((symbol) @operator + (#any-of? @operator + "-" "-=" "!=" "*" "**" "**=" "*=" "/" "//" "//=" "/=" "&" "&=" "%" "%=" "^" "^=" "+" "+=" "<" + "<<" "<<=" "<=" "<>" "=" ">" ">=" ">>" ">>=" "@" "@=" "|" "|=")) + +[ + "#(" + "(" + ")" + "[" + "]" + "#{" + "{" + "}" +] @punctuation.bracket + +[ + "'" + "`" + "~" + "~@" + "#*" + "#**" +] @function.macro + +(dotted_identifier + "." @punctuation.delimiter) diff --git a/test/highlight_examples.hy b/test/highlight_examples.hy new file mode 100644 index 0000000..c918bc6 --- /dev/null +++ b/test/highlight_examples.hy @@ -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."))