I am designing a custom HTML syntax parser using proc_macro
and syn
. A sample:
#[derive(Debug)]
struct BlockElement {
stag: Ident,
child: Vec<Element>,
ctag: Ident
}
impl Synom for BlockElement {
named!(parse -> Self, do_parse!(
punct!(<) >>
stag: syn!(Ident) >>
punct!(>) >>
child: syn!(ElementList) >>
punct!(<) >>
punct!(/) >>
ctag: syn!(Ident) >>
punct!(>) >>
(BlockElement { stag, child: child.inner, ctag })
));
}
Though I know how give out errors using Span
after it has been parsed, I am not able to figure how to do it during a parse. It just errors out with failed to parse anything
. How to pin-point where parsing failed and give appropriate error?