diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-13 14:02:26 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-13 14:02:26 +0000 |
commit | ebc95af2b5b91239fc1d8a5fc8344ded6f6ef3e4 (patch) | |
tree | fe84a7b9a434cb268faea247d9d6dbffed894696 /crates/ra_mbe/src/mbe_expander/transcriber.rs | |
parent | 16cf6bcf4b614a7a1a3a3f3659f7bb3df7cff086 (diff) | |
parent | 98f98cbb5404385703a404547aa2477d4a2fd1cb (diff) |
Merge #2551
2551: Refactor tt::Subtree delimiter r=matklad a=edwin0cheng
Refactor to :
```
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct Subtree {
pub delimiter: Option<Delimiter>,
pub token_trees: Vec<TokenTree>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Delimiter {
Parenthesis,
Brace,
Bracket,
}
```
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src/mbe_expander/transcriber.rs')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/transcriber.rs | 10 |
1 files changed, 5 insertions, 5 deletions
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( | |||
50 | template: &tt::Subtree, | 50 | template: &tt::Subtree, |
51 | bindings: &Bindings, | 51 | bindings: &Bindings, |
52 | ) -> Result<tt::Subtree, ExpandError> { | 52 | ) -> Result<tt::Subtree, ExpandError> { |
53 | assert!(template.delimiter == tt::Delimiter::None); | 53 | assert!(template.delimiter == None); |
54 | let mut ctx = ExpandCtx { bindings: &bindings, nesting: Vec::new(), var_expanded: false }; | 54 | let mut ctx = ExpandCtx { bindings: &bindings, nesting: Vec::new(), var_expanded: false }; |
55 | expand_subtree(&mut ctx, template) | 55 | expand_subtree(&mut ctx, template) |
56 | } | 56 | } |
@@ -106,7 +106,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr) -> Result<Fragment, ExpandError> | |||
106 | // ``` | 106 | // ``` |
107 | // We just treat it a normal tokens | 107 | // We just treat it a normal tokens |
108 | let tt = tt::Subtree { | 108 | let tt = tt::Subtree { |
109 | delimiter: tt::Delimiter::None, | 109 | delimiter: None, |
110 | token_trees: vec![ | 110 | token_trees: vec![ |
111 | tt::Leaf::from(tt::Punct { char: '$', spacing: tt::Spacing::Alone }).into(), | 111 | tt::Leaf::from(tt::Punct { char: '$', spacing: tt::Spacing::Alone }).into(), |
112 | tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() }) | 112 | tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() }) |
@@ -147,7 +147,7 @@ fn expand_repeat( | |||
147 | ctx.var_expanded = false; | 147 | ctx.var_expanded = false; |
148 | 148 | ||
149 | while let Ok(mut t) = expand_subtree(ctx, template) { | 149 | while let Ok(mut t) = expand_subtree(ctx, template) { |
150 | t.delimiter = tt::Delimiter::None; | 150 | t.delimiter = None; |
151 | // if no var expanded in the child, we count it as a fail | 151 | // if no var expanded in the child, we count it as a fail |
152 | if !ctx.var_expanded { | 152 | if !ctx.var_expanded { |
153 | break; | 153 | break; |
@@ -212,7 +212,7 @@ fn expand_repeat( | |||
212 | 212 | ||
213 | // Check if it is a single token subtree without any delimiter | 213 | // Check if it is a single token subtree without any delimiter |
214 | // e.g {Delimiter:None> ['>'] /Delimiter:None>} | 214 | // e.g {Delimiter:None> ['>'] /Delimiter:None>} |
215 | let tt = tt::Subtree { delimiter: tt::Delimiter::None, token_trees: buf }.into(); | 215 | let tt = tt::Subtree { delimiter: None, token_trees: buf }.into(); |
216 | Ok(Fragment::Tokens(tt)) | 216 | Ok(Fragment::Tokens(tt)) |
217 | } | 217 | } |
218 | 218 | ||
@@ -225,7 +225,7 @@ fn push_fragment(buf: &mut Vec<tt::TokenTree>, fragment: Fragment) { | |||
225 | 225 | ||
226 | fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) { | 226 | fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) { |
227 | match tt.delimiter { | 227 | match tt.delimiter { |
228 | tt::Delimiter::None => buf.extend(tt.token_trees), | 228 | None => buf.extend(tt.token_trees), |
229 | _ => buf.push(tt.into()), | 229 | _ => buf.push(tt.into()), |
230 | } | 230 | } |
231 | } | 231 | } |