@@ -276,16 +276,13 @@ If VERSION and OS are not spcified, use the defaults of
276
276
(format " tree-sitter-grammars-%s -%s .tar%s "
277
277
os version ext))
278
278
279
- (defun tree-sitter-langs-compile (lang-symbol &optional clean target )
280
- " Download and compile the grammar for LANG-SYMBOL.
281
- This function requires git and tree-sitter CLI.
279
+ (defun tree-sitter-langs--compile (lang-symbol dir &optional paths target )
280
+ " Download and compile the grammar at DIR for LANG-SYMBOL.
282
281
283
- If the optional arg CLEAN is non-nil, compile from the revision recorded in this
284
- project (through git submodules), and clean up afterwards. Otherwise, compile
285
- from the current state of the grammar repo, without cleanup."
286
- (message " [tree-sitter-langs] Processing %s " lang-symbol)
287
- (unless (executable-find " git" )
288
- (error " Could not find git (needed to download grammars) " ))
282
+ If a directory contains multiple subgrammars, PATHS may be used to specify them.
283
+ TARGET allows a cross-compilation target to be specified.
284
+
285
+ This function requires tree-sitter CLI."
289
286
(unless (executable-find " tree-sitter" )
290
287
(error " Could not find tree-sitter executable (needed to compile grammars) " ))
291
288
(setq target
@@ -294,32 +291,11 @@ from the current state of the grammar repo, without cleanup."
294
291
(" aarch64-apple-darwin" " arm64-apple-macos11" )
295
292
(" nil" nil )
296
293
(_ (error " Unsupported cross-compilation target %s " target))))
297
- (let* ((source (tree-sitter-langs--source lang-symbol))
298
- (dir (if source
299
- (file-name-as-directory
300
- (concat (tree-sitter-langs--repos-dir)
301
- (symbol-name lang-symbol)))
302
- (error " Unknown language `%s' " lang-symbol)))
303
- (sub-path (format " repos/%s " lang-symbol))
304
- (status (tree-sitter-langs--repo-status lang-symbol))
305
- (paths (plist-get source :paths ))
294
+ (let* ((paths (or paths '(" " )))
306
295
(bin-dir (tree-sitter-langs--bin-dir))
307
296
(tree-sitter-langs--out (tree-sitter-langs--buffer
308
297
(format " *tree-sitter-langs-compile %s * " lang-symbol))))
309
- (let ((default-directory tree-sitter-langs-git-dir))
310
- (pcase status
311
- (:uninitialized
312
- (tree-sitter-langs--call " git" " submodule" " update" " --init" " --checkout" " --" sub-path))
313
- (:modified
314
- (when clean
315
- (let ((default-directory dir))
316
- (tree-sitter-langs--call " git" " stash" " push" ))
317
- (tree-sitter-langs--call " git" " submodule" " update" " --init" " --checkout" " --force" " --" sub-path)))
318
- (:conflicts
319
- (error " Unresolved conflicts in %s " dir))
320
- (:synchronized nil )
321
- (_
322
- (error " Weird status from git-submodule '%s ' " status))))
298
+
323
299
(let ((default-directory dir))
324
300
(when (member lang-symbol tree-sitter-langs--langs-with-deps)
325
301
(tree-sitter-langs--call " npm" " set" " progress=false" )
@@ -365,7 +341,8 @@ from the current state of the grammar repo, without cleanup."
365
341
" src/parser.c"
366
342
" -o" (format " %s bin/%s .so" tree-sitter-langs-grammar-dir lang-symbol)
367
343
" -target" target))))
368
- (:default (tree-sitter-langs--call " tree-sitter" " test" )))))
344
+ (:default
345
+ (tree-sitter-langs--call " tree-sitter" " test" )))))
369
346
; ; Replace underscores with hyphens. Example: c_sharp.
370
347
(let ((default-directory bin-dir))
371
348
(dolist (file (directory-files default-directory))
@@ -386,10 +363,45 @@ from the current state of the grammar repo, without cleanup."
386
363
(let ((new-name (concat (file-name-base file) " .dylib" )))
387
364
(when (file-exists-p new-name)
388
365
(delete-file new-name))
389
- (rename-file file new-name))))))
390
- (when clean
391
- (tree-sitter-langs--call " git" " reset" " --hard" " HEAD" )
392
- (tree-sitter-langs--call " git" " clean" " -f" )))))
366
+ (rename-file file new-name)))))))))
367
+
368
+ (defun tree-sitter-langs-compile (lang-symbol &optional clean target )
369
+ " Download and compile the grammar for LANG-SYMBOL.
370
+ This function requires git and tree-sitter CLI.
371
+
372
+ If the optional arg CLEAN is non-nil, compile from the revision recorded in this
373
+ project (through git submodules), and clean up afterwards. Otherwise, compile
374
+ from the current state of the grammar repo, without cleanup."
375
+ (message " [tree-sitter-langs] Processing %s " lang-symbol)
376
+ (unless (executable-find " git" )
377
+ (error " Could not find git (needed to download grammars) " ))
378
+ (let* ((source (tree-sitter-langs--source lang-symbol))
379
+ (dir (if source
380
+ (file-name-as-directory
381
+ (concat (tree-sitter-langs--repos-dir)
382
+ (symbol-name lang-symbol)))
383
+ (error " Unknown language `%s' " lang-symbol)))
384
+ (sub-path (format " repos/%s " lang-symbol))
385
+ (status (tree-sitter-langs--repo-status lang-symbol))
386
+ (paths (plist-get source :paths )))
387
+ (let ((default-directory tree-sitter-langs-git-dir))
388
+ (pcase status
389
+ (:uninitialized
390
+ (tree-sitter-langs--call " git" " submodule" " update" " --init" " --checkout" " --" sub-path))
391
+ (:modified
392
+ (when clean
393
+ (let ((default-directory dir))
394
+ (tree-sitter-langs--call " git" " stash" " push" ))
395
+ (tree-sitter-langs--call " git" " submodule" " update" " --init" " --checkout" " --force" " --" sub-path)))
396
+ (:conflicts
397
+ (error " Unresolved conflicts in %s " dir))
398
+ (:synchronized nil )
399
+ (_
400
+ (error " Weird status from git-submodule '%s ' " status))))
401
+ (tree-sitter-langs--compile lang-symbol (expand-file-name sub-path) paths target)
402
+ (when clean
403
+ (tree-sitter-langs--call " git" " reset" " --hard" " HEAD" )
404
+ (tree-sitter-langs--call " git" " clean" " -f" ))))
393
405
394
406
(cl-defun tree-sitter-langs-create-bundle (&optional clean target )
395
407
" Create a bundle of language grammars.
@@ -521,16 +533,17 @@ non-nil."
521
533
(when (bound-and-true-p dired-omit-mode)
522
534
(dired-omit-mode -1 )))))))
523
535
524
- (defun tree-sitter-langs--copy-query (lang-symbol &optional force )
536
+ (defun tree-sitter-langs--copy-query (lang-symbol &optional src-dir force )
525
537
" Copy highlights.scm file of LANG-SYMBOL to `tree-sitter-langs--queries-dir' .
526
538
This assumes the repo has already been set up, for example by
527
539
`tree-sitter-langs-compile' .
528
540
529
- If the optional arg FORCE is non-nil, any existing file will be overwritten."
530
- (let ((src (thread-first (tree-sitter-langs--repos-dir)
531
- (concat (symbol-name lang-symbol))
532
- file-name-as-directory (concat " queries" )
533
- file-name-as-directory (concat " highlights.scm" ))))
541
+ If the optional arg FORCE is non-nil, any existing file will be overwritten.
542
+ If the optional arg SRC-DIR is non-nil, highlights will be extracted from
543
+ the provided directory."
544
+ (let ((src (thread-first (or src-dir (concat (tree-sitter-langs--repos-dir) (symbol-name lang-symbol)))
545
+ file-name-as-directory (concat " queries" )
546
+ file-name-as-directory (concat " highlights.scm" ))))
534
547
(when (file-exists-p src)
535
548
(let ((dst-dir (file-name-as-directory
536
549
(concat tree-sitter-langs--queries-dir
0 commit comments