1 //! A bit-set of `SyntaxKind`s.
5 /// A bit-set of `SyntaxKind`s
7 pub(crate) struct TokenSet(u128);
10 pub(crate) const EMPTY: TokenSet = TokenSet(0);
12 pub(crate) const fn singleton(kind: SyntaxKind) -> TokenSet {
16 pub(crate) const fn union(self, other: TokenSet) -> TokenSet {
17 TokenSet(self.0 | other.0)
20 pub(crate) fn contains(&self, kind: SyntaxKind) -> bool {
21 self.0 & mask(kind) != 0
25 const fn mask(kind: SyntaxKind) -> u128 {
26 1u128 << (kind as usize)
30 macro_rules! token_set {
31 ($($t:expr),*) => { TokenSet::EMPTY$(.union(TokenSet::singleton($t)))* };
32 ($($t:expr),* ,) => { token_set!($($t),*) };
36 fn token_set_works_for_tokens() {
37 use crate::SyntaxKind::*;
38 let ts = token_set![EOF, SHEBANG];
39 assert!(ts.contains(EOF));
40 assert!(ts.contains(SHEBANG));
41 assert!(!ts.contains(PLUS));