Skip to content

Commit 4d3bcaa

Browse files
committed
feat: use scheme grammar for fennel helix lang
previously used tree-sitter-fennel but seemed unnecessary
1 parent 3aab793 commit 4d3bcaa

File tree

4 files changed

+131
-127
lines changed

4 files changed

+131
-127
lines changed

flake.lock

-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+1-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
devenv.url = "github:cachix/devenv";
4747
disko.inputs.nixpkgs.follows = "nixpkgs";
4848
disko.url = "github:nix-community/disko";
49-
fennel-tree-sitter.flake = false;
50-
fennel-tree-sitter.url = "github:TravonteD/tree-sitter-fennel/1.1.0";
5149
fenix.inputs.nixpkgs.follows = "nixpkgs";
5250
fenix.url = "github:nix-community/fenix";
5351
flake-compat.flake = false;
@@ -134,4 +132,4 @@
134132
];
135133
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
136134
};
137-
}
135+
}

flake/packages.nix

+1-51
Original file line numberDiff line numberDiff line change
@@ -122,57 +122,7 @@
122122
boot.kernelPackages = lib.mkForce pkgs.linuxPackages_latest;
123123
}
124124
];
125-
helix-latest = inputs.helix-editor.packages.${system}.default.override {
126-
grammarOverlays = [
127-
(_final: _prev: {
128-
fennel = pkgs.stdenv.mkDerivation {
129-
pname = "helix-tree-sitter-fennel";
130-
version = inputs.fennel-tree-sitter.rev;
131-
src = inputs.fennel-tree-sitter;
132-
sourceRoot = "source";
133-
dontConfigure = true;
134-
FLAGS = [
135-
"-Isrc"
136-
"-g"
137-
"-O3"
138-
"-fPIC"
139-
"-fno-exceptions"
140-
"-Wl,-z,relro,-z,now"
141-
];
142-
NAME = "fennel";
143-
buildPhase = ''
144-
runHook preBuild
145-
146-
if [[ -e src/scanner.cc ]]; then
147-
$CXX -c src/scanner.cc -o scanner.o $FLAGS
148-
elif [[ -e src/scanner.c ]]; then
149-
$CC -c src/scanner.c -o scanner.o $FLAGS
150-
fi
151-
152-
$CC -c src/parser.c -o parser.o $FLAGS
153-
$CXX -shared -o $NAME.so *.o
154-
155-
ls -al
156-
157-
runHook postBuild
158-
'';
159-
installPhase = ''
160-
runHook preInstall
161-
mkdir $out
162-
mv $NAME.so $out/
163-
runHook postInstall
164-
'';
165-
166-
# Strip failed on darwin: strip: error: symbols referenced by indirect symbol table entries that can't be stripped
167-
fixupPhase = lib.optionalString pkgs.stdenv.isLinux ''
168-
runHook preFixup
169-
$STRIP $out/$NAME.so
170-
runHook postFixup
171-
'';
172-
};
173-
})
174-
];
175-
};
125+
helix-latest = inputs.helix-editor.packages.${system}.default;
176126
zjstatus = inputs.zjstatus.packages.${system}.default;
177127
zwift = inputs.zwift.packages.${system}.default;
178128
persway = inputs.persway.packages.${system}.default;

users/profiles/helix.nix

+129-55
Original file line numberDiff line numberDiff line change
@@ -19,83 +19,157 @@
1919
'';
2020
};
2121
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+
'';
2267
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
3168
32-
(boolean) @constant.builtin.boolean
3369
(number) @constant.numeric
70+
(character) @constant.character
71+
(boolean) @constant.builtin.boolean
3472
3573
(string) @string
74+
3675
(escape_sequence) @constant.character.escape
3776
77+
(comment) @comment.line
78+
(block_comment) @comment.block
79+
(directive) @keyword.directive
3880
39-
((symbol) @variable.builtin
40-
(#match? @variable.builtin "^[$]"))
81+
; operators
82+
83+
((symbol) @operator
84+
(#match? @operator "^(\\+|-|\\*|/|=|>|<|>=|<=|~=|#|\\.|\\?\\.|\\.\\.|//|%|\\^)$"))
4185
42-
(binding) @symbol
86+
; keywords
4387
44-
[ "fn" "lambda" "hashfn" "#" ] @keyword.function
88+
(list
89+
.
90+
((symbol) @keyword.conditional
91+
(#match? @keyword.conditional "^(if|case|match|when|unless)$"
92+
)))
4593
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+
))
50100
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+
))
55107
56-
(multi_symbol
57-
"." @punctuation.delimiter
58-
(symbol) @variable.other.member)
108+
; special forms
59109
60-
(multi_symbol_method
61-
":" @punctuation.delimiter
62-
(symbol) @function.method .)
110+
(list
111+
"["
112+
(symbol)+ @variable
113+
"]")
63114
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"))
68122
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)$"))
72132
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
77134
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
81139
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
86141
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
91147
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 "."))
95163
96-
(list . (symbol) @function)
97-
(list . (multi_symbol (symbol) @function .))
98164
(symbol) @variable
165+
166+
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
167+
168+
(quote "'") @operator
169+
(unquote_splicing ",@") @operator
170+
(unquote ",") @operator
171+
(quasiquote "`") @operator
172+
99173
'';
100174
programs.helix = {
101175
enable = true;
@@ -455,7 +529,7 @@ in {
455529
args = ["-"];
456530
};
457531
language-servers = ["fennel-ls" "lsp-ai"];
458-
grammar = "fennel";
532+
grammar = "scheme";
459533
auto-format = true;
460534
}
461535
{

0 commit comments

Comments
 (0)