aboutsummaryrefslogtreecommitdiff
path: root/src/parser_api.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-01 09:27:31 +0100
committerAleksey Kladov <[email protected]>2018-08-01 09:27:31 +0100
commit37e1625f0139da07c2690b6ee6ca7eae5ebb061a (patch)
tree368d3329e120fc5d76a0595110f7519bb084d70f /src/parser_api.rs
parent53485030dc49aa7cd66e36c8a1e1abf1bf08020c (diff)
return expr
Diffstat (limited to 'src/parser_api.rs')
-rw-r--r--src/parser_api.rs23
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
6pub(crate) struct TokenSet { 6#[derive(Clone, Copy)]
7 pub tokens: &'static [SyntaxKind], 7pub(crate) struct TokenSet(pub(crate) u128);
8fn mask(kind: SyntaxKind) -> u128 {
9 1u128 << (kind as usize)
8} 10}
9 11
10impl TokenSet { 12impl 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]
17macro_rules! token_set { 19macro_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]
30macro_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