Skip to content

No way to tell if nested block closed by delimiter or EOF #69

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

Closed
luniv opened this issue Mar 16, 2015 · 2 comments
Closed

No way to tell if nested block closed by delimiter or EOF #69

luniv opened this issue Mar 16, 2015 · 2 comments

Comments

@luniv
Copy link

luniv commented Mar 16, 2015

I'm working on parsing media queries, and my understanding is that the syntax specifies that a media feature must end with a ) [1].

For example, if you have the string "(width", Parser::parse_nested_block will return Ok(_). And there is no easy way to determine how if it was closed by a ) or EOF, as far as I can see.

#[test]
fn block_closed_by_delimiter() {
    let mut input = Parser::new("(width");

    assert!(input.expect_parenthesis_block().is_ok());
    let result = input.parse_nested_block(|input| {
        assert!(input.expect_ident_matching("width").is_ok());
        assert!(input.is_exhausted());
        Ok(true)
    });
    assert!(result.is_err());
}

1: http://drafts.csswg.org/mediaqueries/#typedef-media-feature

<media-feature> = ( [ <mf-plain> | <mf-boolean> | <mf-range> ] )

@SimonSapin
Copy link
Member

This is by design. The CSS error handling rules say that blocks close implicitly at EOF. (The newer CSS Syntax spec has the same behavior, but is less explicit about it.) This rule is implicit in all other grammar-like syntax definitions, to reduce verbosity.

By the way, you might want to copy some of Servo’s media_queries.rs. Maybe eventually the parsing parts could be move to rust-cssparser.

@luniv
Copy link
Author

luniv commented Mar 16, 2015

Ah. Thanks for the information!

I admit the reason I filed this bug was because I was extending the media query support in Servo (kind of got away on me; have pretty much the full spec implemented, just testing it now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants