From 98f98cbb5404385703a404547aa2477d4a2fd1cb Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 13 Dec 2019 21:53:34 +0800 Subject: Refactor tt::Delimiter --- crates/ra_mbe/src/mbe_expander/transcriber.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'crates/ra_mbe/src/mbe_expander/transcriber.rs') diff --git a/crates/ra_mbe/src/mbe_expander/transcriber.rs b/crates/ra_mbe/src/mbe_expander/transcriber.rs index ed094d5bb..f7636db11 100644 --- a/crates/ra_mbe/src/mbe_expander/transcriber.rs +++ b/crates/ra_mbe/src/mbe_expander/transcriber.rs @@ -50,7 +50,7 @@ pub(super) fn transcribe( template: &tt::Subtree, bindings: &Bindings, ) -> Result { - assert!(template.delimiter == tt::Delimiter::None); + assert!(template.delimiter == None); let mut ctx = ExpandCtx { bindings: &bindings, nesting: Vec::new(), var_expanded: false }; expand_subtree(&mut ctx, template) } @@ -106,7 +106,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> Result // ``` // We just treat it a normal tokens let tt = tt::Subtree { - delimiter: tt::Delimiter::None, + delimiter: None, token_trees: vec![ tt::Leaf::from(tt::Punct { char: '$', spacing: tt::Spacing::Alone }).into(), tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() }) @@ -147,7 +147,7 @@ fn expand_repeat( ctx.var_expanded = false; while let Ok(mut t) = expand_subtree(ctx, template) { - t.delimiter = tt::Delimiter::None; + t.delimiter = None; // if no var expanded in the child, we count it as a fail if !ctx.var_expanded { break; @@ -212,7 +212,7 @@ fn expand_repeat( // Check if it is a single token subtree without any delimiter // e.g {Delimiter:None> ['>'] /Delimiter:None>} - let tt = tt::Subtree { delimiter: tt::Delimiter::None, token_trees: buf }.into(); + let tt = tt::Subtree { delimiter: None, token_trees: buf }.into(); Ok(Fragment::Tokens(tt)) } @@ -225,7 +225,7 @@ fn push_fragment(buf: &mut Vec, fragment: Fragment) { fn push_subtree(buf: &mut Vec, tt: tt::Subtree) { match tt.delimiter { - tt::Delimiter::None => buf.extend(tt.token_trees), + None => buf.extend(tt.token_trees), _ => buf.push(tt.into()), } } -- cgit v1.2.3 From aceb9d7fb0809ccf364514d9177342edea144c59 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 12 Dec 2019 21:47:54 +0800 Subject: Add token ids for all tt::Leaf --- crates/ra_mbe/src/mbe_expander/transcriber.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'crates/ra_mbe/src/mbe_expander/transcriber.rs') diff --git a/crates/ra_mbe/src/mbe_expander/transcriber.rs b/crates/ra_mbe/src/mbe_expander/transcriber.rs index f7636db11..eda66cd50 100644 --- a/crates/ra_mbe/src/mbe_expander/transcriber.rs +++ b/crates/ra_mbe/src/mbe_expander/transcriber.rs @@ -108,7 +108,12 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> Result let tt = tt::Subtree { delimiter: None, token_trees: vec![ - tt::Leaf::from(tt::Punct { char: '$', spacing: tt::Spacing::Alone }).into(), + tt::Leaf::from(tt::Punct { + char: '$', + spacing: tt::Spacing::Alone, + id: tt::TokenId::unspecified(), + }) + .into(), tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() }) .into(), ], -- cgit v1.2.3