Skip to content

macro with repeating arguments fails with ambiguous parse #5902

Closed
@metajack

Description

@metajack

The following macro won't work without the extra set of parens:

macro_rules! handle_element(
    ($tag:expr, $string:expr, $type_id:expr, $ctor:ident, [ $(($field:ident : $field_init:expr)),* ]) => (
        if eq_slice($tag, $string) {
            let _element = ~$ctor {
                parent: Element::new($type_id, ($tag).to_str()),
                $(
                    $field: $field_init,
                )*
            };
            unsafe {
                return Node::as_abstract_node(_element);
            }
        }
    )
)

Here's an example use:

    handle_element!(tag, "ul", HTMLUListElementTypeId, HTMLUListElement, []);
    handle_element!(tag, "img", HTMLImageElementTypeId, HTMLImageElement, [(image: None)]);

I'd like to remove those extra parens. It seems like [ $($field:ident),* ] should be unambiguous, but rustc doesn't like it.

The actual error is error: Local ambiguity: multiple parsing options: built-in NTs ident ('field') or 1 other options. Also, it seems like it should tell me the other options so I have some clue what is going wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTA-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions