diff options
Diffstat (limited to 'src/parser_api.rs')
-rw-r--r-- | src/parser_api.rs | 23 |
1 files changed, 17 insertions, 6 deletions
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 { | |||
3 | SyntaxKind::{self, ERROR}, | 3 | SyntaxKind::{self, ERROR}, |
4 | }; | 4 | }; |
5 | 5 | ||
6 | pub(crate) struct TokenSet { | 6 | #[derive(Clone, Copy)] |
7 | pub tokens: &'static [SyntaxKind], | 7 | pub(crate) struct TokenSet(pub(crate) u128); |
8 | fn mask(kind: SyntaxKind) -> u128 { | ||
9 | 1u128 << (kind as usize) | ||
8 | } | 10 | } |
9 | 11 | ||
10 | impl TokenSet { | 12 | impl TokenSet { |
11 | pub fn contains(&self, kind: SyntaxKind) -> bool { | 13 | pub fn contains(&self, kind: SyntaxKind) -> bool { |
12 | self.tokens.contains(&kind) | 14 | self.0 & mask(kind) != 0 |
13 | } | 15 | } |
14 | } | 16 | } |
15 | 17 | ||
16 | #[macro_export] | 18 | #[macro_export] |
17 | macro_rules! token_set { | 19 | macro_rules! token_set { |
18 | ($($t:ident),*) => { | 20 | ($($t:ident),*) => { |
19 | TokenSet { | 21 | TokenSet($(1u128 << ($t as usize))|*) |
20 | tokens: &[$($t),*], | ||
21 | } | ||
22 | }; | 22 | }; |
23 | 23 | ||
24 | ($($t:ident),* ,) => { | 24 | ($($t:ident),* ,) => { |
@@ -26,6 +26,17 @@ macro_rules! token_set { | |||
26 | }; | 26 | }; |
27 | } | 27 | } |
28 | 28 | ||
29 | #[macro_export] | ||
30 | macro_rules! token_set_union { | ||
31 | ($($ts:expr),*) => { | ||
32 | TokenSet($($ts.0)|*) | ||
33 | }; | ||
34 | |||
35 | ($($ts:expr),* ,) => { | ||
36 | token_set_union!($($ts),*) | ||
37 | }; | ||
38 | } | ||
39 | |||
29 | /// `Parser` struct provides the low-level API for | 40 | /// `Parser` struct provides the low-level API for |
30 | /// navigating through the stream of tokens and | 41 | /// navigating through the stream of tokens and |
31 | /// constructing the parse tree. The actual parsing | 42 | /// constructing the parse tree. The actual parsing |