Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
d0c-s4vage opened this issue Jul 13, 2020 · 1 comment · May be fixed by #39
Open

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

d0c-s4vage opened this issue Jul 13, 2020 · 1 comment · May be fixed by #39
Labels
bug Something isn't working

Comments

@d0c-s4vage
Copy link

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 <[email protected]>"]
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 d0c-s4vage added the bug Something isn't working label Jul 13, 2020
@d0c-s4vage d0c-s4vage linked a pull request Jul 13, 2020 that will close this issue
@d0c-s4vage
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant