use derive(Debug) for SyntaxKind

This commit is contained in:
Aleksey Kladov
2019-08-19 13:11:51 +03:00
parent 53241928e5
commit 00ccc6c292
3 changed files with 10 additions and 284 deletions

View File

@@ -195,10 +195,8 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
let ast = quote! {
#![allow(bad_style, missing_docs, unreachable_pub)]
use super::SyntaxInfo;
/// The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT_DEF`.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[repr(u16)]
pub enum SyntaxKind {
// Technical SyntaxKinds: they appear temporally during parsing,
@@ -219,19 +217,6 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
}
use self::SyntaxKind::*;
impl From<u16> for SyntaxKind {
fn from(d: u16) -> SyntaxKind {
assert!(d <= (__LAST as u16));
unsafe { std::mem::transmute::<u16, SyntaxKind>(d) }
}
}
impl From<SyntaxKind> for u16 {
fn from(k: SyntaxKind) -> u16 {
k as u16
}
}
impl SyntaxKind {
pub fn is_keyword(self) -> bool {
match self {
@@ -254,19 +239,6 @@ fn generate_syntax_kinds(grammar: &Grammar) -> Result<String> {
}
}
pub(crate) fn info(self) -> &'static SyntaxInfo {
match self {
#(#punctuation => &SyntaxInfo { name: stringify!(#punctuation) },)*
#(#all_keywords => &SyntaxInfo { name: stringify!(#all_keywords) },)*
#(#literals => &SyntaxInfo { name: stringify!(#literals) },)*
#(#tokens => &SyntaxInfo { name: stringify!(#tokens) },)*
#(#nodes => &SyntaxInfo { name: stringify!(#nodes) },)*
TOMBSTONE => &SyntaxInfo { name: "TOMBSTONE" },
EOF => &SyntaxInfo { name: "EOF" },
__LAST => &SyntaxInfo { name: "__LAST" },
}
}
pub fn from_keyword(ident: &str) -> Option<SyntaxKind> {
let kw = match ident {
#(#full_keywords_values => #full_keywords,)*