浏览代码

Rewrite choice error emitter to use new id parser

Isaac Woods 5 年之前
父节点
当前提交
4621a096e3
共有 1 个文件被更改,包括 3 次插入12 次删除
  1. 3 12
      aml_parser/src/parser.rs

+ 3 - 12
aml_parser/src/parser.rs

@@ -402,25 +402,16 @@ where
     }
 }
 
-/// This is a helper parser used in the `choice` macro to emit `AmlError::WrongParser`
-/// unconditionally. It should not be used directly.
-pub(crate) fn no_parsers_could_parse<'a, 'c, R>() -> impl Parser<'a, 'c, R>
-where
-    'c: 'a,
-{
-    |input: &'a [u8], context| Err((input, context, AmlError::WrongParser))
-}
-
 /// Takes a number of parsers, and tries to apply each one to the input in order. Returns the
 /// result of the first one that succeeds, or fails if all of them fail.
 pub(crate) macro choice {
     () => {
-        no_parsers_could_parse()
+        id().map(|()| Err(AmlError::WrongParser))
     },
 
     ($first_parser: expr) => {
         $first_parser
-        .or(no_parsers_could_parse())
+        .or(id().map(|()| Err(AmlError::WrongParser)))
     },
 
     ($first_parser: expr, $($other_parser: expr),*) => {
@@ -428,7 +419,7 @@ pub(crate) macro choice {
         $(
             .or($other_parser)
          )*
-        .or(no_parsers_could_parse())
+        .or(id().map(|()| Err(AmlError::WrongParser)))
     }
 }