Add handling token seperator in mbe

This commit is contained in:
Edwin Cheng 2019-04-24 23:01:32 +08:00
parent dfab545d5d
commit 299d97b6d9
8 changed files with 219 additions and 226 deletions

View file

@ -342,7 +342,7 @@ impl<'a> TokenSource for SubtreeTokenSource<'a> {
}
}
struct TokenPeek<'a, I>
pub(crate) struct TokenPeek<'a, I>
where
I: Iterator<Item = &'a tt::TokenTree>,
{
@ -365,7 +365,7 @@ where
TokenPeek { iter: itertools::multipeek(iter) }
}
fn current_punct2(&mut self, p: &tt::Punct) -> Option<((char, char), bool)> {
pub fn current_punct2(&mut self, p: &tt::Punct) -> Option<((char, char), bool)> {
if p.spacing != tt::Spacing::Joint {
return None;
}
@ -375,7 +375,7 @@ where
Some(((p.char, p1.char), p1.spacing == tt::Spacing::Joint))
}
fn current_punct3(&mut self, p: &tt::Punct) -> Option<((char, char, char), bool)> {
pub fn current_punct3(&mut self, p: &tt::Punct) -> Option<((char, char, char), bool)> {
self.current_punct2(p).and_then(|((p0, p1), last_joint)| {
if !last_joint {
None
@ -437,12 +437,16 @@ fn convert_delim(d: tt::Delimiter, closing: bool) -> TtToken {
}
fn convert_literal(l: &tt::Literal) -> TtToken {
TtToken {
kind: classify_literal(&l.text).unwrap().kind,
is_joint_to_next: false,
text: l.text.clone(),
n_tokens: 1,
}
let kind = classify_literal(&l.text)
.map(|tkn| tkn.kind)
.or_else(|| match l.text.as_ref() {
"true" => Some(SyntaxKind::TRUE_KW),
"false" => Some(SyntaxKind::FALSE_KW),
_ => None,
})
.unwrap();
TtToken { kind, is_joint_to_next: false, text: l.text.clone(), n_tokens: 1 }
}
fn convert_ident(ident: &tt::Ident) -> TtToken {