Commit
+287 -156 +/-3 browse
1 | diff --git a/build.ninja b/build.ninja |
2 | index 4ba944b..fe7ee53 100644 |
3 | --- a/build.ninja |
4 | +++ b/build.ninja |
5 | @@ -1,5 +1,5 @@ |
6 | # automatically generated, do not edit. |
7 | - cc = cc -shared -fno-exceptions -g |
8 | + cc = cc -shared -fno-exceptions -g -fPIC |
9 | rule copy |
10 | command = cp $in $out |
11 | rule mkdir |
12 | @@ -9,165 +9,261 @@ rule ts-compile |
13 | rule fix-scanner-include |
14 | command = cat $in | sed "s/..\/..\/common\/scanner.h/common\/scanner.h/g" $ |
15 | > $out |
16 | - rule compile |
17 | - command = $cc $in -o $out |
18 | build target: mkdir |
19 | build target/bash: mkdir |
20 | build target/bash/parser.c: copy grammars/tree-sitter-bash/src/parser.c |
21 | build target/bash/scanner.c: copy grammars/tree-sitter-bash/src/scanner.c |
22 | - build target/bash/highlights.scm: copy $ |
23 | - grammars/tree-sitter-bash/queries/highlights.scm |
24 | - build target/bash/bash.so: compile target/bash/parser.c |
25 | + build target/bash/queries/highlights.scm: copy $ |
26 | + grammars/tree-sitter-bash/src/../queries/highlights.scm |
27 | + rule compile_bash |
28 | + command = $cc $in -o $out |
29 | + build target/bash/bash.so: compile_bash target/bash/parser.c $ |
30 | + target/bash/scanner.c |
31 | build target/c: mkdir |
32 | build target/c/parser.c: copy grammars/tree-sitter-c/src/parser.c |
33 | - build target/c/highlights.scm: copy $ |
34 | - grammars/tree-sitter-c/queries/highlights.scm |
35 | - build target/c/c.so: compile target/c/parser.c |
36 | + build target/c/queries/highlights.scm: copy $ |
37 | + grammars/tree-sitter-c/src/../queries/highlights.scm |
38 | + rule compile_c |
39 | + command = $cc $in -o $out |
40 | + build target/c/c.so: compile_c target/c/parser.c |
41 | build target/c-sharp: mkdir |
42 | build target/c-sharp/parser.c: copy grammars/tree-sitter-c-sharp/src/parser.c |
43 | build target/c-sharp/scanner.c: copy $ |
44 | grammars/tree-sitter-c-sharp/src/scanner.c |
45 | - build target/c-sharp/highlights.scm: copy $ |
46 | - grammars/tree-sitter-c-sharp/queries/highlights.scm |
47 | - build target/c-sharp/c-sharp.so: compile target/c-sharp/parser.c |
48 | + build target/c-sharp/queries/tags.scm: copy $ |
49 | + grammars/tree-sitter-c-sharp/src/../queries/tags.scm |
50 | + build target/c-sharp/queries/highlights.scm: copy $ |
51 | + grammars/tree-sitter-c-sharp/src/../queries/highlights.scm |
52 | + rule compile_c-sharp |
53 | + command = $cc $in -o $out |
54 | + build target/c-sharp/c-sharp.so: compile_c-sharp target/c-sharp/parser.c $ |
55 | + target/c-sharp/scanner.c |
56 | build target/diff: mkdir |
57 | build target/diff/parser.c: copy grammars/tree-sitter-diff/src/parser.c |
58 | - build target/diff/highlights.scm: copy $ |
59 | - grammars/tree-sitter-diff/queries/highlights.scm |
60 | - build target/diff/diff.so: compile target/diff/parser.c |
61 | + build target/diff/queries/highlights.scm: copy $ |
62 | + grammars/tree-sitter-diff/src/../queries/highlights.scm |
63 | + rule compile_diff |
64 | + command = $cc $in -o $out |
65 | + build target/diff/diff.so: compile_diff target/diff/parser.c |
66 | build target/go: mkdir |
67 | build target/go/parser.c: copy grammars/tree-sitter-go/src/parser.c |
68 | - build target/go/highlights.scm: copy $ |
69 | - grammars/tree-sitter-go/queries/highlights.scm |
70 | - build target/go/go.so: compile target/go/parser.c |
71 | + build target/go/queries/tags.scm: copy $ |
72 | + grammars/tree-sitter-go/src/../queries/tags.scm |
73 | + build target/go/queries/highlights.scm: copy $ |
74 | + grammars/tree-sitter-go/src/../queries/highlights.scm |
75 | + build target/go/queries/structure.scm: copy $ |
76 | + grammars/tree-sitter-go/src/../queries/structure.scm |
77 | + rule compile_go |
78 | + command = $cc $in -o $out |
79 | + build target/go/go.so: compile_go target/go/parser.c |
80 | build target/haskell: mkdir |
81 | build target/haskell/parser.c: copy grammars/tree-sitter-haskell/src/parser.c |
82 | build target/haskell/scanner.c: copy $ |
83 | grammars/tree-sitter-haskell/src/scanner.c |
84 | - build target/haskell/highlights.scm: copy $ |
85 | - grammars/tree-sitter-haskell/queries/highlights.scm |
86 | - build target/haskell/haskell.so: compile target/haskell/parser.c |
87 | + build target/haskell/unicode.h: copy $ |
88 | + grammars/tree-sitter-haskell/src/unicode.h |
89 | + build target/haskell/queries/locals.scm: copy $ |
90 | + grammars/tree-sitter-haskell/src/../queries/locals.scm |
91 | + build target/haskell/queries/highlights.scm: copy $ |
92 | + grammars/tree-sitter-haskell/src/../queries/highlights.scm |
93 | + rule compile_haskell |
94 | + command = $cc $in -o $out |
95 | + build target/haskell/haskell.so: compile_haskell target/haskell/parser.c $ |
96 | + target/haskell/scanner.c |
97 | build target/html: mkdir |
98 | build target/html/parser.c: copy grammars/tree-sitter-html/src/parser.c |
99 | build target/html/scanner.c: copy grammars/tree-sitter-html/src/scanner.c |
100 | - build target/html/highlights.scm: copy $ |
101 | - grammars/tree-sitter-html/queries/highlights.scm |
102 | - build target/html/html.so: compile target/html/parser.c |
103 | + build target/html/tag.h: copy grammars/tree-sitter-html/src/tag.h |
104 | + build target/html/queries/injections.scm: copy $ |
105 | + grammars/tree-sitter-html/src/../queries/injections.scm |
106 | + build target/html/queries/highlights.scm: copy $ |
107 | + grammars/tree-sitter-html/src/../queries/highlights.scm |
108 | + rule compile_html |
109 | + command = $cc $in -o $out |
110 | + build target/html/html.so: compile_html target/html/parser.c $ |
111 | + target/html/scanner.c |
112 | build target/java: mkdir |
113 | build target/java/parser.c: copy grammars/tree-sitter-java/src/parser.c |
114 | - build target/java/highlights.scm: copy $ |
115 | - grammars/tree-sitter-java/queries/highlights.scm |
116 | - build target/java/java.so: compile target/java/parser.c |
117 | + build target/java/queries/tags.scm: copy $ |
118 | + grammars/tree-sitter-java/src/../queries/tags.scm |
119 | + build target/java/queries/highlights.scm: copy $ |
120 | + grammars/tree-sitter-java/src/../queries/highlights.scm |
121 | + rule compile_java |
122 | + command = $cc $in -o $out |
123 | + build target/java/java.so: compile_java target/java/parser.c |
124 | build target/javascript: mkdir |
125 | build target/javascript/parser.c: copy $ |
126 | grammars/tree-sitter-javascript/src/parser.c |
127 | build target/javascript/scanner.c: copy $ |
128 | grammars/tree-sitter-javascript/src/scanner.c |
129 | - build target/javascript/highlights.scm: copy $ |
130 | - grammars/tree-sitter-javascript/queries/highlights.scm |
131 | - build target/javascript/javascript.so: compile target/javascript/parser.c |
132 | + build target/javascript/queries/tags.scm: copy $ |
133 | + grammars/tree-sitter-javascript/src/../queries/tags.scm |
134 | + build target/javascript/queries/highlights-params.scm: copy $ |
135 | + grammars/tree-sitter-javascript/src/../queries/highlights-params.scm |
136 | + build target/javascript/queries/injections.scm: copy $ |
137 | + grammars/tree-sitter-javascript/src/../queries/injections.scm |
138 | + build target/javascript/queries/locals.scm: copy $ |
139 | + grammars/tree-sitter-javascript/src/../queries/locals.scm |
140 | + build target/javascript/queries/highlights.scm: copy $ |
141 | + grammars/tree-sitter-javascript/src/../queries/highlights.scm |
142 | + build target/javascript/queries/highlights-jsx.scm: copy $ |
143 | + grammars/tree-sitter-javascript/src/../queries/highlights-jsx.scm |
144 | + rule compile_javascript |
145 | + command = $cc $in -o $out |
146 | + build target/javascript/javascript.so: compile_javascript $ |
147 | + target/javascript/parser.c target/javascript/scanner.c |
148 | build target/json: mkdir |
149 | build target/json/parser.c: copy grammars/tree-sitter-json/src/parser.c |
150 | - build target/json/highlights.scm: copy $ |
151 | - grammars/tree-sitter-json/queries/highlights.scm |
152 | - build target/json/json.so: compile target/json/parser.c |
153 | + build target/json/queries/highlights.scm: copy $ |
154 | + grammars/tree-sitter-json/src/../queries/highlights.scm |
155 | + rule compile_json |
156 | + command = $cc $in -o $out |
157 | + build target/json/json.so: compile_json target/json/parser.c |
158 | build target/julia: mkdir |
159 | build target/julia/parser.c: copy grammars/tree-sitter-julia/src/parser.c |
160 | build target/julia/scanner.c: copy grammars/tree-sitter-julia/src/scanner.c |
161 | - build target/julia/julia.so: compile target/julia/parser.c |
162 | + rule compile_julia |
163 | + command = $cc $in -o $out |
164 | + build target/julia/julia.so: compile_julia target/julia/parser.c $ |
165 | + target/julia/scanner.c |
166 | build target/markdown: mkdir |
167 | build target/markdown/parser.c: copy $ |
168 | grammars/tree-sitter-markdown/tree-sitter-markdown/src/parser.c |
169 | build target/markdown/scanner.c: copy $ |
170 | grammars/tree-sitter-markdown/tree-sitter-markdown/src/scanner.c |
171 | - build target/markdown/markdown.so: compile target/markdown/parser.c |
172 | - build target/markdown-inline: mkdir |
173 | - build target/markdown-inline/parser.c: copy $ |
174 | - grammars/tree-sitter-markdown/tree-sitter-markdown-inline/src/parser.c |
175 | - build target/markdown-inline/scanner.c: copy $ |
176 | - grammars/tree-sitter-markdown/tree-sitter-markdown-inline/src/scanner.c |
177 | - build target/markdown-inline/highlights.scm: copy $ |
178 | - grammars/tree-sitter-markdown/tree-sitter-markdown-inline/queries/highlights.scm |
179 | - build target/markdown-inline/markdown-inline.so: compile $ |
180 | - target/markdown-inline/parser.c |
181 | + build target/markdown/queries/injections.scm: copy $ |
182 | + grammars/tree-sitter-markdown/tree-sitter-markdown/queries/injections.scm |
183 | + build target/markdown/queries/highlights.scm: copy $ |
184 | + grammars/tree-sitter-markdown/tree-sitter-markdown/queries/highlights.scm |
185 | + rule compile_markdown |
186 | + command = $cc $in -o $out |
187 | + build target/markdown/markdown.so: compile_markdown $ |
188 | + target/markdown/parser.c target/markdown/scanner.c |
189 | build target/ocaml: mkdir |
190 | build target/ocaml/parser.c: copy $ |
191 | grammars/tree-sitter-ocaml/ocaml/src/parser.c |
192 | build target/ocaml/scanner.c: fix-scanner-include $ |
193 | grammars/tree-sitter-ocaml/ocaml/src/scanner.c |
194 | - build target/ocaml/common: mkdir |
195 | build target/ocaml/common/scanner.h: copy $ |
196 | - grammars/tree-sitter-ocaml/ocaml/../common/scanner.h |
197 | - build target/ocaml/highlights.scm: copy $ |
198 | - grammars/tree-sitter-ocaml/ocaml/../queries/highlights.scm |
199 | - build target/ocaml/ocaml.so: compile target/ocaml/parser.c |
200 | + grammars/tree-sitter-ocaml/common/scanner.h |
201 | + build target/ocaml/queries/tags.scm: copy $ |
202 | + grammars/tree-sitter-ocaml/queries/tags.scm |
203 | + build target/ocaml/queries/locals.scm: copy $ |
204 | + grammars/tree-sitter-ocaml/queries/locals.scm |
205 | + build target/ocaml/queries/highlights.scm: copy $ |
206 | + grammars/tree-sitter-ocaml/queries/highlights.scm |
207 | + rule compile_ocaml |
208 | + command = $cc $in -o $out |
209 | + build target/ocaml/ocaml.so: compile_ocaml target/ocaml/parser.c $ |
210 | + target/ocaml/scanner.c |
211 | build target/php: mkdir |
212 | build target/php/parser.c: copy grammars/tree-sitter-php/src/parser.c |
213 | build target/php/scanner.c: copy grammars/tree-sitter-php/src/scanner.c |
214 | - build target/php/highlights.scm: copy $ |
215 | - grammars/tree-sitter-php/queries/highlights.scm |
216 | - build target/php/php.so: compile target/php/parser.c |
217 | + build target/php/queries/tags.scm: copy $ |
218 | + grammars/tree-sitter-php/src/../queries/tags.scm |
219 | + build target/php/queries/injections.scm: copy $ |
220 | + grammars/tree-sitter-php/src/../queries/injections.scm |
221 | + build target/php/queries/highlights.scm: copy $ |
222 | + grammars/tree-sitter-php/src/../queries/highlights.scm |
223 | + rule compile_php |
224 | + command = $cc $in -o $out |
225 | + build target/php/php.so: compile_php target/php/parser.c target/php/scanner.c |
226 | build target/python: mkdir |
227 | build target/python/parser.c: copy grammars/tree-sitter-python/src/parser.c |
228 | build target/python/scanner.c: copy grammars/tree-sitter-python/src/scanner.c |
229 | - build target/python/highlights.scm: copy $ |
230 | - grammars/tree-sitter-python/queries/highlights.scm |
231 | - build target/python/python.so: compile target/python/parser.c |
232 | + build target/python/queries/tags.scm: copy $ |
233 | + grammars/tree-sitter-python/src/../queries/tags.scm |
234 | + build target/python/queries/highlights.scm: copy $ |
235 | + grammars/tree-sitter-python/src/../queries/highlights.scm |
236 | + rule compile_python |
237 | + command = $cc $in -o $out |
238 | + build target/python/python.so: compile_python target/python/parser.c $ |
239 | + target/python/scanner.c |
240 | build target/regex: mkdir |
241 | build target/regex/parser.c: copy grammars/tree-sitter-regex/src/parser.c |
242 | - build target/regex/highlights.scm: copy $ |
243 | - grammars/tree-sitter-regex/queries/highlights.scm |
244 | - build target/regex/regex.so: compile target/regex/parser.c |
245 | - build target/ruby: mkdir |
246 | - build target/ruby/parser.c: copy grammars/tree-sitter-ruby/src/parser.c |
247 | - build target/ruby/highlights.scm: copy $ |
248 | - grammars/tree-sitter-ruby/queries/highlights.scm |
249 | - build target/ruby/ruby.so: compile target/ruby/parser.c |
250 | + build target/regex/queries/highlights.scm: copy $ |
251 | + grammars/tree-sitter-regex/src/../queries/highlights.scm |
252 | + rule compile_regex |
253 | + command = $cc $in -o $out |
254 | + build target/regex/regex.so: compile_regex target/regex/parser.c |
255 | build target/rust: mkdir |
256 | build target/rust/parser.c: copy grammars/tree-sitter-rust/src/parser.c |
257 | build target/rust/scanner.c: copy grammars/tree-sitter-rust/src/scanner.c |
258 | - build target/rust/highlights.scm: copy $ |
259 | - grammars/tree-sitter-rust/queries/highlights.scm |
260 | - build target/rust/rust.so: compile target/rust/parser.c |
261 | + build target/rust/queries/tags.scm: copy $ |
262 | + grammars/tree-sitter-rust/src/../queries/tags.scm |
263 | + build target/rust/queries/injections.scm: copy $ |
264 | + grammars/tree-sitter-rust/src/../queries/injections.scm |
265 | + build target/rust/queries/highlights.scm: copy $ |
266 | + grammars/tree-sitter-rust/src/../queries/highlights.scm |
267 | + rule compile_rust |
268 | + command = $cc $in -o $out |
269 | + build target/rust/rust.so: compile_rust target/rust/parser.c $ |
270 | + target/rust/scanner.c |
271 | build target/scala: mkdir |
272 | build target/scala/parser.c: copy grammars/tree-sitter-scala/src/parser.c |
273 | build target/scala/scanner.c: copy grammars/tree-sitter-scala/src/scanner.c |
274 | - build target/scala/highlights.scm: copy $ |
275 | + build target/scala/stack.h: copy grammars/tree-sitter-scala/src/stack.h |
276 | + build target/scala/queries/locals.scm: copy $ |
277 | + grammars/tree-sitter-scala/queries/scala/locals.scm |
278 | + build target/scala/queries/highlights.scm: copy $ |
279 | grammars/tree-sitter-scala/queries/scala/highlights.scm |
280 | - build target/scala/scala.so: compile target/scala/parser.c |
281 | + rule compile_scala |
282 | + command = $cc $in -o $out |
283 | + build target/scala/scala.so: compile_scala target/scala/parser.c $ |
284 | + target/scala/scanner.c |
285 | build target/sql: mkdir |
286 | build target/sql/parser.c: copy grammars/tree-sitter-sql/src/parser.c |
287 | - build target/sql/highlights.scm: copy $ |
288 | - grammars/tree-sitter-sql/queries/highlights.scm |
289 | - build target/sql/sql.so: compile target/sql/parser.c |
290 | + build target/sql/queries/indents.scm: copy $ |
291 | + grammars/tree-sitter-sql/src/../queries/indents.scm |
292 | + build target/sql/queries/highlights.scm: copy $ |
293 | + grammars/tree-sitter-sql/src/../queries/highlights.scm |
294 | + rule compile_sql |
295 | + command = $cc $in -o $out |
296 | + build target/sql/sql.so: compile_sql target/sql/parser.c |
297 | build target/toml: mkdir |
298 | build target/toml/parser.c: copy grammars/tree-sitter-toml/src/parser.c |
299 | build target/toml/scanner.c: copy grammars/tree-sitter-toml/src/scanner.c |
300 | - build target/toml/highlights.scm: copy $ |
301 | - grammars/tree-sitter-toml/queries/highlights.scm |
302 | - build target/toml/toml.so: compile target/toml/parser.c |
303 | + build target/toml/queries/highlights.scm: copy $ |
304 | + grammars/tree-sitter-toml/src/../queries/highlights.scm |
305 | + rule compile_toml |
306 | + command = $cc $in -o $out |
307 | + build target/toml/toml.so: compile_toml target/toml/parser.c $ |
308 | + target/toml/scanner.c |
309 | build target/typescript: mkdir |
310 | build target/typescript/parser.c: copy $ |
311 | grammars/tree-sitter-typescript/typescript/src/parser.c |
312 | build target/typescript/scanner.c: fix-scanner-include $ |
313 | grammars/tree-sitter-typescript/typescript/src/scanner.c |
314 | - build target/typescript/common: mkdir |
315 | build target/typescript/common/scanner.h: copy $ |
316 | - grammars/tree-sitter-typescript/typescript/../common/scanner.h |
317 | - build target/typescript/highlights.scm: copy $ |
318 | - grammars/tree-sitter-typescript/typescript/../queries/highlights.scm |
319 | - build target/typescript/typescript.so: compile target/typescript/parser.c |
320 | + grammars/tree-sitter-typescript/common/scanner.h |
321 | + build target/typescript/queries/tags.scm: copy $ |
322 | + grammars/tree-sitter-typescript/queries/tags.scm |
323 | + build target/typescript/queries/locals.scm: copy $ |
324 | + grammars/tree-sitter-typescript/queries/locals.scm |
325 | + build target/typescript/queries/highlights.scm: copy $ |
326 | + grammars/tree-sitter-typescript/queries/highlights.scm |
327 | + rule compile_typescript |
328 | + command = $cc $in -o $out |
329 | + build target/typescript/typescript.so: compile_typescript $ |
330 | + target/typescript/parser.c target/typescript/scanner.c |
331 | build target/tsx: mkdir |
332 | build target/tsx/parser.c: copy $ |
333 | grammars/tree-sitter-typescript/tsx/src/parser.c |
334 | build target/tsx/scanner.c: fix-scanner-include $ |
335 | grammars/tree-sitter-typescript/tsx/src/scanner.c |
336 | - build target/tsx/common: mkdir |
337 | build target/tsx/common/scanner.h: copy $ |
338 | - grammars/tree-sitter-typescript/tsx/../common/scanner.h |
339 | - build target/tsx/highlights.scm: copy $ |
340 | - grammars/tree-sitter-typescript/tsx/../queries/highlights.scm |
341 | - build target/tsx/tsx.so: compile target/tsx/parser.c |
342 | + grammars/tree-sitter-typescript/common/scanner.h |
343 | + build target/tsx/queries/tags.scm: copy $ |
344 | + grammars/tree-sitter-typescript/queries/tags.scm |
345 | + build target/tsx/queries/locals.scm: copy $ |
346 | + grammars/tree-sitter-typescript/queries/locals.scm |
347 | + build target/tsx/queries/highlights.scm: copy $ |
348 | + grammars/tree-sitter-typescript/queries/highlights.scm |
349 | + rule compile_tsx |
350 | + command = $cc $in -o $out |
351 | + build target/tsx/tsx.so: compile_tsx target/tsx/parser.c target/tsx/scanner.c |
352 | build target/verilog: mkdir |
353 | build target/verilog/parser.c: copy grammars/tree-sitter-verilog/src/parser.c |
354 | - build target/verilog/verilog.so: compile target/verilog/parser.c |
355 | + rule compile_verilog |
356 | + command = $cc $in -o $out |
357 | + build target/verilog/verilog.so: compile_verilog target/verilog/parser.c |
358 | diff --git a/build.py b/build.py |
359 | index d6262b8..71e6c64 100755 |
360 | --- a/build.py |
361 | +++ b/build.py |
362 | @@ -1,62 +1,99 @@ |
363 | #!/usr/bin/env python |
364 | |
365 | + from glob import glob |
366 | from collections import namedtuple |
367 | from os import path |
368 | |
369 | import ninja_syntax |
370 | |
371 | - Source = namedtuple("Source", ["name", "path", "includes", "highlights"]) |
372 | + # name of project and array of tuples where the first element is all of |
373 | + # the files to include and the second element is the target directory to copy |
374 | + # them into. If the second element is None it will go to the root path |
375 | + Source = namedtuple("Source", ["name", "includes"]) |
376 | + |
377 | + |
378 | + # default source layout in use for most tree-sitter projects |
379 | + def _default_config(name, basepath): |
380 | + return Source( |
381 | + name, |
382 | + [ |
383 | + (glob(f"{basepath}/*.c"), None), |
384 | + (glob(f"{basepath}/*.h"), None), |
385 | + (glob(f"{basepath}/../queries/*.scm"), "queries"), |
386 | + ], |
387 | + ) |
388 | + |
389 | |
390 | sources = [ |
391 | - Source("bash", "grammars/tree-sitter-bash", [], "queries/highlights.scm"), |
392 | - Source("c", "grammars/tree-sitter-c", [], "queries/highlights.scm"), |
393 | - Source("c-sharp", "grammars/tree-sitter-c-sharp", [], "queries/highlights.scm"), |
394 | - Source("diff", "grammars/tree-sitter-diff", [], "queries/highlights.scm"), |
395 | - Source("go", "grammars/tree-sitter-go", [], "queries/highlights.scm"), |
396 | - Source("haskell", "grammars/tree-sitter-haskell", [], "queries/highlights.scm"), |
397 | - Source("html", "grammars/tree-sitter-html", [], "queries/highlights.scm"), |
398 | - Source("java", "grammars/tree-sitter-java", [], "queries/highlights.scm"), |
399 | + _default_config("bash", "grammars/tree-sitter-bash/src"), |
400 | + _default_config("c", "grammars/tree-sitter-c/src"), |
401 | + _default_config("c-sharp", "grammars/tree-sitter-c-sharp/src"), |
402 | + _default_config("diff", "grammars/tree-sitter-diff/src"), |
403 | + _default_config("go", "grammars/tree-sitter-go/src"), |
404 | + _default_config("haskell", "grammars/tree-sitter-haskell/src"), |
405 | + _default_config("html", "grammars/tree-sitter-html/src"), |
406 | + _default_config("java", "grammars/tree-sitter-java/src"), |
407 | + _default_config("javascript", "grammars/tree-sitter-javascript/src"), |
408 | + _default_config("json", "grammars/tree-sitter-json/src"), |
409 | + _default_config("julia", "grammars/tree-sitter-julia/src"), |
410 | Source( |
411 | - "javascript", "grammars/tree-sitter-javascript", [], "queries/highlights.scm" |
412 | + "markdown", |
413 | + [ |
414 | + (glob("grammars/tree-sitter-markdown/tree-sitter-markdown/src/*.c"), None), |
415 | + ( |
416 | + glob( |
417 | + "grammars/tree-sitter-markdown/tree-sitter-markdown/queries/*.scm" |
418 | + ), |
419 | + "queries", |
420 | + ), |
421 | + ], |
422 | ), |
423 | - Source("json", "grammars/tree-sitter-json", [], "queries/highlights.scm"), |
424 | - Source("julia", "grammars/tree-sitter-julia", [], None), |
425 | - Source("markdown", "grammars/tree-sitter-markdown/tree-sitter-markdown", [], None), |
426 | Source( |
427 | - "markdown-inline", |
428 | - "grammars/tree-sitter-markdown/tree-sitter-markdown-inline", |
429 | - [], |
430 | - "queries/highlights.scm", |
431 | + "ocaml", |
432 | + [ |
433 | + (glob("grammars/tree-sitter-ocaml/ocaml/src/*.c"), None), |
434 | + (glob("grammars/tree-sitter-ocaml/common/*.h"), "common"), |
435 | + (glob("grammars/tree-sitter-ocaml/queries/*.scm"), "queries"), |
436 | + ], |
437 | ), |
438 | + _default_config("php", "grammars/tree-sitter-php/src"), |
439 | + _default_config("python", "grammars/tree-sitter-python/src"), |
440 | + _default_config("regex", "grammars/tree-sitter-regex/src"), |
441 | + # TODO: ruby is using a cpp scanner and i'm not going to support it for now |
442 | + # _default_config("ruby", "grammars/tree-sitter-ruby"), |
443 | + _default_config("rust", "grammars/tree-sitter-rust/src"), |
444 | Source( |
445 | - "ocaml", |
446 | - "grammars/tree-sitter-ocaml/ocaml", |
447 | - [("../common/scanner.h", "common/scanner.h")], |
448 | - "../queries/highlights.scm", |
449 | + "scala", |
450 | + [ |
451 | + (glob("grammars/tree-sitter-scala/src/*.c"), None), |
452 | + (glob("grammars/tree-sitter-scala/src/*.h"), None), |
453 | + (glob("grammars/tree-sitter-scala/queries/scala/*.scm"), "queries"), |
454 | + ], |
455 | ), |
456 | - Source("php", "grammars/tree-sitter-php", [], "queries/highlights.scm"), |
457 | - Source("python", "grammars/tree-sitter-python", [], "queries/highlights.scm"), |
458 | - Source("regex", "grammars/tree-sitter-regex", [], "queries/highlights.scm"), |
459 | - Source("ruby", "grammars/tree-sitter-ruby", [], "queries/highlights.scm"), |
460 | - Source("rust", "grammars/tree-sitter-rust", [], "queries/highlights.scm"), |
461 | - Source("scala", "grammars/tree-sitter-scala", [], "queries/scala/highlights.scm"), |
462 | - Source("sql", "grammars/tree-sitter-sql", [], "queries/highlights.scm"), |
463 | - Source("toml", "grammars/tree-sitter-toml", [], "queries/highlights.scm"), |
464 | + _default_config("sql", "grammars/tree-sitter-sql/src"), |
465 | + _default_config("toml", "grammars/tree-sitter-toml/src"), |
466 | Source( |
467 | "typescript", |
468 | - "grammars/tree-sitter-typescript/typescript", |
469 | - [("../common/scanner.h", "common/scanner.h")], |
470 | - "../queries/highlights.scm", |
471 | + [ |
472 | + (glob("grammars/tree-sitter-typescript/typescript/src/*.c"), None), |
473 | + (glob("grammars/tree-sitter-typescript/typescript/src/*.h"), None), |
474 | + (glob("grammars/tree-sitter-typescript/common/*.h"), "common"), |
475 | + (glob("grammars/tree-sitter-typescript/queries/*.scm"), "queries"), |
476 | + ], |
477 | ), |
478 | Source( |
479 | "tsx", |
480 | - "grammars/tree-sitter-typescript/tsx", |
481 | - [("../common/scanner.h", "common/scanner.h")], |
482 | - "../queries/highlights.scm", |
483 | + [ |
484 | + (glob("grammars/tree-sitter-typescript/tsx/src/*.c"), None), |
485 | + (glob("grammars/tree-sitter-typescript/tsx/src/*.h"), None), |
486 | + (glob("grammars/tree-sitter-typescript/common/*.h"), "common"), |
487 | + (glob("grammars/tree-sitter-typescript/queries/*.scm"), "queries"), |
488 | + ], |
489 | ), |
490 | - Source("verilog", "grammars/tree-sitter-verilog", [], None), |
491 | + _default_config("verilog", "grammars/tree-sitter-verilog/src"), |
492 | ] |
493 | |
494 | + # these projects require an include fix |
495 | scanner_hacks = ["ocaml", "typescript", "tsx"] |
496 | |
497 | |
498 | @@ -64,45 +101,38 @@ if __name__ == "__main__": |
499 | with open("build.ninja", "w") as fp: |
500 | w = ninja_syntax.Writer(fp) |
501 | w.comment("automatically generated, do not edit.") |
502 | - w.variable("cc", "cc -shared -fno-exceptions -g") |
503 | + w.variable("cc", "cc -shared -fno-exceptions -g -fPIC") |
504 | w.rule("copy", command="cp $in $out") |
505 | w.rule("mkdir", command="mkdir -p $out") |
506 | w.rule("ts-compile", command="cd $in && tree-sitter generate") |
507 | sed_fix = "s/..\/..\/common\/scanner.h/common\/scanner.h/g" |
508 | w.rule("fix-scanner-include", command=f'cat $in | sed "{sed_fix}" > $out') |
509 | - w.rule("compile", command=f"$cc $in -o $out") |
510 | w.build("target", "mkdir") |
511 | for source in sources: |
512 | - w.build(path.join("target", source.name), "mkdir") |
513 | - parser_src_path = path.join(source.path, "src", "parser.c") |
514 | + target_root = path.join("target", source.name) |
515 | + w.build(target_root, "mkdir") |
516 | # NOTE: all parsers currently have committed their generated code |
517 | # so there isn't any reason to run this right now. |
518 | # w.build(parser_path, "ts-compile", [source.path]) |
519 | - parser_dst_path = path.join("target", source.name, "parser.c") |
520 | - w.build(parser_dst_path, "copy", inputs=[parser_src_path]) |
521 | - scanner_src_path = path.join(source.path, "src", "scanner.c") |
522 | - scanner_dst_path = path.join("target", source.name, "scanner.c") |
523 | - if path.exists(scanner_src_path): |
524 | - if source.name in scanner_hacks: |
525 | - w.build( |
526 | - scanner_dst_path, |
527 | - "fix-scanner-include", |
528 | - inputs=[scanner_src_path], |
529 | - ) |
530 | - else: |
531 | - w.build(scanner_dst_path, "copy", inputs=[scanner_src_path]) |
532 | + compile_inputs = [] |
533 | for include in source.includes: |
534 | - include_dst_dir = path.join("target", source.name, "common") |
535 | - w.build(include_dst_dir, "mkdir") |
536 | - include_src_path = path.join(source.path, include[0]) |
537 | - include_dst_path = path.join("target", source.name, include[1]) |
538 | - w.build(include_dst_path, "copy", inputs=[include_src_path]) |
539 | - |
540 | - if source.highlights: |
541 | - highlights_src_path = path.join(source.path, source.highlights) |
542 | - highlights_dst_path = path.join("target", source.name, "highlights.scm") |
543 | - w.build(highlights_dst_path, "copy", inputs=[highlights_src_path]) |
544 | - lib_out = path.join("target", source.name, f"{source.name}.so") |
545 | - w.build(lib_out, "compile", inputs=[parser_dst_path]) |
546 | - |
547 | + if include[1]: |
548 | + target_dir = path.join(target_root, include[1]) |
549 | + else: |
550 | + target_dir = target_root |
551 | + for include_path in include[0]: |
552 | + filename = path.basename(include_path) |
553 | + target_path = path.join(target_dir, filename) |
554 | + # hacks for scanner.c in sub-language projects |
555 | + if filename == "scanner.c" and source.name in scanner_hacks: |
556 | + w.build( |
557 | + target_path, "fix-scanner-include", inputs=[include_path] |
558 | + ) |
559 | + else: |
560 | + w.build(target_path, "copy", inputs=[include_path]) |
561 | + if filename in ["parser.c", "scanner.c"]: |
562 | + compile_inputs.append(target_path) |
563 | + lib_out = path.join(target_root, f"{source.name}.so") |
564 | + w.rule(f"compile_{source.name}", command=f"$cc $in -o $out") |
565 | + w.build(lib_out, f"compile_{source.name}", inputs=compile_inputs) |
566 | w.close() |
567 | diff --git a/install.sh b/install.sh |
568 | index 6e57778..1f9bdcb 100755 |
569 | --- a/install.sh |
570 | +++ b/install.sh |
571 | @@ -7,13 +7,18 @@ for name in `find target -maxdepth 1 -type d -printf '%f\n' | tail -n +2` ; do |
572 | install -d "/usr/include/tree-sitter-amalgamation/$name" |
573 | install -m 0444 -t "/usr/include/tree-sitter-amalgamation/$name" \ |
574 | target/$name/*.c |
575 | - [[ -f target/$name/highlights.scm ]] && { |
576 | - install -m 0444 -t "/usr/include/tree-sitter-amalgamation/$name" \ |
577 | - "target/$name/highlights.scm" |
578 | + install -m 0444 -t "/usr/include/tree-sitter-amalgamation/$name" \ |
579 | + target/$name/*.h 2>/dev/null || true |
580 | + [[ -d target/$name/queries ]] && { |
581 | + install -d "/usr/include/tree-sitter-amalgamation/$name/queries" |
582 | + install -m 0444 -t "/usr/include/tree-sitter-amalgamation/$name/queries" \ |
583 | + target/$name/queries/*.scm |
584 | } |
585 | - [[ -f target/$name/common/scanner.h ]] && { |
586 | + [[ -d target/$name/common ]] && { |
587 | install -d "/usr/include/tree-sitter-amalgamation/$name/common" |
588 | install -m 0444 -t "/usr/include/tree-sitter-amalgamation/$name/common" \ |
589 | - "target/$name/common/scanner.h" |
590 | + target/$name/common/*.c 2>/dev/null || true |
591 | + install -m 0444 -t "/usr/include/tree-sitter-amalgamation/$name/common" \ |
592 | + target/$name/common/*.h 2>/dev/null || true |
593 | } |
594 | done |