浏览代码

Tidy up context reuse in choice! macro

Rather than mutating the parameter we pass the context in with, we simply
create a new binding for each parser. I think this is a bit neater.
Isaac Woods 4 年之前
父节点
当前提交
b4231f7608
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      aml/src/parser.rs

+ 4 - 4
aml/src/parser.rs

@@ -452,13 +452,13 @@ pub(crate) macro choice {
      * type-check (and so reduces the cost of pulling us in as a dependency as well as improving ergonomics).
      */
     ($($parser: expr),+) => {
-        move |input, mut context| {
+        move |input, context| {
             $(
-                match ($parser).parse(input, context) {
+                let context = match ($parser).parse(input, context) {
                     Ok(parse_result) => return Ok(parse_result),
-                    Err((_, new_context, Propagate::Err(AmlError::WrongParser))) => { context = new_context; },
+                    Err((_, new_context, Propagate::Err(AmlError::WrongParser))) => new_context,
                     Err((_, context, propagate)) => return Err((input, context, propagate)),
-                }
+                };
              )+
             Err((input, context, Propagate::Err(AmlError::WrongParser)))
         }