Coverage report: /home/ellis/comp/core/lib/syn/ts.lisp

KindCoveredAll%
expression1553 28.3
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; ts.lisp --- Tree-sitter API
2
 
3
 ;; High-level Tree-sitter API
4
 
5
 ;;; Commentary:
6
 
7
 ;; Tree-sitter is currently the most well-supported syntax parsing backend in
8
 ;; use by IDEs, and we can generally rely on the various language grammars
9
 ;; defined via tree-sitter. As we progress we may adapt other more direct
10
 ;; methods of building ASTs by querying compilers directly, but for now we
11
 ;; have some catching up to do :).
12
 
13
 ;;; Code:
14
 (in-package :syn/ts)
15
 (load-tree-sitter)
16
 (load-tree-sitter-alien)
17
 
18
 ;; (setq syn/lang:*language* :rust)
19
 (defmacro with-lang (lang &body body)
20
   `(with-ts-lang syn/lang:*language* ,lang
21
      ,@body))
22
 
23
 (defun lang-stats (lang)
24
   (with-ts-lang lang l
25
     (cons (ts-language-symbol-count l)
26
           (ts-language-field-count l))))
27
 
28
 (defun parse-file (lang path &key (produce-cst t) (consume t) (start 0) (end))
29
   (parse-string 
30
    lang
31
    (with-output-to-string (s)
32
      (write-file-into-stream path s))
33
    :consume consume
34
    :produce-cst produce-cst
35
    :start start
36
    :end end))
37
 
38
 (defun ts-file-query (lang path query)
39
   (let ((input (with-output-to-string (s) (write-file-into-stream path s))))
40
     (with-ts-query (q lang query (length query))
41
       (with-ts-query-cursor c
42
         (let ((tree (parse-string lang input :consume nil)))
43
           (tree-sitter::ts-query-cursor-exec-pointer c q (tree-sitter::ts-tree-root-node-pointer tree))
44
           c)))))