macro
Parsing a small token grammar
A small macro can validate exactly one identifier by matching the first token and checking that no second token exists. This parser does not accept paths or expressions. Example: two-crate workspace; see fixtures/proc-macro-workspace/consumer/src/bin/token_parsing.rs. This caller is not a standalone rustc program. Expected stdout (not executed): '14\n' Common mistake: Accepting a valid first token but silently ignoring extra input.
Formal Syntax & Structure
rust syntaxrust
match (tokens.next(), tokens.next())Working Example
Example Snippetrust
use teaching_macros::single_ident;fn main() { let count = 14; println!("{}", single_ident!(count)); }