aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe/src/expander
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mbe/src/expander')
-rw-r--r--crates/mbe/src/expander/matcher.rs20
-rw-r--r--crates/mbe/src/expander/transcriber.rs8
2 files changed, 14 insertions, 14 deletions
diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs
index c982eb58f..c0e1705c0 100644
--- a/crates/mbe/src/expander/matcher.rs
+++ b/crates/mbe/src/expander/matcher.rs
@@ -121,7 +121,7 @@ impl Match {
121 121
122/// Matching errors are added to the `Match`. 122/// Matching errors are added to the `Match`.
123pub(super) fn match_(pattern: &MetaTemplate, input: &tt::Subtree) -> Match { 123pub(super) fn match_(pattern: &MetaTemplate, input: &tt::Subtree) -> Match {
124 let mut res = match_loop(pattern, &input); 124 let mut res = match_loop(pattern, input);
125 res.bound_count = count(res.bindings.bindings()); 125 res.bound_count = count(res.bindings.bindings());
126 return res; 126 return res;
127 127
@@ -202,7 +202,7 @@ impl BindingsBuilder {
202 } 202 }
203 203
204 fn push_nested(&mut self, parent: &mut BindingsIdx, child: &BindingsIdx) { 204 fn push_nested(&mut self, parent: &mut BindingsIdx, child: &BindingsIdx) {
205 let BindingsIdx(idx, nidx) = self.copy(&child); 205 let BindingsIdx(idx, nidx) = self.copy(child);
206 self.nodes[parent.0].push(LinkNode::Node(Rc::new(BindingKind::Nested(idx, nidx)))); 206 self.nodes[parent.0].push(LinkNode::Node(Rc::new(BindingKind::Nested(idx, nidx))));
207 } 207 }
208 208
@@ -221,7 +221,7 @@ impl BindingsBuilder {
221 221
222 fn build_inner(&self, bindings: &mut Bindings, link_nodes: &[LinkNode<Rc<BindingKind>>]) { 222 fn build_inner(&self, bindings: &mut Bindings, link_nodes: &[LinkNode<Rc<BindingKind>>]) {
223 let mut nodes = Vec::new(); 223 let mut nodes = Vec::new();
224 self.collect_nodes(&link_nodes, &mut nodes); 224 self.collect_nodes(link_nodes, &mut nodes);
225 225
226 for cmd in nodes { 226 for cmd in nodes {
227 match &**cmd { 227 match &**cmd {
@@ -282,7 +282,7 @@ impl BindingsBuilder {
282 282
283 nested_refs.into_iter().for_each(|iter| { 283 nested_refs.into_iter().for_each(|iter| {
284 let mut child_bindings = Bindings::default(); 284 let mut child_bindings = Bindings::default();
285 self.build_inner(&mut child_bindings, &iter); 285 self.build_inner(&mut child_bindings, iter);
286 nested.push(child_bindings) 286 nested.push(child_bindings)
287 }) 287 })
288 } 288 }
@@ -417,7 +417,7 @@ fn match_loop_inner<'t>(
417 let sep_len = item.sep.as_ref().map_or(0, Separator::tt_count); 417 let sep_len = item.sep.as_ref().map_or(0, Separator::tt_count);
418 if item.sep.is_some() && sep_idx != sep_len { 418 if item.sep.is_some() && sep_idx != sep_len {
419 let sep = item.sep.as_ref().unwrap(); 419 let sep = item.sep.as_ref().unwrap();
420 if src.clone().expect_separator(&sep, sep_idx) { 420 if src.clone().expect_separator(sep, sep_idx) {
421 item.dot.next(); 421 item.dot.next();
422 item.sep_parsed = Some(sep_idx + 1); 422 item.sep_parsed = Some(sep_idx + 1);
423 try_push!(next_items, item); 423 try_push!(next_items, item);
@@ -487,7 +487,7 @@ fn match_loop_inner<'t>(
487 item.meta_result = Some((fork, match_res)); 487 item.meta_result = Some((fork, match_res));
488 try_push!(bb_items, item); 488 try_push!(bb_items, item);
489 } else { 489 } else {
490 bindings_builder.push_optional(&mut item.bindings, &name); 490 bindings_builder.push_optional(&mut item.bindings, name);
491 item.dot.next(); 491 item.dot.next();
492 cur_items.push(item); 492 cur_items.push(item);
493 } 493 }
@@ -495,7 +495,7 @@ fn match_loop_inner<'t>(
495 Some(err) => { 495 Some(err) => {
496 res.add_err(err); 496 res.add_err(err);
497 if let Some(fragment) = match_res.value { 497 if let Some(fragment) = match_res.value {
498 bindings_builder.push_fragment(&mut item.bindings, &name, fragment); 498 bindings_builder.push_fragment(&mut item.bindings, name, fragment);
499 } 499 }
500 item.is_error = true; 500 item.is_error = true;
501 error_items.push(item); 501 error_items.push(item);
@@ -504,7 +504,7 @@ fn match_loop_inner<'t>(
504 } 504 }
505 } 505 }
506 OpDelimited::Op(Op::Leaf(leaf)) => { 506 OpDelimited::Op(Op::Leaf(leaf)) => {
507 if let Err(err) = match_leaf(&leaf, &mut src.clone()) { 507 if let Err(err) = match_leaf(leaf, &mut src.clone()) {
508 res.add_err(err); 508 res.add_err(err);
509 item.is_error = true; 509 item.is_error = true;
510 } else { 510 } else {
@@ -640,10 +640,10 @@ fn match_loop(pattern: &MetaTemplate, src: &tt::Subtree) -> Match {
640 let (iter, match_res) = item.meta_result.take().unwrap(); 640 let (iter, match_res) = item.meta_result.take().unwrap();
641 match match_res.value { 641 match match_res.value {
642 Some(fragment) => { 642 Some(fragment) => {
643 bindings_builder.push_fragment(&mut item.bindings, &name, fragment); 643 bindings_builder.push_fragment(&mut item.bindings, name, fragment);
644 } 644 }
645 None if match_res.err.is_none() => { 645 None if match_res.err.is_none() => {
646 bindings_builder.push_optional(&mut item.bindings, &name); 646 bindings_builder.push_optional(&mut item.bindings, name);
647 } 647 }
648 _ => {} 648 _ => {}
649 } 649 }
diff --git a/crates/mbe/src/expander/transcriber.rs b/crates/mbe/src/expander/transcriber.rs
index dd7fa97d7..49a137577 100644
--- a/crates/mbe/src/expander/transcriber.rs
+++ b/crates/mbe/src/expander/transcriber.rs
@@ -55,7 +55,7 @@ pub(super) fn transcribe(
55 template: &MetaTemplate, 55 template: &MetaTemplate,
56 bindings: &Bindings, 56 bindings: &Bindings,
57) -> ExpandResult<tt::Subtree> { 57) -> ExpandResult<tt::Subtree> {
58 let mut ctx = ExpandCtx { bindings: &bindings, nesting: Vec::new() }; 58 let mut ctx = ExpandCtx { bindings, nesting: Vec::new() };
59 let mut arena: Vec<tt::TokenTree> = Vec::new(); 59 let mut arena: Vec<tt::TokenTree> = Vec::new();
60 expand_subtree(&mut ctx, template, None, &mut arena) 60 expand_subtree(&mut ctx, template, None, &mut arena)
61} 61}
@@ -91,12 +91,12 @@ fn expand_subtree(
91 Op::Leaf(tt) => arena.push(tt.clone().into()), 91 Op::Leaf(tt) => arena.push(tt.clone().into()),
92 Op::Subtree { tokens, delimiter } => { 92 Op::Subtree { tokens, delimiter } => {
93 let ExpandResult { value: tt, err: e } = 93 let ExpandResult { value: tt, err: e } =
94 expand_subtree(ctx, &tokens, *delimiter, arena); 94 expand_subtree(ctx, tokens, *delimiter, arena);
95 err = err.or(e); 95 err = err.or(e);
96 arena.push(tt.into()); 96 arena.push(tt.into());
97 } 97 }
98 Op::Var { name, id, .. } => { 98 Op::Var { name, id, .. } => {
99 let ExpandResult { value: fragment, err: e } = expand_var(ctx, &name, *id); 99 let ExpandResult { value: fragment, err: e } = expand_var(ctx, name, *id);
100 err = err.or(e); 100 err = err.or(e);
101 push_fragment(arena, fragment); 101 push_fragment(arena, fragment);
102 } 102 }
@@ -141,7 +141,7 @@ fn expand_var(ctx: &mut ExpandCtx, v: &SmolStr, id: tt::TokenId) -> ExpandResult
141 .into(); 141 .into();
142 ExpandResult::ok(Fragment::Tokens(tt)) 142 ExpandResult::ok(Fragment::Tokens(tt))
143 } else { 143 } else {
144 ctx.bindings.get(&v, &mut ctx.nesting).map_or_else( 144 ctx.bindings.get(v, &mut ctx.nesting).map_or_else(
145 |e| ExpandResult { value: Fragment::Tokens(tt::TokenTree::empty()), err: Some(e) }, 145 |e| ExpandResult { value: Fragment::Tokens(tt::TokenTree::empty()), err: Some(e) },
146 |b| ExpandResult::ok(b.clone()), 146 |b| ExpandResult::ok(b.clone()),
147 ) 147 )