aboutsummaryrefslogtreecommitdiff
path: root/code/src/syntax_highlight/grammar.rs
blob: ba703e7c3e3b120e0c96da1922739cde0a744351 (plain)
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
pub fn grammar_for(syntax: &str) -> &'static [(&'static [&'static str], &'static str)] {
    match syntax {
        "rs" => &[
            (
                &[
                    "fn", "pub", "async", "return", "if", "else", "let", "for", "while", "loop",
                    "impl", "for", "trait", "struct", "enum",
                ],
                "keyword",
            ),
            (
                &[
                    "[A-Z][a-z]*",
                    "bool",
                    "usize",
                    "u8",
                    "u16",
                    "u32",
                    "u64",
                    "u128",
                    "i8",
                    "i16",
                    "i32",
                    "i64",
                    "i128",
                    "isize",
                    "f32",
                    "f64",
                ],
                "type",
            ),
            (&["(?m)(//.*)$"], "comment"),
            (&["([a-z_][A-Za-z0-9_]*!)\\s*"], "macro"),
            (&["([a-z_][A-Za-z0-9_]*)\\s*\\("], "identifier"),
            (&["\".*?\"", "\\d", "true", "false"], "literal"),
        ],
        _ => &[],
    }
}