aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/syntax_kind
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-08 23:06:30 +0100
committerAleksey Kladov <[email protected]>2019-04-09 08:26:51 +0100
commitfaf526e021e09770cae28f8d7c8ee88a54d6574d (patch)
tree9fb5bbab15472c7d5b870a65c0ec34256b13c428 /crates/ra_parser/src/syntax_kind
parentac6ab0758731d0555fbf1b1a918abd3e12c8169d (diff)
migrate to untyped rowan
Diffstat (limited to 'crates/ra_parser/src/syntax_kind')
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs18
-rw-r--r--crates/ra_parser/src/syntax_kind/generated.rs.tera18
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 547af1b27..b8350266f 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)]
10pub enum SyntaxKind { 11pub 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
@@ -230,9 +231,25 @@ pub enum SyntaxKind {
230 ARG_LIST, 231 ARG_LIST,
231 TYPE_BOUND, 232 TYPE_BOUND,
232 TYPE_BOUND_LIST, 233 TYPE_BOUND_LIST,
234 // Technical kind so that we can cast from u16 safely
235 #[doc(hidden)]
236 __LAST,
233} 237}
234use self::SyntaxKind::*; 238use self::SyntaxKind::*;
235 239
240impl From<u16> for SyntaxKind {
241 fn from(d: u16) -> SyntaxKind {
242 assert!(d <= (__LAST as u16));
243 unsafe { std::mem::transmute::<u16, SyntaxKind>(d) }
244 }
245}
246
247impl From<SyntaxKind> for u16 {
248 fn from(k: SyntaxKind) -> u16 {
249 k as u16
250 }
251}
252
236impl SyntaxKind { 253impl SyntaxKind {
237 pub fn is_keyword(self) -> bool { 254 pub fn is_keyword(self) -> bool {
238 match self { 255 match self {
@@ -573,6 +590,7 @@ impl SyntaxKind {
573 TYPE_BOUND_LIST => &SyntaxInfo { name: "TYPE_BOUND_LIST" }, 590 TYPE_BOUND_LIST => &SyntaxInfo { name: "TYPE_BOUND_LIST" },
574 TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, 591 TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" },
575 EOF => &SyntaxInfo { name: "EOF" }, 592 EOF => &SyntaxInfo { name: "EOF" },
593 __LAST => &SyntaxInfo { name: "__LAST" },
576 } 594 }
577 } 595 }
578 pub fn from_keyword(ident: &str) -> Option<SyntaxKind> { 596 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)]
12pub enum SyntaxKind { 13pub 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}
30use self::SyntaxKind::*; 34use self::SyntaxKind::*;
31 35
36impl 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
43impl From<SyntaxKind> for u16 {
44 fn from(k: SyntaxKind) -> u16 {
45 k as u16
46 }
47}
48
32impl SyntaxKind { 49impl 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> {