]> git.lizzy.rs Git - rust.git/commitdiff
assign ids to tokens
authorAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 11 Feb 2019 16:28:39 +0000 (19:28 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Mon, 11 Feb 2019 18:02:19 +0000 (21:02 +0300)
crates/ra_mbe/src/mbe_expander.rs
crates/ra_mbe/src/mbe_parser.rs
crates/ra_mbe/src/syntax_bridge.rs
crates/ra_tt/src/lib.rs

index eec713d9c1424a8202a6adc0ed808f2d875abd0c..f6177f078194a355f770a08e0c92aa3f2cd6c069 100644 (file)
@@ -3,6 +3,7 @@
 /// `tt::TokenTree` for the result of the expansion.
 use rustc_hash::FxHashMap;
 use ra_syntax::SmolStr;
+use tt::TokenId;
 
 use crate::tt_cursor::TtCursor;
 
@@ -185,7 +186,8 @@ fn expand_tt(
         }
         crate::TokenTree::Leaf(leaf) => match leaf {
             crate::Leaf::Ident(ident) => {
-                tt::Leaf::from(tt::Ident { text: ident.text.clone() }).into()
+                tt::Leaf::from(tt::Ident { text: ident.text.clone(), id: TokenId::unspecified() })
+                    .into()
             }
             crate::Leaf::Punct(punct) => tt::Leaf::from(punct.clone()).into(),
             crate::Leaf::Var(v) => bindings.get(&v.text, nesting)?.clone(),
index 60e566ed2370708675892ef0afc26cdbcb6f65f1..58e2533f18b6e37d9abf2418890a029dafdd5463 100644 (file)
@@ -41,7 +41,7 @@ fn parse_subtree(tt: &tt::Subtree) -> Option<crate::Subtree> {
                     }
                 }
                 tt::Leaf::Punct(punct) => crate::Leaf::from(*punct).into(),
-                tt::Leaf::Ident(tt::Ident { text }) => {
+                tt::Leaf::Ident(tt::Ident { text, id: _ }) => {
                     crate::Leaf::from(crate::Ident { text: text.clone() }).into()
                 }
                 tt::Leaf::Literal(tt::Literal { text }) => {
index 9a2eceabac7abea8b2da22961c48d3d8e037d625..d734f55976ab7ab4e6042c9496c120357d9499b9 100644 (file)
@@ -37,7 +37,7 @@ fn convert_tt(tt: &SyntaxNode) -> Option<tt::Subtree> {
                 convert_tt(child)?.into()
             } else if child.kind().is_keyword() || child.kind() == IDENT {
                 let text = child.leaf_text().unwrap().clone();
-                tt::Leaf::from(tt::Ident { text }).into()
+                tt::Leaf::from(tt::Ident { text, id: tt::TokenId::unspecified() }).into()
             } else if child.kind().is_literal() {
                 tt::Leaf::from(tt::Literal { text: child.leaf_text().unwrap().clone() }).into()
             } else {
index df31f72f39d2bd4c3cef51d2a315378a0f0291c0..e0a4cdb8b0407a474338fd56ca667a2a7f2132be 100644 (file)
@@ -18,6 +18,15 @@ fn from(it: $v) -> $e {
 
 use smol_str::SmolStr;
 
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
+pub struct TokenId(pub u32);
+
+impl TokenId {
+    pub const fn unspecified() -> TokenId {
+        TokenId(!0)
+    }
+}
+
 #[derive(Debug, Clone)]
 pub enum TokenTree {
     Leaf(Leaf),
@@ -67,6 +76,7 @@ pub enum Spacing {
 #[derive(Debug, Clone)]
 pub struct Ident {
     pub text: SmolStr,
+    pub id: TokenId,
 }
 
 impl fmt::Display for TokenTree {