runnables.scm

 1; Rust mod test
 2((attribute_item
 3  (attribute
 4    (identifier) @_attribute
 5    arguments: ((token_tree
 6      (identifier) @_test)
 7      (#eq? @_test "test")))
 8  (#eq? @_attribute "cfg"))
 9  .
10  (mod_item
11    name: (_) @run)
12  (#set! tag rust-mod-test))
13
14; Rust test
15(((attribute_item
16  (attribute
17    [
18      (identifier) @_attribute
19      (scoped_identifier
20        (identifier) @_attribute)
21    ])
22  (#match? @_attribute "test")) @_start
23  .
24  (attribute_item)*
25  .
26  [
27    (line_comment)
28    (block_comment)
29  ]*
30  .
31  (function_item
32    name: (_) @run @_test_name
33    body: _) @_end)
34  (#set! tag rust-test))
35
36; Rust doc test
37(((line_comment)*
38  (line_comment
39    doc: (_) @_comment_content) @_start @run
40  (#match? @_comment_content "```")
41  .
42  (line_comment)*
43  .
44  (line_comment
45    doc: (_) @_end_comment_content) @_end_code_block
46  (#match? @_end_comment_content "```")
47  .
48  (line_comment)*
49  (attribute_item)*
50  .
51  [
52    (function_item
53      name: (_) @_doc_test_name
54      body: _)
55    (function_signature_item
56      name: (_) @_doc_test_name)
57    (struct_item
58      name: (_) @_doc_test_name)
59    (enum_item
60      name: (_) @_doc_test_name
61      body: _)
62    ((attribute_item)?
63      (macro_definition
64        name: (_) @_doc_test_name))
65    (mod_item
66      name: (_) @_doc_test_name)
67  ] @_end)
68  (#set! tag rust-doc-test))
69
70; Rust main function
71(((function_item
72  name: (_) @run
73  body: _) @_rust_main_function_end
74  (#eq? @run "main"))
75  (#set! tag rust-main))