浏览代码

Make try_parse macro's implementation simpler

Isaac Woods 6 年之前
父节点
当前提交
b7bfefe627
共有 1 个文件被更改,包括 5 次插入8 次删除
  1. 5 8
      src/aml/parser.rs

+ 5 - 8
src/aml/parser.rs

@@ -29,17 +29,14 @@ where
 /// the stream with each one. If a parsing function fails, it rolls back the stream and tries the
 /// next one. If none of the functions can parse the next part of the stream, we error on the
 /// unexpected byte.
-// TODO: rewrite to not use try_parse, and just `match` the errors manually. Might be much cleaner
 macro_rules! try_parse {
-    ($parser: expr, $($function: path),+) => {
-        if false {
-            unreachable!();
-        } $(else if let Some(value) = $parser.try_parse($function)? {
-                Ok(value)
-        })+ else {
+    ($parser: expr, $($function: path),+) => {{
+        $(if let Some(value) = $parser.try_parse($function)? {
+            Ok(value)
+        } else)+ {
             Err(AmlError::UnexpectedByte($parser.stream.peek()?))
         }
-    }
+    }}
 }
 
 impl<'s, 'a, 'h, H> AmlParser<'s, 'a, 'h, H>