aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/parser_api.rs
diff options
context:
space:
mode:
authorZac Winter <[email protected]>2018-09-06 14:54:54 +0100
committerZac Winter <[email protected]>2018-09-06 14:57:04 +0100
commit518cc87496494d639f0a6bf189f1a3567bcfa328 (patch)
treeac9a756c5cfc83fed671f57e20a2f05d8b00e539 /crates/libsyntax2/src/parser_api.rs
parent751562d2f77a7bc3eeeffbf8e53c9f3515fa9653 (diff)
Moved TokenSet into it's own file.
Diffstat (limited to 'crates/libsyntax2/src/parser_api.rs')
-rw-r--r--crates/libsyntax2/src/parser_api.rs37
1 files changed, 1 insertions, 36 deletions
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 @@
1use { 1use {
2 token_set::TokenSet,
2 parser_impl::ParserImpl, 3 parser_impl::ParserImpl,
3 SyntaxKind::{self, ERROR}, 4 SyntaxKind::{self, ERROR},
4 drop_bomb::DropBomb, 5 drop_bomb::DropBomb,
5}; 6};
6 7
7#[derive(Clone, Copy)]
8pub(crate) struct TokenSet(pub(crate) u128);
9
10fn mask(kind: SyntaxKind) -> u128 {
11 1u128 << (kind as usize)
12}
13
14impl TokenSet {
15 pub const EMPTY: TokenSet = TokenSet(0);
16
17 pub fn contains(&self, kind: SyntaxKind) -> bool {
18 self.0 & mask(kind) != 0
19 }
20}
21
22#[macro_export]
23macro_rules! token_set {
24 ($($t:ident),*) => { TokenSet($(1u128 << ($t as usize))|*) };
25 ($($t:ident),* ,) => { token_set!($($t),*) };
26}
27
28#[macro_export]
29macro_rules! token_set_union {
30 ($($ts:expr),*) => { TokenSet($($ts.0)|*) };
31 ($($ts:expr),* ,) => { token_set_union!($($ts),*) };
32}
33
34#[test]
35fn token_set_works_for_tokens() {
36 use SyntaxKind::*;
37 let ts = token_set! { EOF, SHEBANG };
38 assert!(ts.contains(EOF));
39 assert!(ts.contains(SHEBANG));
40 assert!(!ts.contains(PLUS));
41}
42
43/// `Parser` struct provides the low-level API for 8/// `Parser` struct provides the low-level API for
44/// navigating through the stream of tokens and 9/// navigating through the stream of tokens and
45/// constructing the parse tree. The actual parsing 10/// constructing the parse tree. The actual parsing