I'm looking at the nom
crate for rust, which contains lots of functions to parse bytes/characters.
Many of the functions, such as tag()
, seen below, process input that's provided not as a parameter to the function, but that appears instead in a second set of parentheses, following what I would call the parameters. If, in examples, one looks for a needle in a haystack, then the tag()
function uses a parameter of its own, which is how one specifies the needle, but the haystack is specified separately, after the parameter parentheses, inside parentheses of its own (perhaps because it's a single value tuple?).
use nom::bytes::complete::tag;
fn parser(s: &str) -> IResult<&str, &str> {
tag("Hello")(s)
}
In the example above, tag()
's job is to test whether the input s
starts with Hello
. You can call parser
, passing in "Hello everybody!, and the tag()
function does indeed verify that the start of s
is Hello. But how did (s)
find its way into tag()
?
Can someone explain this syntax to me, or show where to read about it. It works, and I can use it, but I don't understand what I'm looking at!
thanks