From 37e1625f0139da07c2690b6ee6ca7eae5ebb061a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 1 Aug 2018 11:27:31 +0300 Subject: return expr --- src/parser_api.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/parser_api.rs') diff --git a/src/parser_api.rs b/src/parser_api.rs index 5a0da32c9..d12f773b2 100644 --- a/src/parser_api.rs +++ b/src/parser_api.rs @@ -3,22 +3,22 @@ use { SyntaxKind::{self, ERROR}, }; -pub(crate) struct TokenSet { - pub tokens: &'static [SyntaxKind], +#[derive(Clone, Copy)] +pub(crate) struct TokenSet(pub(crate) u128); +fn mask(kind: SyntaxKind) -> u128 { + 1u128 << (kind as usize) } impl TokenSet { pub fn contains(&self, kind: SyntaxKind) -> bool { - self.tokens.contains(&kind) + self.0 & mask(kind) != 0 } } #[macro_export] macro_rules! token_set { ($($t:ident),*) => { - TokenSet { - tokens: &[$($t),*], - } + TokenSet($(1u128 << ($t as usize))|*) }; ($($t:ident),* ,) => { @@ -26,6 +26,17 @@ macro_rules! token_set { }; } +#[macro_export] +macro_rules! token_set_union { + ($($ts:expr),*) => { + TokenSet($($ts.0)|*) + }; + + ($($ts:expr),* ,) => { + token_set_union!($($ts),*) + }; +} + /// `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