injections.scm

  1; Refer to https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/go/injections.scm#L4C1-L16C41
  2(call_expression
  3  (selector_expression) @_function
  4  (#any-of? @_function
  5    "regexp.Match" "regexp.MatchReader" "regexp.MatchString" "regexp.Compile" "regexp.CompilePOSIX"
  6    "regexp.MustCompile" "regexp.MustCompilePOSIX")
  7  (argument_list
  8    .
  9    [
 10      (raw_string_literal)
 11      (interpreted_string_literal)
 12    ] @injection.content
 13    (#set! injection.language "regex")
 14    ))
 15
 16; INJECT SQL
 17(
 18	[
 19		; var, const or short declaration of raw or interpreted string literal
 20		((comment) @comment
 21  		.
 22    	(expression_list
 23     	[
 24      		(interpreted_string_literal)
 25        	(raw_string_literal)
 26        ] @injection.content
 27        ))
 28
 29        ; when passing as a literal element (to struct field eg.)
 30		((comment) @comment
 31        .
 32        (literal_element
 33        [
 34        	(interpreted_string_literal)
 35        	(raw_string_literal)
 36        ] @injection.content
 37        ))
 38
 39        ; when passing as a function parameter
 40        ((comment) @comment
 41        .
 42        [
 43        	(interpreted_string_literal)
 44        	(raw_string_literal)
 45        ] @injection.content)
 46    ]
 47
 48    (#match? @comment "^\\/\\*\\s*sql\\s*\\*\\/") ; /* sql */ or /*sql*/
 49    (#set! injection.language "sql")
 50)
 51
 52; INJECT JSON
 53(
 54	[
 55		; var, const or short declaration of raw or interpreted string literal
 56		((comment) @comment
 57  		.
 58    	(expression_list
 59     	[
 60      		(interpreted_string_literal)
 61        	(raw_string_literal)
 62        ] @injection.content
 63        ))
 64
 65        ; when passing as a literal element (to struct field eg.)
 66		((comment) @comment
 67        .
 68        (literal_element
 69        [
 70        	(interpreted_string_literal)
 71        	(raw_string_literal)
 72        ] @injection.content
 73        ))
 74
 75        ; when passing as a function parameter
 76        ((comment) @comment
 77        .
 78        [
 79        	(interpreted_string_literal)
 80        	(raw_string_literal)
 81        ] @injection.content)
 82    ]
 83
 84    (#match? @comment "^\\/\\*\\s*json\\s*\\*\\/") ; /* json */ or /*json*/
 85    (#set! injection.language "json")
 86)
 87
 88; INJECT YAML
 89(
 90	[
 91		; var, const or short declaration of raw or interpreted string literal
 92		((comment) @comment
 93  		.
 94    	(expression_list
 95     	[
 96      		(interpreted_string_literal)
 97        	(raw_string_literal)
 98        ] @injection.content
 99        ))
100
101        ; when passing as a literal element (to struct field eg.)
102		((comment) @comment
103        .
104        (literal_element
105        [
106        	(interpreted_string_literal)
107        	(raw_string_literal)
108        ] @injection.content
109        ))
110
111        ; when passing as a function parameter
112        ((comment) @comment
113        .
114        [
115        	(interpreted_string_literal)
116        	(raw_string_literal)
117        ] @injection.content)
118    ]
119
120    (#match? @comment "^\\/\\*\\s*yaml\\s*\\*\\/") ; /* yaml */ or /*yaml*/
121    (#set! injection.language "yaml")
122)
123
124; INJECT XML
125(
126	[
127		; var, const or short declaration of raw or interpreted string literal
128		((comment) @comment
129  		.
130    	(expression_list
131     	[
132      		(interpreted_string_literal)
133        	(raw_string_literal)
134        ] @injection.content
135        ))
136
137        ; when passing as a literal element (to struct field eg.)
138		((comment) @comment
139        .
140        (literal_element
141        [
142        	(interpreted_string_literal)
143        	(raw_string_literal)
144        ] @injection.content
145        ))
146
147        ; when passing as a function parameter
148        ((comment) @comment
149        .
150        [
151        	(interpreted_string_literal)
152        	(raw_string_literal)
153        ] @injection.content)
154    ]
155
156    (#match? @comment "^\\/\\*\\s*xml\\s*\\*\\/") ; /* xml */ or /*xml*/
157    (#set! injection.language "xml")
158)
159
160; INJECT HTML
161(
162	[
163		; var, const or short declaration of raw or interpreted string literal
164		((comment) @comment
165  		.
166    	(expression_list
167     	[
168      		(interpreted_string_literal)
169        	(raw_string_literal)
170        ] @injection.content
171        ))
172
173        ; when passing as a literal element (to struct field eg.)
174		((comment) @comment
175        .
176        (literal_element
177        [
178        	(interpreted_string_literal)
179        	(raw_string_literal)
180        ] @injection.content
181        ))
182
183        ; when passing as a function parameter
184        ((comment) @comment
185        .
186        [
187        	(interpreted_string_literal)
188        	(raw_string_literal)
189        ] @injection.content)
190    ]
191
192    (#match? @comment "^\\/\\*\\s*html\\s*\\*\\/") ; /* html */ or /*html*/
193    (#set! injection.language "html")
194)
195
196; INJECT JS
197(
198	[
199		; var, const or short declaration of raw or interpreted string literal
200		((comment) @comment
201  		.
202    	(expression_list
203     	[
204      		(interpreted_string_literal)
205        	(raw_string_literal)
206        ] @injection.content
207        ))
208
209        ; when passing as a literal element (to struct field eg.)
210		((comment) @comment
211        .
212        (literal_element
213        [
214        	(interpreted_string_literal)
215        	(raw_string_literal)
216        ] @injection.content
217        ))
218
219        ; when passing as a function parameter
220        ((comment) @comment
221        .
222        [
223        	(interpreted_string_literal)
224        	(raw_string_literal)
225        ] @injection.content)
226    ]
227
228    (#match? @comment "^\\/\\*\\s*js\\s*\\*\\/") ; /* js */ or /*js*/
229    (#set! injection.language "javascript")
230)
231
232; INJECT CSS
233(
234	[
235		; var, const or short declaration of raw or interpreted string literal
236		((comment) @comment
237  		.
238    	(expression_list
239     	[
240      		(interpreted_string_literal)
241        	(raw_string_literal)
242        ] @injection.content
243        ))
244
245        ; when passing as a literal element (to struct field eg.)
246		((comment) @comment
247        .
248        (literal_element
249        [
250        	(interpreted_string_literal)
251        	(raw_string_literal)
252        ] @injection.content
253        ))
254
255        ; when passing as a function parameter
256        ((comment) @comment
257        .
258        [
259        	(interpreted_string_literal)
260        	(raw_string_literal)
261        ] @injection.content)
262    ]
263
264    (#match? @comment "^\\/\\*\\s*css\\s*\\*\\/") ; /* css */ or /*css*/
265    (#set! injection.language "css")
266)
267
268; INJECT LUA
269(
270	[
271		; var, const or short declaration of raw or interpreted string literal
272		((comment) @comment
273  		.
274    	(expression_list
275     	[
276      		(interpreted_string_literal)
277        	(raw_string_literal)
278        ] @injection.content
279        ))
280
281        ; when passing as a literal element (to struct field eg.)
282		((comment) @comment
283        .
284        (literal_element
285        [
286        	(interpreted_string_literal)
287        	(raw_string_literal)
288        ] @injection.content
289        ))
290
291        ; when passing as a function parameter
292        ((comment) @comment
293        .
294        [
295        	(interpreted_string_literal)
296        	(raw_string_literal)
297        ] @injection.content)
298    ]
299
300    (#match? @comment "^\\/\\*\\s*lua\\s*\\*\\/") ; /* lua */ or /*lua*/
301    (#set! injection.language "lua")
302)
303
304; INJECT BASH
305(
306	[
307		; var, const or short declaration of raw or interpreted string literal
308		((comment) @comment
309  		.
310    	(expression_list
311     	[
312      		(interpreted_string_literal)
313        	(raw_string_literal)
314        ] @injection.content
315        ))
316
317        ; when passing as a literal element (to struct field eg.)
318		((comment) @comment
319        .
320        (literal_element
321        [
322        	(interpreted_string_literal)
323        	(raw_string_literal)
324        ] @injection.content
325        ))
326
327        ; when passing as a function parameter
328        ((comment) @comment
329        .
330        [
331        	(interpreted_string_literal)
332        	(raw_string_literal)
333        ] @injection.content)
334    ]
335
336    (#match? @comment "^\\/\\*\\s*bash\\s*\\*\\/") ; /* bash */ or /*bash*/
337    (#set! injection.language "bash")
338)
339
340; INJECT CSV
341(
342	[
343		; var, const or short declaration of raw or interpreted string literal
344		((comment) @comment
345  		.
346    	(expression_list
347     	[
348      		(interpreted_string_literal)
349        	(raw_string_literal)
350        ] @injection.content
351        ))
352
353        ; when passing as a literal element (to struct field eg.)
354		((comment) @comment
355        .
356        (literal_element
357        [
358        	(interpreted_string_literal)
359        	(raw_string_literal)
360        ] @injection.content
361        ))
362
363        ; when passing as a function parameter
364        ((comment) @comment
365        .
366        [
367        	(interpreted_string_literal)
368        	(raw_string_literal)
369        ] @injection.content)
370    ]
371
372    (#match? @comment "^\\/\\*\\s*csv\\s*\\*\\/") ; /* csv */ or /*csv*/
373    (#set! injection.language "csv")
374)