Skip to content

Commit 58897dd

Browse files
committed
assign ids to tokens
1 parent b356ab4 commit 58897dd

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

crates/ra_mbe/src/mbe_expander.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/// `tt::TokenTree` for the result of the expansion.
44
use rustc_hash::FxHashMap;
55
use ra_syntax::SmolStr;
6+
use tt::TokenId;
67

78
use crate::tt_cursor::TtCursor;
89

@@ -185,7 +186,8 @@ fn expand_tt(
185186
}
186187
crate::TokenTree::Leaf(leaf) => match leaf {
187188
crate::Leaf::Ident(ident) => {
188-
tt::Leaf::from(tt::Ident { text: ident.text.clone() }).into()
189+
tt::Leaf::from(tt::Ident { text: ident.text.clone(), id: TokenId::unspecified() })
190+
.into()
189191
}
190192
crate::Leaf::Punct(punct) => tt::Leaf::from(punct.clone()).into(),
191193
crate::Leaf::Var(v) => bindings.get(&v.text, nesting)?.clone(),

crates/ra_mbe/src/mbe_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn parse_subtree(tt: &tt::Subtree) -> Option<crate::Subtree> {
4141
}
4242
}
4343
tt::Leaf::Punct(punct) => crate::Leaf::from(*punct).into(),
44-
tt::Leaf::Ident(tt::Ident { text }) => {
44+
tt::Leaf::Ident(tt::Ident { text, id: _ }) => {
4545
crate::Leaf::from(crate::Ident { text: text.clone() }).into()
4646
}
4747
tt::Leaf::Literal(tt::Literal { text }) => {

crates/ra_mbe/src/syntax_bridge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ fn convert_tt(tt: &SyntaxNode) -> Option<tt::Subtree> {
3737
convert_tt(child)?.into()
3838
} else if child.kind().is_keyword() || child.kind() == IDENT {
3939
let text = child.leaf_text().unwrap().clone();
40-
tt::Leaf::from(tt::Ident { text }).into()
40+
tt::Leaf::from(tt::Ident { text, id: tt::TokenId::unspecified() }).into()
4141
} else if child.kind().is_literal() {
4242
tt::Leaf::from(tt::Literal { text: child.leaf_text().unwrap().clone() }).into()
4343
} else {

crates/ra_tt/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ use std::fmt;
1818

1919
use smol_str::SmolStr;
2020

21+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22+
pub struct TokenId(pub u32);
23+
24+
impl TokenId {
25+
pub const fn unspecified() -> TokenId {
26+
TokenId(!0)
27+
}
28+
}
29+
2130
#[derive(Debug, Clone)]
2231
pub enum TokenTree {
2332
Leaf(Leaf),
@@ -67,6 +76,7 @@ pub enum Spacing {
6776
#[derive(Debug, Clone)]
6877
pub struct Ident {
6978
pub text: SmolStr,
79+
pub id: TokenId,
7080
}
7181

7282
impl fmt::Display for TokenTree {

0 commit comments

Comments
 (0)