Coverage report: /home/ellis/comp/core/ffi/tree-sitter/ffi.lisp

KindCoveredAll%
expression083 0.0
branch00nil
Key
Not instrumented
Conditionalized out
Executed
Not executed
 
Both branches taken
One branch taken
Neither branch taken
1
 ;;; ffi/tree-sitter/ffi.lisp --- Low-level FFI bindings for Tree-sitter
2
 
3
 ;;
4
 
5
 ;; see https://github.com/death/cl-tree-sitter for an alternative
6
 ;; implementation - has functions for working on pointers instead of
7
 ;; raw objects like below:
8
 
9
 ;;(defar ts-node-start-point-pointer ts-point (self (* ts-node)))
10
 ;;(defar ts-node-end-point-pointer ts-point (self (* ts-node)))
11
 
12
 ;;; Code:
13
 (in-package :tree-sitter)
14
 
15
 ;;; Alien Types
16
 (define-alien-type ts-state-id unsigned-int)
17
 (define-alien-type ts-symbol unsigned-int)
18
 (define-alien-type ts-field-id unsigned-int)
19
 (define-alien-type ts-language (struct ts-language))
20
 (define-alien-type ts-parser (struct ts-parser))
21
 (define-alien-type ts-tree (struct ts-tree))
22
 (define-alien-enum (ts-query-error unsigned-int)
23
   :none 0
24
   :syntax 1
25
   :node-type 2
26
   :field 3
27
   :capture 4)
28
 
29
 (define-alien-type ts-query 
30
     (struct ts-query
31
       ;; ts-query
32
       (query (* t))
33
       (error-offset unsigned-int)
34
       (error-type ts-query-error)))
35
 
36
 (define-alien-type ts-query-cursor (struct ts-query-cursor))
37
 (define-alien-type ts-query-cursor-state
38
     (struct ts-query-cursor-state
39
       (payload (* t))
40
       (current-byte-offset unsigned-int)))
41
 
42
 (define-alien-type ts-node
43
     (struct ts-node
44
             (context (array unsigned-int 4))
45
             (id (* t))
46
             (tree (* ts-tree))))
47
 
48
 (define-alien-type ts-query-capture
49
     (struct ts-query-capture
50
       (node ts-node)
51
       (index unsigned-int)))
52
 
53
 (define-alien-type ts-query-match
54
     (struct ts-query-match
55
       (id unsigned-int)
56
       (pattern-index unsigned-short)
57
       (capture-count unsigned-short)
58
       ;; (* ts-query-capture)
59
       (captures (* t))))
60
 
61
 (define-alien-type ts-query-cursor-options 
62
   (struct ts-query-cursor-options
63
     (payload (* t))
64
     (state (* ts-query-cursor-state))))
65
 
66
 (define-alien-type ts-lookahead-iterator (struct ts-lookahead-iterator))
67
 
68
 (define-alien-type ts-point
69
     (struct ts-point
70
             (row unsigned-int)
71
             (column unsigned-int)))
72
 
73
 (define-alien-type ts-range
74
   (struct ts-range
75
           (start-point ts-point)
76
           (end-point ts-point)
77
           (start-byte unsigned-int)
78
           (end-byte unsigned-int)))
79
           
80
 (define-alien-enum (ts-log-type int)
81
                    :parse 0
82
                    :lex 1)
83
 
84
 (define-alien-type ts-logger
85
     (struct nil
86
             (payload (* t))
87
             (log (* (function void (* t) ts-log-type c-string)))))
88
 
89
 (define-alien-type ts-input-edit
90
   (struct ts-input-edit
91
           (start-byte unsigned-int)
92
           (old-end-byte unsigned-int)
93
           (new-end-byte unsigned-int)
94
           (start-point ts-point)
95
           (old-end-point ts-point)
96
           (new-end-point ts-point)))
97
 
98
 (define-alien-type ts-tree-cursor 
99
     (struct nil
100
             (tree (* ts-tree))
101
             (id (* t))
102
             (context (array unsigned-int 2))))
103
 
104
 (define-alien-enum (ts-input-encoding int)
105
                    :utf-8 0
106
                    :utf-16 2)
107
 
108
 (define-alien-enum (ts-symbol-type int)
109
                    :regular 0
110
                    :anonymous 1
111
                    :auxiliary 2)
112
 
113
 (define-alien-type ts-input (struct ts-input
114
                                     (payload (* t))
115
                                     (read (* (function c-string (* t)
116
                                                        unsigned-int
117
                                                        ts-point
118
                                                        (* unsigned-int))))
119
                                     (encoding ts-input-encoding)))
120
 
121
 ;;; Parser
122
 (defar ts-parser-new (* ts-parser))
123
 (defar ts-parser-delete void (self (* ts-parser)))
124
 (defar ts-parser-reset void (self (* ts-parser)))
125
 (defar ts-parser-set-language boolean (self (* ts-parser)) (language (* ts-language)))
126
 (defar ts-parser-language (* ts-language) (self (* ts-parser)))
127
 ;; (defar ts-parser-parse (* ts-tree) (self (* ts-parser)) (old-tree (* ts-tree)) (input ts-input))
128
 (defar ts-parser-parse-string (* ts-tree) (self (* ts-parser)) (old-tree (* ts-tree)) (string c-string) (length unsigned-int))
129
 ;; Set the file descriptor to which the parser should write debugging graphs
130
 ;; during parsing. The graphs are formatted in the DOT language. You may want
131
 ;; to pipe these graphs directly to a `dot(1)` process in order to generate
132
 ;; SVG output. You can turn off this logging by passing a negative number.
133
 (defar ts-parser-print-dot-graphs void (self (* ts-parser)) (fd int))
134
 ;;; Tree
135
 (defar ts-tree-copy (* ts-tree) (self (* ts-tree)))
136
 (defar ts-tree-delete void (self (* ts-tree)))
137
 (defar ts-tree-language (* ts-language) (self (* ts-tree)))
138
 (defar ts-tree-edit void (self (* ts-tree)) (edit (* unsigned-int)))
139
 (defar ts-tree-print-dot-graph void (self (* ts-tree)) (file-descriptor int))
140
 
141
 ;;; Tree Cursor
142
 (defar ts-tree-cursor-current-field-name c-string (cursor (* ts-tree-cursor)))
143
 (defar ts-tree-cursor-current-field-id ts-field-id (cursor (* ts-tree-cursor)))
144
 (defar ts-tree-cursor-current-descendant-index unsigned-int (cursor (* ts-tree-cursor)))
145
 (defar ts-tree-cursor-current-depth unsigned-int (cursor (* ts-tree-cursor)))
146
 (defar ts-tree-cursor-goto-next-sibling boolean (self (* ts-tree-cursor)))
147
 (defar ts-tree-cursor-goto-first-child-for-byte long (self (* ts-tree-cursor)) (goal-byte unsigned-int))
148
 (defar ts-tree-cursor-goto-first-child-for-point-pointer long (self (* ts-tree-cursor)) (goal-point (* ts-point)))
149
 (defar ts-tree-cursor-goto-parent boolean (self (* ts-tree-cursor)))
150
 (defar ts-tree-cursor-copy-pointer (* ts-tree-cursor) (cursor (* ts-tree-cursor)))
151
 (defar ts-tree-cursor-goto-first-child boolean (self (* ts-tree-cursor)))
152
 (defar ts-tree-cursor-goto-last-child boolean (self (* ts-tree-cursor)))
153
 (defar ts-tree-cursor-goto-descendant void (self (* ts-tree-cursor)) (goal-descendant-index unsigned-int))
154
 (defar ts-tree-cursor-delete void (cursor (* ts-tree-cursor)))
155
 
156
 (defar ts-language-version unsigned-int (v (* ts-language)))
157
 (defar ts-language-symbol-count unsigned-int (v (* ts-language)))
158
 (defar ts-language-symbol-name c-string (v (* ts-language)) (s (* ts-symbol)))
159
 (defar ts-language-symbol-type ts-symbol-type (v (* ts-language)) (s ts-symbol))
160
 (defar ts-language-field-count unsigned-int (v (* ts-language)))
161
 (defar ts-language-field-name-for-id c-string (v (* ts-language)) (id ts-field-id))
162
 (defar ts-language-field-id-for-name ts-field-id (v (* ts-language)) (name c-string) (nlen (unsigned 32)))
163
 
164
 (defar ts-language-next-state ts-state-id 
165
   (self (* ts-language)) 
166
   (state ts-state-id)
167
   (symbol ts-symbol))
168
 
169
 ;;; Query
170
 (defar ts-query-new (* ts-query)
171
   (lang (* ts-language))
172
   (source (* char))
173
   (source-len unsigned-int)
174
   (error-offset (* unsigned-int))
175
   (error-type (* ts-query-error)))
176
 
177
 (defar ts-query-delete void (query (* ts-query)))
178
 
179
 (defar ts-query-cursor-new (* ts-query-cursor))
180
 
181
 (defar ts-query-cursor-delete void
182
   (cursor (* ts-query-cursor)))
183
 
184
 (defar ts-query-pattern-count unsigned-int
185
   (self (* ts-query)))
186
 (defar ts-query-capture-count unsigned-int
187
   (self (* ts-query)))
188
 (defar ts-query-string-count unsigned-int
189
   (self (* ts-query)))
190
 
191
 ;;; ALIEN.C
192
 (defar ts-query-cursor-exec-pointer void
193
   (cursor (* ts-query-cursor))
194
   (query (* ts-query))
195
   (node (* ts-node)))
196
 
197
 (defar ts-query-cursor-exec-with-options-pointer void
198
   (cursor (* ts-query-cursor))
199
   (query (* ts-query))
200
   (node (* ts-node))
201
   (options (* ts-query-cursor-options)))
202
 
203
 (defar ts-query-cursor-next-match boolean
204
   (cursor (* ts-query-cursor))
205
   (match (* ts-query-match)))
206
 
207
 (defar ts-query-cursor-remove-match void
208
   (cursor (* ts-query-cursor))
209
   (match-id unsigned-int))
210
 
211
 (defar ts-query-cursor-next-capture boolean
212
   (cursor (* ts-query-cursor))
213
   (match (* ts-query-match))
214
   (capture-index (* unsigned-int)))
215
 
216
 (defar ts-query-cursor-set-max-start-depth void
217
   (cursor (* ts-query-cursor))
218
   (max-start-depth unsigned-int))
219
 
220
 (defar ts-tree-root-node-pointer (* ts-node)
221
   (tree (* ts-tree)))
222
 
223
 (defar ts-tree-cursor-new-pointer (* ts-tree-cursor)
224
   (node (* ts-node)))
225
 
226
 (defar ts-node-is-named-pointer boolean
227
   (node (* ts-node)))
228
 
229
 (defar ts-tree-cursor-current-node-pointer (* ts-node)
230
   (cursor (* ts-tree-cursor)))
231
 
232
 (defar ts-node-start-point-pointer (* ts-point)
233
   (node (* ts-node)))
234
 
235
 (defar ts-node-end-point-pointer (* ts-point)
236
   (node (* ts-node)))
237
 
238
 (defar ts-node-type-pointer c-string
239
   (node (* ts-node)))
240
 
241
 (defar ts-node-string-pointer c-string
242
   (node (* ts-node)))
243
 
244
 (defar ts-node-start-byte-pointer unsigned-int
245
   (node (* ts-node)))
246
 
247
 (defar ts-node-end-byte-pointer unsigned-int
248
   (node (* ts-node)))
249
 
250
 (defar ts-node-child-count-pointer unsigned-int
251
   (node (* ts-node)))
252
 
253
 (defar ts-node-parent-pointer (* ts-node)
254
   (node (* ts-node)))
255