rslint_syntax/lib.rs
1//! A crate for generated Syntax node definitions and utility macros.
2//! Both rslint_lexer and rslint_parser rely on these definitions, therefore
3//! they are wrapped in this crate to prevent cyclic dependencies
4
5#[macro_use]
6mod generated;
7
8pub use self::generated::SyntaxKind;
9
10impl From<u16> for SyntaxKind {
11 fn from(d: u16) -> SyntaxKind {
12 assert!(d <= (SyntaxKind::__LAST as u16));
13 unsafe { std::mem::transmute::<u16, SyntaxKind>(d) }
14 }
15}
16
17impl From<SyntaxKind> for u16 {
18 fn from(k: SyntaxKind) -> u16 {
19 k as u16
20 }
21}
22
23impl SyntaxKind {
24 pub fn is_trivia(self) -> bool {
25 matches!(self, SyntaxKind::WHITESPACE | SyntaxKind::COMMENT)
26 }
27}