aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_parser/src/syntax_kind.rs
blob: 3efcfa4030306e1ffdf3b0d1f70b887d9b628068 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#[macro_use]
mod generated;

pub use self::generated::SyntaxKind;

impl From<u16> for SyntaxKind {
    fn from(d: u16) -> SyntaxKind {
        assert!(d <= (SyntaxKind::__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_trivia(self) -> bool {
        match self {
            SyntaxKind::WHITESPACE | SyntaxKind::COMMENT => true,
            _ => false,
        }
    }
}