mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
rename all things
This commit is contained in:
parent
ba0bfeee12
commit
b5021411a8
478 changed files with 219 additions and 204 deletions
37
crates/ra_syntax/src/token_set.rs
Normal file
37
crates/ra_syntax/src/token_set.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use SyntaxKind;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct TokenSet(pub(crate) u128);
|
||||
|
||||
fn mask(kind: SyntaxKind) -> u128 {
|
||||
1u128 << (kind as usize)
|
||||
}
|
||||
|
||||
impl TokenSet {
|
||||
pub const EMPTY: TokenSet = TokenSet(0);
|
||||
|
||||
pub fn contains(&self, kind: SyntaxKind) -> bool {
|
||||
self.0 & mask(kind) != 0
|
||||
}
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! token_set {
|
||||
($($t:ident),*) => { TokenSet($(1u128 << ($t as usize))|*) };
|
||||
($($t:ident),* ,) => { token_set!($($t),*) };
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! token_set_union {
|
||||
($($ts:expr),*) => { TokenSet($($ts.0)|*) };
|
||||
($($ts:expr),* ,) => { token_set_union!($($ts),*) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn token_set_works_for_tokens() {
|
||||
use SyntaxKind::*;
|
||||
let ts = token_set! { EOF, SHEBANG };
|
||||
assert!(ts.contains(EOF));
|
||||
assert!(ts.contains(SHEBANG));
|
||||
assert!(!ts.contains(PLUS));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue