diff options
author | Aleksey Kladov <[email protected]> | 2019-08-19 09:02:18 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-08-19 09:42:39 +0100 |
commit | 832b40a075285063b857bf05a69a8cf979d9078a (patch) | |
tree | bca6983bfd05c9539aa9cb2ce94b7fa6aeecebc7 /crates/ra_parser/src/syntax_kind/generated.rs.tera | |
parent | 7d29cf12256921d63860402a2e7cd2936c22e01e (diff) |
use new quote-generated syntax kinds
Diffstat (limited to 'crates/ra_parser/src/syntax_kind/generated.rs.tera')
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs.tera | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs.tera b/crates/ra_parser/src/syntax_kind/generated.rs.tera deleted file mode 100644 index f5abbec4b..000000000 --- a/crates/ra_parser/src/syntax_kind/generated.rs.tera +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | {# THIS File is not automatically generated: | ||
2 | the below applies to the result of this template | ||
3 | #}// This file is automatically generated based on the file `./generated.rs.tera` when `cargo gen-syntax` is run | ||
4 | // Do not edit manually | ||
5 | |||
6 | #![allow(bad_style, missing_docs, unreachable_pub)] | ||
7 | #![cfg_attr(rustfmt, rustfmt_skip)] | ||
8 | use super::SyntaxInfo; | ||
9 | |||
10 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. | ||
11 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
12 | #[repr(u16)] | ||
13 | pub enum SyntaxKind { | ||
14 | // Technical SyntaxKinds: they appear temporally during parsing, | ||
15 | // but never end up in the final tree | ||
16 | #[doc(hidden)] | ||
17 | TOMBSTONE, | ||
18 | #[doc(hidden)] | ||
19 | EOF, | ||
20 | |||
21 | {%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} | ||
22 | {{t.1}}, | ||
23 | {%- endfor -%} | ||
24 | {% for kw in concat(a=keywords, b=contextual_keywords) %} | ||
25 | {{kw | upper}}_KW, | ||
26 | {%- endfor -%} | ||
27 | {% for t in concat(a=literals, b=tokens, c=nodes) %} | ||
28 | {{t}}, | ||
29 | {%- endfor %} | ||
30 | // Technical kind so that we can cast from u16 safely | ||
31 | #[doc(hidden)] | ||
32 | __LAST, | ||
33 | } | ||
34 | use self::SyntaxKind::*; | ||
35 | |||
36 | #[macro_export] | ||
37 | macro_rules! T { | ||
38 | {%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} | ||
39 | {%- if t.0 == '{' or t.0 == '}' or t.0 == '[' or t.0 == ']' or t.0 == '(' or t.0 == ')' %} | ||
40 | ('{{t.0}}') => { $crate::SyntaxKind::{{t.1}} }; | ||
41 | {%- else %} | ||
42 | ({{t.0}}) => { $crate::SyntaxKind::{{t.1}} }; | ||
43 | {%- endif %} | ||
44 | {%- endfor -%} | ||
45 | {% for kw in concat(a=keywords, b=contextual_keywords) %} | ||
46 | ({{kw}}) => { $crate::SyntaxKind::{{kw | upper}}_KW }; | ||
47 | {%- endfor %} | ||
48 | } | ||
49 | |||
50 | impl From<u16> for SyntaxKind { | ||
51 | fn from(d: u16) -> SyntaxKind { | ||
52 | assert!(d <= (__LAST as u16)); | ||
53 | unsafe { std::mem::transmute::<u16, SyntaxKind>(d) } | ||
54 | } | ||
55 | } | ||
56 | |||
57 | impl From<SyntaxKind> for u16 { | ||
58 | fn from(k: SyntaxKind) -> u16 { | ||
59 | k as u16 | ||
60 | } | ||
61 | } | ||
62 | |||
63 | impl SyntaxKind { | ||
64 | pub fn is_keyword(self) -> bool { | ||
65 | match self { | ||
66 | {%- for kw in concat(a=keywords, b=contextual_keywords) %} | ||
67 | | {{kw | upper}}_KW | ||
68 | {%- endfor %} | ||
69 | => true, | ||
70 | _ => false | ||
71 | } | ||
72 | } | ||
73 | |||
74 | pub fn is_punct(self) -> bool { | ||
75 | match self { | ||
76 | {%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} | ||
77 | | {{t.1}} | ||
78 | {%- endfor %} | ||
79 | => true, | ||
80 | _ => false | ||
81 | } | ||
82 | } | ||
83 | pub fn is_literal(self) -> bool { | ||
84 | match self { | ||
85 | {%- for t in literals %} | ||
86 | | {{t}} | ||
87 | {%- endfor %} | ||
88 | => true, | ||
89 | _ => false | ||
90 | } | ||
91 | } | ||
92 | |||
93 | pub(crate) fn info(self) -> &'static SyntaxInfo { | ||
94 | match self { | ||
95 | {%- for t in concat(a=single_byte_tokens, b=multi_byte_tokens) %} | ||
96 | {{t.1}} => &SyntaxInfo { name: "{{t.1}}" }, | ||
97 | {%- endfor -%} | ||
98 | {% for kw in concat(a=keywords, b=contextual_keywords) %} | ||
99 | {{kw | upper}}_KW => &SyntaxInfo { name: "{{kw | upper}}_KW" }, | ||
100 | {%- endfor -%} | ||
101 | {% for t in concat(a=literals, b=tokens, c=nodes) %} | ||
102 | {{t}} => &SyntaxInfo { name: "{{t}}" }, | ||
103 | {%- endfor %} | ||
104 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, | ||
105 | EOF => &SyntaxInfo { name: "EOF" }, | ||
106 | __LAST => &SyntaxInfo { name: "__LAST" }, | ||
107 | } | ||
108 | } | ||
109 | pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { | ||
110 | let kw = match ident { | ||
111 | {%- for kw in keywords %} | ||
112 | "{{kw}}" => {{kw | upper}}_KW, | ||
113 | {%- endfor %} | ||
114 | _ => return None, | ||
115 | }; | ||
116 | Some(kw) | ||
117 | } | ||
118 | |||
119 | pub fn from_char(c: char) -> Option<SyntaxKind> { | ||
120 | let tok = match c { | ||
121 | {%- for t in single_byte_tokens %} | ||
122 | '{{t.0}}' => {{t.1}}, | ||
123 | {%- endfor %} | ||
124 | _ => return None, | ||
125 | }; | ||
126 | Some(tok) | ||
127 | } | ||
128 | } | ||