rustwasm / weedle

A WebIDL Parser
MIT License
43 stars 27 forks source link

Unable to parse extended attribute with quoted tuple of values #38

Open d0c-s4vage opened 4 years ago

d0c-s4vage commented 4 years ago

Describe the Bug

Weedle seems to be unable to parse extended attributes that contain a tuple of quoted values.

Steps to Reproduce

For example, this parses correctly:

fn parse_non_quoted() {
    let data: &str = r#"
        [Attribute=(hello, there)]
        interface HTMLImageElement : HTMLElement {
        };
    "#;
    match weedle::parse(data) {
        Ok(v) => println!("  parsed! \n\n{:?}", v),
        Err(e) => println!("  could not parse: {}", e),
    };
}

With the result:

[Interface(InterfaceDefinition { attributes: Some(Bracketed { open_bracket: OpenBracket, body: Punctuated { list: [IdentList(ExtendedAttributeIdentList { identifier: Identifier("Attribute"), assign: Assign, list: Parenthesized { open_paren: OpenParen, body: Punctuated { list: [Identifier("hello"), Identifier("there")], separator: Comma }, close_paren: CloseParen } })], separator: Comma }, close_bracket: CloseBracket }), interface: Interface, identifier: Identifier("HTMLImageElement"), inheritance: Some(Inheritance { colon: Colon, identifier: Identifier("HTMLElement") }), members: Braced { open_brace: OpenBrace, body: [], close_brace: CloseBrace }, semi_colon: SemiColon })]

while quoted tuple values do not parse correctly:

fn parse_quoted() {
    let data: &str = r#"
        [Attribute=("hello", "there")]
        interface Test {
        };
    "#;
    match weedle::parse(data) {
        Ok(v) => println!("  parsed! \n\n{:?}", v),
        Err(e) => println!("  could not parse: {}", e),
    };
}

This is also observed while parsing chrome IDLs:

Source Data

src/main.rs

extern crate weedle;

fn parse_non_quoted() {
    let data: &str = r#"
        [Attribute=(hello, there)]
        interface HTMLImageElement : HTMLElement {
        };
    "#;
    match weedle::parse(data) {
        Ok(v) => println!("  parsed! \n\n{:?}", v),
        Err(e) => println!("  could not parse: {}", e),
    };
}

fn parse_quoted() {
    let data: &str = r#"
        [Attribute=("hello", "there")]
        interface Test {
        };
    "#;
    match weedle::parse(data) {
        Ok(v) => println!("  parsed! \n\n{:?}", v),
        Err(e) => println!("  could not parse: {}", e),
    };
}

fn main() {
    println!("Parsing extended attribute with non-quoted values in tuple");
    parse_non_quoted();

    println!("Parsing extended attribute with quoted values in tuple");
    parse_quoted();
}

Cargo.toml

[package]
name = "weedle_test"
version = "0.1.0"
authors = ["James Johnson <d0c.s4vage@gmail.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
weedle = "0.11.0"
d0c-s4vage commented 4 years ago

I already made mention of this on the PR (#39), but wanted to bring it up here as well:

This may only be a chrome IDL issue since the official WebIDL grammar (https://heycam.github.io/webidl/#es-extended-attributes) only seems to support identifier lists, not string lists. Feel free to ignore/close this issue if this is indeed the case.

I can understand wanting to keep this library strictly in-line with the official grammar.