diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 10:46:17 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-21 10:46:17 +0000 |
commit | d77b5857c2420666e84dcd433f254e000e2843aa (patch) | |
tree | 416e333019e349bf4ee369f2548d9e6f6a9c67e9 /crates/ra_syntax/src/parsing/token_set.rs | |
parent | 18b0c509f77a8e06141fee6668532cced1ebf5d8 (diff) | |
parent | 46179230a05331b1debd4dfa3bb197fa38d92347 (diff) |
Merge #867
867: This moves the parser to separate crate r=matklad a=matklad
That makes parser independent form both the token and the tree representation.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_syntax/src/parsing/token_set.rs')
-rw-r--r-- | crates/ra_syntax/src/parsing/token_set.rs | 41 |
1 files changed, 0 insertions, 41 deletions
diff --git a/crates/ra_syntax/src/parsing/token_set.rs b/crates/ra_syntax/src/parsing/token_set.rs deleted file mode 100644 index 24152a38a..000000000 --- a/crates/ra_syntax/src/parsing/token_set.rs +++ /dev/null | |||
@@ -1,41 +0,0 @@ | |||
1 | use crate::SyntaxKind; | ||
2 | |||
3 | #[derive(Clone, Copy)] | ||
4 | pub(crate) struct TokenSet(u128); | ||
5 | |||
6 | impl TokenSet { | ||
7 | pub(crate) const fn empty() -> TokenSet { | ||
8 | TokenSet(0) | ||
9 | } | ||
10 | |||
11 | pub(crate) const fn singleton(kind: SyntaxKind) -> TokenSet { | ||
12 | TokenSet(mask(kind)) | ||
13 | } | ||
14 | |||
15 | pub(crate) const fn union(self, other: TokenSet) -> TokenSet { | ||
16 | TokenSet(self.0 | other.0) | ||
17 | } | ||
18 | |||
19 | pub(crate) fn contains(&self, kind: SyntaxKind) -> bool { | ||
20 | self.0 & mask(kind) != 0 | ||
21 | } | ||
22 | } | ||
23 | |||
24 | const fn mask(kind: SyntaxKind) -> u128 { | ||
25 | 1u128 << (kind as usize) | ||
26 | } | ||
27 | |||
28 | #[macro_export] | ||
29 | macro_rules! token_set { | ||
30 | ($($t:ident),*) => { TokenSet::empty()$(.union(TokenSet::singleton($t)))* }; | ||
31 | ($($t:ident),* ,) => { token_set!($($t),*) }; | ||
32 | } | ||
33 | |||
34 | #[test] | ||
35 | fn token_set_works_for_tokens() { | ||
36 | use crate::SyntaxKind::*; | ||
37 | let ts = token_set![EOF, SHEBANG]; | ||
38 | assert!(ts.contains(EOF)); | ||
39 | assert!(ts.contains(SHEBANG)); | ||
40 | assert!(!ts.contains(PLUS)); | ||
41 | } | ||