diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /crates/ra_mbe/src/mbe_expander | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_mbe/src/mbe_expander')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/matcher.rs | 8 | ||||
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/transcriber.rs | 17 |
2 files changed, 15 insertions, 10 deletions
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index 33b9d483d..e36b5a412 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs | |||
@@ -16,7 +16,7 @@ impl Bindings { | |||
16 | fn push_optional(&mut self, name: &SmolStr) { | 16 | fn push_optional(&mut self, name: &SmolStr) { |
17 | // FIXME: Do we have a better way to represent an empty token ? | 17 | // FIXME: Do we have a better way to represent an empty token ? |
18 | // Insert an empty subtree for empty token | 18 | // Insert an empty subtree for empty token |
19 | let tt = tt::Subtree { delimiter: tt::Delimiter::None, token_trees: vec![] }.into(); | 19 | let tt = tt::Subtree::default().into(); |
20 | self.inner.insert(name.clone(), Binding::Fragment(Fragment::Tokens(tt))); | 20 | self.inner.insert(name.clone(), Binding::Fragment(Fragment::Tokens(tt))); |
21 | } | 21 | } |
22 | 22 | ||
@@ -65,7 +65,7 @@ macro_rules! bail { | |||
65 | } | 65 | } |
66 | 66 | ||
67 | pub(super) fn match_(pattern: &tt::Subtree, src: &tt::Subtree) -> Result<Bindings, ExpandError> { | 67 | pub(super) fn match_(pattern: &tt::Subtree, src: &tt::Subtree) -> Result<Bindings, ExpandError> { |
68 | assert!(pattern.delimiter == tt::Delimiter::None); | 68 | assert!(pattern.delimiter == None); |
69 | 69 | ||
70 | let mut res = Bindings::default(); | 70 | let mut res = Bindings::default(); |
71 | let mut src = TtIter::new(src); | 71 | let mut src = TtIter::new(src); |
@@ -106,7 +106,7 @@ fn match_subtree( | |||
106 | } | 106 | } |
107 | Op::TokenTree(tt::TokenTree::Subtree(lhs)) => { | 107 | Op::TokenTree(tt::TokenTree::Subtree(lhs)) => { |
108 | let rhs = src.expect_subtree().map_err(|()| err!("expected subtree"))?; | 108 | let rhs = src.expect_subtree().map_err(|()| err!("expected subtree"))?; |
109 | if lhs.delimiter != rhs.delimiter { | 109 | if lhs.delimiter_kind() != rhs.delimiter_kind() { |
110 | bail!("mismatched delimiter") | 110 | bail!("mismatched delimiter") |
111 | } | 111 | } |
112 | let mut src = TtIter::new(rhs); | 112 | let mut src = TtIter::new(rhs); |
@@ -210,7 +210,7 @@ impl<'a> TtIter<'a> { | |||
210 | 0 => Err(()), | 210 | 0 => Err(()), |
211 | 1 => Ok(res[0].clone()), | 211 | 1 => Ok(res[0].clone()), |
212 | _ => Ok(tt::TokenTree::Subtree(tt::Subtree { | 212 | _ => Ok(tt::TokenTree::Subtree(tt::Subtree { |
213 | delimiter: tt::Delimiter::None, | 213 | delimiter: None, |
214 | token_trees: res.into_iter().cloned().collect(), | 214 | token_trees: res.into_iter().cloned().collect(), |
215 | })), | 215 | })), |
216 | } | 216 | } |
diff --git a/crates/ra_mbe/src/mbe_expander/transcriber.rs b/crates/ra_mbe/src/mbe_expander/transcriber.rs index ed094d5bb..eda66cd50 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,9 +106,14 @@ 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 { |
112 | char: '$', | ||
113 | spacing: tt::Spacing::Alone, | ||
114 | id: tt::TokenId::unspecified(), | ||
115 | }) | ||
116 | .into(), | ||
112 | tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() }) | 117 | tt::Leaf::from(tt::Ident { text: v.clone(), id: tt::TokenId::unspecified() }) |
113 | .into(), | 118 | .into(), |
114 | ], | 119 | ], |
@@ -147,7 +152,7 @@ fn expand_repeat( | |||
147 | ctx.var_expanded = false; | 152 | ctx.var_expanded = false; |
148 | 153 | ||
149 | while let Ok(mut t) = expand_subtree(ctx, template) { | 154 | while let Ok(mut t) = expand_subtree(ctx, template) { |
150 | t.delimiter = tt::Delimiter::None; | 155 | t.delimiter = None; |
151 | // if no var expanded in the child, we count it as a fail | 156 | // if no var expanded in the child, we count it as a fail |
152 | if !ctx.var_expanded { | 157 | if !ctx.var_expanded { |
153 | break; | 158 | break; |
@@ -212,7 +217,7 @@ fn expand_repeat( | |||
212 | 217 | ||
213 | // Check if it is a single token subtree without any delimiter | 218 | // Check if it is a single token subtree without any delimiter |
214 | // e.g {Delimiter:None> ['>'] /Delimiter:None>} | 219 | // e.g {Delimiter:None> ['>'] /Delimiter:None>} |
215 | let tt = tt::Subtree { delimiter: tt::Delimiter::None, token_trees: buf }.into(); | 220 | let tt = tt::Subtree { delimiter: None, token_trees: buf }.into(); |
216 | Ok(Fragment::Tokens(tt)) | 221 | Ok(Fragment::Tokens(tt)) |
217 | } | 222 | } |
218 | 223 | ||
@@ -225,7 +230,7 @@ fn push_fragment(buf: &mut Vec<tt::TokenTree>, fragment: Fragment) { | |||
225 | 230 | ||
226 | fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) { | 231 | fn push_subtree(buf: &mut Vec<tt::TokenTree>, tt: tt::Subtree) { |
227 | match tt.delimiter { | 232 | match tt.delimiter { |
228 | tt::Delimiter::None => buf.extend(tt.token_trees), | 233 | None => buf.extend(tt.token_trees), |
229 | _ => buf.push(tt.into()), | 234 | _ => buf.push(tt.into()), |
230 | } | 235 | } |
231 | } | 236 | } |