rust/crates/parser/src/syntax_kind.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

30 lines
653 B
Rust
Raw Normal View History

2021-05-22 17:20:22 +03:00
//! Defines [`SyntaxKind`] -- a fieldless enum of all possible syntactic
//! constructs of the Rust language.
2018-07-29 15:16:07 +03:00
mod generated;
2021-09-06 18:42:07 +03:00
#[allow(unreachable_pub)]
pub use self::generated::{SyntaxKind, T};
2018-07-29 15:16:07 +03:00
2019-08-19 13:11:51 +03:00
impl From<u16> for SyntaxKind {
2021-01-17 16:50:03 +03:00
#[inline]
2019-08-19 13:11:51 +03:00
fn from(d: u16) -> SyntaxKind {
assert!(d <= (SyntaxKind::__LAST as u16));
unsafe { std::mem::transmute::<u16, SyntaxKind>(d) }
2018-07-29 15:16:07 +03:00
}
}
2019-08-19 13:11:51 +03:00
impl From<SyntaxKind> for u16 {
2021-01-17 16:50:03 +03:00
#[inline]
2019-08-19 13:11:51 +03:00
fn from(k: SyntaxKind) -> u16 {
k as u16
}
2018-07-29 15:16:07 +03:00
}
impl SyntaxKind {
2021-01-17 16:50:03 +03:00
#[inline]
2018-08-12 18:50:16 +03:00
pub fn is_trivia(self) -> bool {
2020-06-28 04:02:03 +03:00
matches!(self, SyntaxKind::WHITESPACE | SyntaxKind::COMMENT)
2018-07-29 15:16:07 +03:00
}
}