rust/src/syntax_kinds/generated.rs.tera

76 lines
2.2 KiB
Plaintext
Raw Normal View History

2018-07-30 06:06:22 -05:00
#![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 {
2018-07-30 10:02:13 -05:00
{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
2018-07-30 09:46:50 -05:00
{{t.1}},
{%- endfor -%}
2018-07-30 10:02:13 -05:00
{% for kw in concat(a=keywords, b=contextual_keywords) %}
2018-07-30 06:06:22 -05:00
{{kw | upper}}_KW,
{%- endfor -%}
2018-07-30 10:02:13 -05:00
{% for t in concat(a=tokens, b=nodes) %}
{{t}},
2018-07-30 06:06:22 -05:00
{%- endfor %}
// Technical SyntaxKinds: they appear temporally during parsing,
// but never end up in the final tree
#[doc(hidden)]
TOMBSTONE,
#[doc(hidden)]
EOF,
}
use self::SyntaxKind::*;
impl SyntaxKind {
pub(crate) fn info(self) -> &'static SyntaxInfo {
match self {
2018-07-30 10:02:13 -05:00
{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
2018-07-30 09:46:50 -05:00
{{t.1}} => &SyntaxInfo { name: "{{t.1}}" },
{%- endfor -%}
2018-07-30 10:02:13 -05:00
{% for kw in concat(a=keywords, b=contextual_keywords) %}
2018-07-30 06:06:22 -05:00
{{kw | upper}}_KW => &SyntaxInfo { name: "{{kw | upper}}_KW" },
{%- endfor -%}
2018-07-30 10:02:13 -05:00
{% for t in concat(a=tokens, b=nodes) %}
{{t}} => &SyntaxInfo { name: "{{t}}" },
2018-07-30 06:06:22 -05:00
{%- endfor %}
TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" },
EOF => &SyntaxInfo { name: "EOF" },
}
}
pub(crate) fn from_keyword(ident: &str) -> Option<SyntaxKind> {
let kw = match ident {
{%- for kw in keywords %}
"{{kw}}" => {{kw | upper}}_KW,
{%- endfor %}
_ => return None,
};
Some(kw)
}
2018-07-30 09:46:50 -05:00
pub(crate) fn from_char(c: char) -> Option<SyntaxKind> {
let tok = match c {
{%- for t in single_byte_tokens %}
'{{t.0}}' => {{t.1}},
2018-07-30 10:11:33 -05:00
{%- endfor %}
_ => return None,
};
Some(tok)
}
pub(crate) fn static_text(self) -> Option<&'static str> {
let tok = match self {
{%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %}
{{t.1}} => "{{t.0}}",
{%- endfor %}
{% for kw in concat(a=keywords, b=contextual_keywords) %}
{{kw | upper}}_KW => "{{kw}}",
2018-07-30 09:46:50 -05:00
{%- endfor %}
_ => return None,
};
Some(tok)
}
2018-07-30 06:06:22 -05:00
}