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

1

5

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?

Yockey answered 16/7, 2018 at 18:8 Comment(0)
C
6

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!.

Childress answered 16/7, 2018 at 18:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.