diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-09-06 15:05:37 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-09-06 15:05:37 +0100 |
commit | ba7b3c2108c13c20d3e279ff5f0bb4cc9522e08a (patch) | |
tree | ac9a756c5cfc83fed671f57e20a2f05d8b00e539 /crates/libsyntax2/src/parser_api.rs | |
parent | 751562d2f77a7bc3eeeffbf8e53c9f3515fa9653 (diff) | |
parent | 518cc87496494d639f0a6bf189f1a3567bcfa328 (diff) |
Merge #59
59: Moved TokenSet into it's own file. r=matklad a=Plasticcaz
As discussed in Issue #11, the only thing left in that issue that hasn't been fixed appears to be that TokenSet is not in it's own file. This pull request pulls TokenSet, it's macros and it's test into it's own file.
Co-authored-by: Zac Winter <[email protected]>
Diffstat (limited to 'crates/libsyntax2/src/parser_api.rs')
-rw-r--r-- | crates/libsyntax2/src/parser_api.rs | 37 |
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 @@ | |||
1 | use { | 1 | use { |
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)] | ||
8 | pub(crate) struct TokenSet(pub(crate) u128); | ||
9 | |||
10 | fn mask(kind: SyntaxKind) -> u128 { | ||
11 | 1u128 << (kind as usize) | ||
12 | } | ||
13 | |||
14 | impl 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] | ||
23 | macro_rules! token_set { | ||
24 | ($($t:ident),*) => { TokenSet($(1u128 << ($t as usize))|*) }; | ||
25 | ($($t:ident),* ,) => { token_set!($($t),*) }; | ||
26 | } | ||
27 | |||
28 | #[macro_export] | ||
29 | macro_rules! token_set_union { | ||
30 | ($($ts:expr),*) => { TokenSet($($ts.0)|*) }; | ||
31 | ($($ts:expr),* ,) => { token_set_union!($($ts),*) }; | ||
32 | } | ||
33 | |||
34 | #[test] | ||
35 | fn 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 |