From d334b5a1db9ec6a57f54077d422a3f4b3c8c1178 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 Feb 2019 13:27:45 +0300 Subject: move parser to a separate crate --- crates/ra_parser/src/syntax_kind/generated.rs.tera | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 crates/ra_parser/src/syntax_kind/generated.rs.tera (limited to 'crates/ra_parser/src/syntax_kind/generated.rs.tera') diff --git a/crates/ra_parser/src/syntax_kind/generated.rs.tera b/crates/ra_parser/src/syntax_kind/generated.rs.tera new file mode 100644 index 000000000..837437136 --- /dev/null +++ b/crates/ra_parser/src/syntax_kind/generated.rs.tera @@ -0,0 +1,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(crate) fn from_keyword(ident: &str) -> Option { + let kw = match ident { +{%- for kw in keywords %} + "{{kw}}" => {{kw | upper}}_KW, +{%- endfor %} + _ => return None, + }; + Some(kw) + } + + pub(crate) fn from_char(c: char) -> Option { + let tok = match c { +{%- for t in single_byte_tokens %} + '{{t.0}}' => {{t.1}}, +{%- endfor %} + _ => return None, + }; + Some(tok) + } +} -- cgit v1.2.3