1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use tree_sitter::{Language, Query};
static CHECK_SANITY: &str = r#"
(blk
  header:(_)@header
)
(name)@name
(string)@string
"#;

static EXTRACT_SYNTAX_HIGHLIGHTING_SRC: &str = r#"
[
 "namespace"
 "as"
 "constraint"
 "true"
 "false"
 "cardinality"
 ]@keyword
(comment) @comment

(lang_lvl) @macro

(string) @string

(int) @number

(number) @number

[
    (group_mode)
    (constraints)
    (include)
    (features)
    (imports)
] @keyword

[
    "|"
    "&"
    "=>"
    "<=>"
    ">"
    "<"
    "=="
    "+"
    "*"
    "-"
    "/"
    "!"
    ".."
] @operator

(function op:(_) @function)

(attribute_value name:(_)@enumMember)

(ref alias:(_)@parameter)

(blk
    header: [(name)] @parameter)

(typed_feature type:(_) @class name:(_) @parameter)
(path)@parameter
"#;

pub struct Queries {
    pub highlight: Query,
    pub check_sanity: Query,
}
impl Queries {
    pub fn new(lang: &Language) -> Queries {
        Queries {
            highlight: Query::new(*lang, EXTRACT_SYNTAX_HIGHLIGHTING_SRC).unwrap(),
            check_sanity: Query::new(*lang, CHECK_SANITY).unwrap(),
        }
    }
}
/*
pub fn node_source(source: &Rope) -> impl tree_sitter::TextProvider<'_> {
    |node: tree_sitter::Node| {
        source
            .byte_slice(node.byte_range())
            .chunks()
            .map(|i: &str| i.as_bytes())
    }
}*/