aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/syntax_kind/generated.rs.tera
blob: f241a21a0eb86cc6118b84be85c701282adef37d (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
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
87
88
89
90
91
92
93
94
95
96
{# THIS File is not automatically generated:
the below applies to the result of this template
#}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run
// Do not edit manually

#![allow(bad_style, missing_docs, unreachable_pub)]
#![cfg_attr(rustfmt, rustfmt_skip)]
use super::SyntaxInfo;

/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum SyntaxKind {
    // Technical SyntaxKinds: they appear temporally during parsing,
    // but never end up in the final tree
    #[doc(hidden)]
    TOMBSTONE,
    #[doc(hidden)]
    EOF,

{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
    {{t.1}},
{%- endfor -%}
{% for kw in concat(a=keywords, b=contextual_keywords) %}
    {{kw | upper}}_KW,
{%- endfor -%}
{% for t in concat(a=literals, b=tokens, c=nodes) %}
    {{t}},
{%- endfor %}
}
use self::SyntaxKind::*;

impl SyntaxKind {
    pub fn is_keyword(self) -> bool {
        match self {
{%- for kw in concat(a=keywords, b=contextual_keywords) %}
            | {{kw | upper}}_KW
{%- endfor %}
                => true,
            _ => false
        }
    }

    pub fn is_punct(self) -> bool {
        match self {
{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
            | {{t.1}}
{%- endfor %}
                => true,
            _ => false
        }
    }
    pub fn is_literal(self) -> bool {
        match self {
{%- for t in literals %}
            | {{t}}
{%- endfor %}
                => true,
            _ => false
        }
    }

    pub(crate) fn info(self) -> &'static SyntaxInfo {
        match self {
{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
            {{t.1}} => &SyntaxInfo { name: "{{t.1}}" },
{%- endfor -%}
{% for kw in concat(a=keywords, b=contextual_keywords) %}
            {{kw | upper}}_KW => &SyntaxInfo { name: "{{kw | upper}}_KW" },
{%- endfor -%}
{% for t in concat(a=literals, b=tokens, c=nodes) %}
            {{t}} => &SyntaxInfo { name: "{{t}}" },
{%- endfor %}
            TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" },
            EOF => &SyntaxInfo { name: "EOF" },
        }
    }
    pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
        let kw = match ident {
{%- for kw in keywords %}
            "{{kw}}" => {{kw | upper}}_KW,
{%- endfor %}
            _ => return None,
        };
        Some(kw)
    }

    pub fn from_char(c: char) -> Option<SyntaxKind> {
        let tok = match c {
{%- for t in single_byte_tokens %}
            '{{t.0}}' => {{t.1}},
{%- endfor %}
            _ => return None,
        };
        Some(tok)
    }
}