3
votes

I have such a macro:

macro_rules! expect_token (
    ([$($token:matchers, $result:expr)|+] <= $tokens:ident, $parsed_tokens:ident, $error:expr) => (
        match $tokens.pop() {
            $(
                Some($token) => {
                    $parsed_tokens.push($token);
                    $result
                },
             )+
             None => {
                 $parsed_tokens.reverse();
                 $tokens.extend($parsed_tokens.into_iter());
                 return NotComplete;
             },
            _ => return error(expr)
        }
    );
)

when I call it with expect_token!([Ident(name), name] <= tokens, parsed_tokens, "expected function name in prototype"); I get the error "error: expected open delimiter".

What does this error mean and what I am doing wrong?

P.S. If you are wondering what is the definition of identifiers like NotComplete, you can look at https://github.com/jauhien/iron-kaleidoscope/blob/master/src/parser.rs, but it is not relevant for this question as far as I understand, as the problem is not with the macro body, but with its invocation.

1
Have you tired log_syntax! and/or trace_macros!(true)? - errordeveloper
trace_macros!(true) gives no additional information: expect_token! { [ Ident ( name ) , name ] <= tokens , parsed_tokens , "expected function name in prototype" } /home/jauhien/work/rust/iron-repl/iron-repl/src/parser.rs:167:31: 167:36 error: expected open delimiter /home/jauhien/work/rust/iron-repl/iron-repl/src/parser.rs:167 let name = expect_token!([Ident(name), name] <= tokens, parsed_tokens, "expected function name in prototype"); Regarding log_syntax!, I have not found how to properly use it. - Jaŭhien Piatlicki
@errordeveloper: log_syntax! also gives no additional information - Jaŭhien Piatlicki

1 Answers

0
votes

Ok, I have found the response: matchers in macros invocation should be enclosed in parenthesis. The problem was in my misunderstanding of matchers as left hand side of match rules, while they are lhs of the => in macro rules, which is clearly stated in documentation.

P.S. What about the whole macros I gave as example it is wrong anyway. )