Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where does nom's "$i" macro argument come from?

Tags:

macros

rust

nom

I'm trying to understand how Rust macro captures work and am looking at the nom parser library.

Location nom/src/bytes.rs declares macro tag! which captures with ($i:expr, $tag: expr). However throughout the places where tag! is used it is used with only one argument, i.e. tag!("+"). Example: nom-lua52/op.rs. I've read tutorials about macros however this construct seems to be special.

It seems like the input $i is somehow implicit?

like image 926
Konrad Eisele Avatar asked Jul 16 '18 18:07

Konrad Eisele


1 Answers

The trick is that the tag!() macro call is inside the value! macro, which will match against tag! and pass it an additional parameter. This is described in the file implementing tag!.

like image 62
starblue Avatar answered Oct 24 '22 04:10

starblue