|
19 | 19 | '';
|
20 | 20 | };
|
21 | 21 | in {
|
| 22 | + xdg.configFile."helix/runtime/queries/fennel/injections.scm".source = pkgs.writeText "fennel-injections.scm" '' |
| 23 | + ; inherits: scheme |
| 24 | + ''; |
| 25 | + xdg.configFile."helix/runtime/queries/fennel/indents.scm".source = pkgs.writeText "fennel-indents.scm" '' |
| 26 | + ; Exclude literals in the first patterns, since different rules apply for them. |
| 27 | + ; Similarly, exclude certain keywords (detected by a regular expression). |
| 28 | + ; If a list has 2 elements on the first line, it is aligned to the second element. |
| 29 | + (list . (_) @first . (_) @anchor |
| 30 | + (#same-line? @first @anchor) |
| 31 | + (#set! "scope" "tail") |
| 32 | + (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number") |
| 33 | + (#not-match? @first "lambda.*|λ.*|let.*|set.*|fn.*")) @align |
| 34 | + ; If the first element in a list is also a list and on a line by itself, the outer list is aligned to it |
| 35 | + (list . (list) @anchor . |
| 36 | + (#set! "scope" "tail") |
| 37 | + (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number")) @align |
| 38 | + (list . (list) @anchor . (_) @second |
| 39 | + (#not-same-line? @anchor @second) |
| 40 | + (#set! "scope" "tail") |
| 41 | + (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number") |
| 42 | + (#not-match? @first "lambda.*|λ.*|let.*|set.*|fn.*")) @align |
| 43 | + ; If the first element in a list is not a list and on a line by itself, the outer list is aligned to |
| 44 | + ; it plus 1 additional space. This cannot currently be modelled exactly by our indent queries, |
| 45 | + ; but the following is equivalent, assuming that: |
| 46 | + ; - the indent width is 2 (the default for scheme) |
| 47 | + ; - There is no space between the opening parenthesis of the list and the first element |
| 48 | + (list . (_) @first . |
| 49 | + (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number") |
| 50 | + (#not-match? @first "def.*|let.*|set!")) @indent |
| 51 | + (list . (_) @first . (_) @second |
| 52 | + (#not-same-line? @first @second) |
| 53 | + (#not-kind-eq? @first "boolean") (#not-kind-eq? @first "character") (#not-kind-eq? @first "string") (#not-kind-eq? @first "number") |
| 54 | + (#not-match? @first "lambda.*|λ.*|let.*|set.*|fn.*")) @indent |
| 55 | +
|
| 56 | + ; If the first element in a list is a literal, align the list to it |
| 57 | + (list . [(boolean) (character) (string) (number)] @anchor |
| 58 | + (#set! "scope" "tail")) @align |
| 59 | +
|
| 60 | + ; If the first element is among a set of predefined keywords, align the list to this element |
| 61 | + ; plus 1 space (using the same workaround as above for now). This is a simplification since actually |
| 62 | + ; the second line of the list should be indented by 2 spaces more in some cases. Supporting this would |
| 63 | + ; be possible but require significantly more patterns. |
| 64 | + (list . (symbol) @first |
| 65 | + (#not-match? @first "lambda.*|λ.*|let.*|set.*|fn.*")) @indent |
| 66 | + ''; |
22 | 67 | xdg.configFile."helix/runtime/queries/fennel/highlights.scm".source = pkgs.writeText "fennel-highlights.scm" ''
|
23 |
| - (comment) @comment |
24 |
| -
|
25 |
| - [ "(" ")" "{" "}" "[" "]" ] @punctuation.bracket |
26 |
| -
|
27 |
| - [ ":" ":until" "&" "&as" "?" ] @punctuation.special |
28 |
| -
|
29 |
| - (nil) @constant.builtin |
30 |
| - (vararg) @punctuation.special |
31 | 68 |
|
32 |
| - (boolean) @constant.builtin.boolean |
33 | 69 | (number) @constant.numeric
|
| 70 | + (character) @constant.character |
| 71 | + (boolean) @constant.builtin.boolean |
34 | 72 |
|
35 | 73 | (string) @string
|
| 74 | +
|
36 | 75 | (escape_sequence) @constant.character.escape
|
37 | 76 |
|
| 77 | + (comment) @comment.line |
| 78 | + (block_comment) @comment.block |
| 79 | + (directive) @keyword.directive |
38 | 80 |
|
39 |
| - ((symbol) @variable.builtin |
40 |
| - (#match? @variable.builtin "^[$]")) |
| 81 | + ; operators |
| 82 | +
|
| 83 | + ((symbol) @operator |
| 84 | + (#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=|~=|#|\\.|\\?\\.|\\.\\.|//|%|\\^)$")) |
41 | 85 |
|
42 |
| - (binding) @symbol |
| 86 | + ; keywords |
43 | 87 |
|
44 |
| - [ "fn" "lambda" "hashfn" "#" ] @keyword.function |
| 88 | + (list |
| 89 | + . |
| 90 | + ((symbol) @keyword.conditional |
| 91 | + (#match? @keyword.conditional "^(if|case|match|when|unless)$" |
| 92 | + ))) |
45 | 93 |
|
46 |
| - (fn name: [ |
47 |
| - (symbol) @function |
48 |
| - (multi_symbol (symbol) @function .) |
49 |
| - ]) |
| 94 | + (list |
| 95 | + . |
| 96 | + (symbol) @keyword |
| 97 | + (#match? @keyword |
| 98 | + "^(let\\*|fn|lambda|λ|case|=>|set|let|do|else|and|if|or|not=|not|lshift|rshift|band|bor|bxor|bnot|length|when|unless|case|match|assert|require|global|local|var|comment|doc|eval-compiler|lua|macros|unquote|quote|tset|values|tail\\!)$" |
| 99 | + )) |
50 | 100 |
|
51 |
| - (lambda name: [ |
52 |
| - (symbol) @function |
53 |
| - (multi_symbol (symbol) @function .) |
54 |
| - ]) |
| 101 | + (list |
| 102 | + . |
| 103 | + (symbol) @function.builtin |
| 104 | + (#match? @function.builtin |
| 105 | + "^(assert|collectgarbage|dofile|error|getmetatable|ipairs|load|loadfile|next|pairs|pcall|print|rawequal|rawget|rawlen|rawset|require|select|setmetatable|tonumber|tostring|type|warn|xpcall|module|setfenv|loadstring|unpack|require-macros|import-macros|include)$" |
| 106 | + )) |
55 | 107 |
|
56 |
| - (multi_symbol |
57 |
| - "." @punctuation.delimiter |
58 |
| - (symbol) @variable.other.member) |
| 108 | + ; special forms |
59 | 109 |
|
60 |
| - (multi_symbol_method |
61 |
| - ":" @punctuation.delimiter |
62 |
| - (symbol) @function.method .) |
| 110 | + (list |
| 111 | + "[" |
| 112 | + (symbol)+ @variable |
| 113 | + "]") |
63 | 114 |
|
64 |
| - [ "for" "each" ] @keyword.control.repeat |
65 |
| - ((symbol) @keyword.control.repeat |
66 |
| - (#eq? @keyword.control.repeat |
67 |
| - "while")) |
| 115 | + (list |
| 116 | + . |
| 117 | + (symbol) @_f |
| 118 | + . |
| 119 | + (list |
| 120 | + (symbol) @variable) |
| 121 | + (#eq? @_f "lambda")) |
68 | 122 |
|
69 |
| - [ "match" ] @keyword.control.conditional |
70 |
| - ((symbol) @keyword.control.conditional |
71 |
| - (#match? @keyword.control.conditional "^(if|when)$")) |
| 123 | + (list |
| 124 | + . |
| 125 | + (symbol) @_f |
| 126 | + . |
| 127 | + (list |
| 128 | + (list |
| 129 | + (symbol) @variable.parameter)) |
| 130 | + (#match? @_f |
| 131 | + "^(let|let\\*|let-syntax|let-values|let\\*-values|letrec|letrec\\*|letrec-syntax)$")) |
72 | 132 |
|
73 |
| - [ "global" "local" "let" "set" "var" "where" "or" ] @keyword |
74 |
| - ((symbol) @keyword |
75 |
| - (#match? @keyword |
76 |
| - "^(comment|do|doc|eval-compiler|lua|macros|quote|tset|values)$")) |
| 133 | + ; quote |
77 | 134 |
|
78 |
| - ((symbol) @keyword.control.import |
79 |
| - (#match? @keyword.control.import |
80 |
| - "^(require|require-macros|import-macros|include)$")) |
| 135 | + (list |
| 136 | + . |
| 137 | + (symbol) @_f |
| 138 | + (#eq? @_f "quote")) @string.symbol |
81 | 139 |
|
82 |
| - [ "collect" "icollect" "accumulate" ] @function.macro |
83 |
| - ((symbol) @function.macro |
84 |
| - (#match? @function.macro |
85 |
| - "^(->|->>|-\\?>|-\\?>>|\\?\\.|doto|macro|macrodebug|partial|pick-args|pick-values|with-open)$")) |
| 140 | + ; library |
86 | 141 |
|
87 |
| - ; Lua builtins |
88 |
| - ((symbol) @constant.builtin |
89 |
| - (#match? @constant.builtin |
90 |
| - "^(arg|_ENV|_G|_VERSION)$")) |
| 142 | + (list |
| 143 | + . |
| 144 | + (symbol) @_lib |
| 145 | + . |
| 146 | + (symbol) @namespace |
91 | 147 |
|
92 |
| - ((symbol) @function.builtin |
93 |
| - (#match? @function.builtin |
94 |
| - "^(assert|collectgarbage|dofile|error|getmetatable|ipairs|load|loadfile|loadstring|module|next|pairs|pcall|print|rawequal|rawget|rawlen|rawset|require|select|setfenv|setmetatable|tonumber|tostring|type|unpack|warn|xpcall)$")) |
| 148 | + (#eq? @_lib "library")) |
| 149 | +
|
| 150 | + ; procedure |
| 151 | +
|
| 152 | + (list |
| 153 | + . |
| 154 | + (symbol) @function) |
| 155 | +
|
| 156 | + ;; variables |
| 157 | +
|
| 158 | + ((symbol) @variable.builtin |
| 159 | + (#eq? @variable.builtin "...")) |
| 160 | +
|
| 161 | + ((symbol) @variable.builtin |
| 162 | + (#eq? @variable.builtin ".")) |
95 | 163 |
|
96 |
| - (list . (symbol) @function) |
97 |
| - (list . (multi_symbol (symbol) @function .)) |
98 | 164 | (symbol) @variable
|
| 165 | +
|
| 166 | + ["(" ")" "[" "]" "{" "}"] @punctuation.bracket |
| 167 | +
|
| 168 | + (quote "'") @operator |
| 169 | + (unquote_splicing ",@") @operator |
| 170 | + (unquote ",") @operator |
| 171 | + (quasiquote "`") @operator |
| 172 | +
|
99 | 173 | '';
|
100 | 174 | programs.helix = {
|
101 | 175 | enable = true;
|
|
455 | 529 | args = ["-"];
|
456 | 530 | };
|
457 | 531 | language-servers = ["fennel-ls" "lsp-ai"];
|
458 |
| - grammar = "fennel"; |
| 532 | + grammar = "scheme"; |
459 | 533 | auto-format = true;
|
460 | 534 | }
|
461 | 535 | {
|
|
0 commit comments