return expr

This commit is contained in:
Aleksey Kladov
2018-08-01 11:27:31 +03:00
parent 53485030dc
commit 37e1625f01
8 changed files with 100 additions and 18 deletions

View File

@@ -3,22 +3,22 @@ use {
SyntaxKind::{self, ERROR},
};
pub(crate) struct TokenSet {
pub tokens: &'static [SyntaxKind],
#[derive(Clone, Copy)]
pub(crate) struct TokenSet(pub(crate) u128);
fn mask(kind: SyntaxKind) -> u128 {
1u128 << (kind as usize)
}
impl TokenSet {
pub fn contains(&self, kind: SyntaxKind) -> bool {
self.tokens.contains(&kind)
self.0 & mask(kind) != 0
}
}
#[macro_export]
macro_rules! token_set {
($($t:ident),*) => {
TokenSet {
tokens: &[$($t),*],
}
TokenSet($(1u128 << ($t as usize))|*)
};
($($t:ident),* ,) => {
@@ -26,6 +26,17 @@ macro_rules! token_set {
};
}
#[macro_export]
macro_rules! token_set_union {
($($ts:expr),*) => {
TokenSet($($ts.0)|*)
};
($($ts:expr),* ,) => {
token_set_union!($($ts),*)
};
}
/// `Parser` struct provides the low-level API for
/// navigating through the stream of tokens and
/// constructing the parse tree. The actual parsing