git.delta.rocks / jrsonnet / refs/commits / dacee201fa00

difftreelog

source

crates/jrsonnet-rowan-parser/src/token_set.rs899 Bsourcehistory
1use crate::SyntaxKind;23#[derive(Clone, Copy, Default)]4pub struct SyntaxKindSet(u128);56impl SyntaxKindSet {7	#[allow(dead_code)]8	pub const EMPTY: Self = Self(0);9	pub const ALL: Self = Self(u128::MAX);1011	pub const fn new(kinds: &[SyntaxKind]) -> SyntaxKindSet {12		let mut res = 0u128;13		let mut i = 0;14		while i < kinds.len() {15			res |= mask(kinds[i]);16			i += 117		}18		SyntaxKindSet(res)19	}2021	pub const fn union(self, other: SyntaxKindSet) -> SyntaxKindSet {22		SyntaxKindSet(self.0 | other.0)23	}2425	pub const fn contains(&self, kind: SyntaxKind) -> bool {26		self.0 & mask(kind) != 027	}28}2930const fn mask(kind: SyntaxKind) -> u128 {31	1u128 << (kind as u128)32}3334#[macro_export]35macro_rules! TS {36	($($tt:tt)*) => {37		$crate::SyntaxKindSet::new(&[38			$(39				$crate::T![$tt]40			),*41		])42	};43}4445#[test]46fn sanity() {47	assert!(48		(SyntaxKind::ERROR as u32) < 127,49		"can't keep KindSet as bitset"50	);51}