diff options
Diffstat (limited to 'crates/ra_parser')
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs | 18 | ||||
-rw-r--r-- | crates/ra_parser/src/syntax_kind/generated.rs.tera | 18 |
2 files changed, 36 insertions, 0 deletions
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index b16177de2..498b0e164 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs | |||
@@ -7,6 +7,7 @@ use super::SyntaxInfo; | |||
7 | 7 | ||
8 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. | 8 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. |
9 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 9 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
10 | #[repr(u16)] | ||
10 | pub enum SyntaxKind { | 11 | pub enum SyntaxKind { |
11 | // Technical SyntaxKinds: they appear temporally during parsing, | 12 | // Technical SyntaxKinds: they appear temporally during parsing, |
12 | // but never end up in the final tree | 13 | // but never end up in the final tree |
@@ -232,9 +233,25 @@ pub enum SyntaxKind { | |||
232 | ARG_LIST, | 233 | ARG_LIST, |
233 | TYPE_BOUND, | 234 | TYPE_BOUND, |
234 | TYPE_BOUND_LIST, | 235 | TYPE_BOUND_LIST, |
236 | // Technical kind so that we can cast from u16 safely | ||
237 | #[doc(hidden)] | ||
238 | __LAST, | ||
235 | } | 239 | } |
236 | use self::SyntaxKind::*; | 240 | use self::SyntaxKind::*; |
237 | 241 | ||
242 | impl From<u16> for SyntaxKind { | ||
243 | fn from(d: u16) -> SyntaxKind { | ||
244 | assert!(d <= (__LAST as u16)); | ||
245 | unsafe { std::mem::transmute::<u16, SyntaxKind>(d) } | ||
246 | } | ||
247 | } | ||
248 | |||
249 | impl From<SyntaxKind> for u16 { | ||
250 | fn from(k: SyntaxKind) -> u16 { | ||
251 | k as u16 | ||
252 | } | ||
253 | } | ||
254 | |||
238 | impl SyntaxKind { | 255 | impl SyntaxKind { |
239 | pub fn is_keyword(self) -> bool { | 256 | pub fn is_keyword(self) -> bool { |
240 | match self { | 257 | match self { |
@@ -577,6 +594,7 @@ impl SyntaxKind { | |||
577 | TYPE_BOUND_LIST => &SyntaxInfo { name: "TYPE_BOUND_LIST" }, | 594 | TYPE_BOUND_LIST => &SyntaxInfo { name: "TYPE_BOUND_LIST" }, |
578 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, | 595 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, |
579 | EOF => &SyntaxInfo { name: "EOF" }, | 596 | EOF => &SyntaxInfo { name: "EOF" }, |
597 | __LAST => &SyntaxInfo { name: "__LAST" }, | ||
580 | } | 598 | } |
581 | } | 599 | } |
582 | pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { | 600 | pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { |
diff --git a/crates/ra_parser/src/syntax_kind/generated.rs.tera b/crates/ra_parser/src/syntax_kind/generated.rs.tera index f241a21a0..5b9ff21af 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs.tera +++ b/crates/ra_parser/src/syntax_kind/generated.rs.tera | |||
@@ -9,6 +9,7 @@ use super::SyntaxInfo; | |||
9 | 9 | ||
10 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. | 10 | /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. |
11 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] | 11 | #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | #[repr(u16)] | ||
12 | pub enum SyntaxKind { | 13 | pub enum SyntaxKind { |
13 | // Technical SyntaxKinds: they appear temporally during parsing, | 14 | // Technical SyntaxKinds: they appear temporally during parsing, |
14 | // but never end up in the final tree | 15 | // but never end up in the final tree |
@@ -26,9 +27,25 @@ pub enum SyntaxKind { | |||
26 | {% for t in concat(a=literals, b=tokens, c=nodes) %} | 27 | {% for t in concat(a=literals, b=tokens, c=nodes) %} |
27 | {{t}}, | 28 | {{t}}, |
28 | {%- endfor %} | 29 | {%- endfor %} |
30 | // Technical kind so that we can cast from u16 safely | ||
31 | #[doc(hidden)] | ||
32 | __LAST, | ||
29 | } | 33 | } |
30 | use self::SyntaxKind::*; | 34 | use self::SyntaxKind::*; |
31 | 35 | ||
36 | impl From<u16> for SyntaxKind { | ||
37 | fn from(d: u16) -> SyntaxKind { | ||
38 | assert!(d <= (__LAST as u16)); | ||
39 | unsafe { std::mem::transmute::<u16, SyntaxKind>(d) } | ||
40 | } | ||
41 | } | ||
42 | |||
43 | impl From<SyntaxKind> for u16 { | ||
44 | fn from(k: SyntaxKind) -> u16 { | ||
45 | k as u16 | ||
46 | } | ||
47 | } | ||
48 | |||
32 | impl SyntaxKind { | 49 | impl SyntaxKind { |
33 | pub fn is_keyword(self) -> bool { | 50 | pub fn is_keyword(self) -> bool { |
34 | match self { | 51 | match self { |
@@ -72,6 +89,7 @@ impl SyntaxKind { | |||
72 | {%- endfor %} | 89 | {%- endfor %} |
73 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, | 90 | TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, |
74 | EOF => &SyntaxInfo { name: "EOF" }, | 91 | EOF => &SyntaxInfo { name: "EOF" }, |
92 | __LAST => &SyntaxInfo { name: "__LAST" }, | ||
75 | } | 93 | } |
76 | } | 94 | } |
77 | pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { | 95 | pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { |