Make mbe compile with parser changes

This commit is contained in:
Lukas Wirth 2023-02-03 21:39:24 +01:00
parent 6fa6efe90f
commit 9053bcc65c
3 changed files with 14 additions and 7 deletions

View file

@ -95,6 +95,7 @@ pub fn token_tree_to_syntax_node(
parser::Step::Token { kind, n_input_tokens: n_raw_tokens } => {
tree_sink.token(kind, n_raw_tokens)
}
parser::Step::FloatSplit { .. } => tree_sink.token(SyntaxKind::FLOAT_NUMBER, 1),
parser::Step::Enter { kind } => tree_sink.start_node(kind),
parser::Step::Exit => tree_sink.finish_node(),
parser::Step::Error { msg } => tree_sink.error(msg.to_string()),

View file

@ -140,6 +140,7 @@ impl<'a> TtIter<'a> {
let mut cursor = buffer.begin();
let mut error = false;
let mut float_splits = vec![];
for step in tree_traversal.iter() {
match step {
parser::Step::Token { kind, mut n_input_tokens } => {
@ -150,6 +151,10 @@ impl<'a> TtIter<'a> {
cursor = cursor.bump_subtree();
}
}
parser::Step::FloatSplit { .. } => {
float_splits.push(cursor);
cursor = cursor.bump_subtree();
}
parser::Step::Enter { .. } | parser::Step::Exit => (),
parser::Step::Error { .. } => error = true,
}
@ -167,18 +172,17 @@ impl<'a> TtIter<'a> {
if cursor.is_root() {
while curr != cursor {
if let Some(token) = curr.token_tree() {
res.push(token);
res.push(token.cloned());
}
curr = curr.bump();
}
}
self.inner = self.inner.as_slice()[res.len()..].iter();
let res = match res.len() {
1 => Some(res[0].cloned()),
0 => None,
0 | 1 => res.pop(),
_ => Some(tt::TokenTree::Subtree(tt::Subtree {
delimiter: tt::Delimiter::unspecified(),
token_trees: res.into_iter().map(|it| it.cloned()).collect(),
token_trees: res,
})),
};
ExpandResult { value: res, err }

View file

@ -16,8 +16,8 @@ enum Entry<'t, Span> {
// Mimicking types from proc-macro.
Subtree(Option<&'t TokenTree<Span>>, &'t Subtree<Span>, EntryId),
Leaf(&'t TokenTree<Span>),
// End entries contain a pointer to the entry from the containing
// token tree, or None if this is the outermost level.
/// End entries contain a pointer to the entry from the containing
/// token tree, or [`None`] if this is the outermost level.
End(Option<EntryPtr>),
}
@ -226,7 +226,9 @@ impl<'a, Span> Cursor<'a, Span> {
/// a cursor into that subtree
pub fn bump_subtree(self) -> Cursor<'a, Span> {
match self.entry() {
Some(Entry::Subtree(_, _, _)) => self.subtree().unwrap(),
Some(&Entry::Subtree(_, _, entry_id)) => {
Cursor::create(self.buffer, EntryPtr(entry_id, 0))
}
_ => self.bump(),
}
}