From 518cc87496494d639f0a6bf189f1a3567bcfa328 Mon Sep 17 00:00:00 2001 From: Zac Winter Date: Thu, 6 Sep 2018 21:54:54 +0800 Subject: Moved TokenSet into it's own file. --- crates/libsyntax2/src/parser_api.rs | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'crates/libsyntax2/src/parser_api.rs') diff --git a/crates/libsyntax2/src/parser_api.rs b/crates/libsyntax2/src/parser_api.rs index 9bc58e7f7..c4753140e 100644 --- a/crates/libsyntax2/src/parser_api.rs +++ b/crates/libsyntax2/src/parser_api.rs @@ -1,45 +1,10 @@ use { + token_set::TokenSet, parser_impl::ParserImpl, SyntaxKind::{self, ERROR}, drop_bomb::DropBomb, }; -#[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)); -} - /// `Parser` struct provides the low-level API for /// navigating through the stream of tokens and /// constructing the parse tree. The actual parsing -- cgit v1.2.3