How to provide useful compiler errors in a procedural macro?

I am developing my own HTML parser using proc_macro and syn . 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 }) )); } 

Although I know how to throw errors using Span after it has been parsed, I cannot figure out how to do this during parsing. These are just errors with failed to parse anything . How to determine where the parsing is and give the corresponding error?

+7
rust
source share

No one has answered this question yet.

See related questions:

3
How to evaluate expressions in the Rust macro system?
3
How to change the following from_str macro to from_json?
2
How to define a function with different calling conventions depending on the architecture using a macro?
2
How do I grant access to AtomicBool between threads?
2
Is it possible to save state in Rust procedural macros?
one
Unable to call functional procedural macro: cannot be expanded to statements
0
Is it possible to have one drawer with procedural macros and logic?
0
How to write your own derived macro?
0
Macro error when trying to implement a tag inside a macro extension
0
How do you get the impl block type in a Rust procedural macro?

All Articles