From faf526e021e09770cae28f8d7c8ee88a54d6574d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 9 Apr 2019 01:06:30 +0300 Subject: migrate to untyped rowan --- crates/ra_parser/src/syntax_kind/generated.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'crates/ra_parser/src/syntax_kind/generated.rs') 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; /// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`. #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr(u16)] pub enum SyntaxKind { // Technical SyntaxKinds: they appear temporally during parsing, // but never end up in the final tree @@ -230,9 +231,25 @@ pub enum SyntaxKind { ARG_LIST, TYPE_BOUND, TYPE_BOUND_LIST, + // Technical kind so that we can cast from u16 safely + #[doc(hidden)] + __LAST, } use self::SyntaxKind::*; +impl From for SyntaxKind { + fn from(d: u16) -> SyntaxKind { + assert!(d <= (__LAST as u16)); + unsafe { std::mem::transmute::(d) } + } +} + +impl From for u16 { + fn from(k: SyntaxKind) -> u16 { + k as u16 + } +} + impl SyntaxKind { pub fn is_keyword(self) -> bool { match self { @@ -573,6 +590,7 @@ impl SyntaxKind { TYPE_BOUND_LIST => &SyntaxInfo { name: "TYPE_BOUND_LIST" }, TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" }, EOF => &SyntaxInfo { name: "EOF" }, + __LAST => &SyntaxInfo { name: "__LAST" }, } } pub fn from_keyword(ident: &str) -> Option { -- cgit v1.2.3