我试图使用nom解析一个字符串,该字符串要么将被换行符终止,要么将在使用后到达输入端。我有下面的代码,看起来应该编译:
named!(am_implied <AddressingMode>,
do_parse!(
opt!(space) >>
alt!(
line_ending |
eof!()
) >>
(AddressingMode::Implied)
)
);这在以下消息中失败:
error[E0282]: unable to infer enough type information about `E`
--> src/lib.rs:181:1
|
181 | named!(am_implied <AddressingMode>,
| ^ cannot infer type for `E`
|
= note: type annotations or generic parameter binding required我认为上面的代码应该编译,因为下面的代码编译:
named!(am_implied <AddressingMode>,
do_parse!(
opt!(space) >>
line_ending >>
eof!() >>
(AddressingMode::Implied)
)
);当line_ending和eof!解析器不是在alt!解析器中使用,而当它们在alt!解析器中使用时,为什么会发生这种情况呢?我想知道在line_ending或eof!上匹配的正确解决方案。
https://stackoverflow.com/questions/41658386
复制相似问题