runnables.scm

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