1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:07:35 +00:00

LibWeb: Rewrite media-query parsing to match spec grammar

Past me decided that the grammar was overly verbose and I could do it
better myself. Which seemed fine until the spec changed and I didn't
know how to integrate the changes. Lesson learned! :^)

Rather than have a function for every single part of the grammar, I have
written some as lambdas, and combned `<media-condition>` and
`<media-condition-without-or>` into one function. But otherwise it's
close to the spec, with comments listing the part of the grammar being
parsed, so hopefully it will be easier to make future adjustments!

This does not add any new functionality.
This commit is contained in:
Sam Atkins 2022-01-01 11:44:44 +00:00 committed by Andreas Kling
parent b6fe7cc324
commit c3bf9e5b79
3 changed files with 193 additions and 118 deletions

View file

@ -235,9 +235,10 @@ private:
Result<Selector::SimpleSelector, ParsingResult> parse_simple_selector(TokenStream<StyleComponentValueRule>&);
NonnullRefPtr<MediaQuery> parse_media_query(TokenStream<StyleComponentValueRule>&);
OwnPtr<MediaCondition> consume_media_condition(TokenStream<StyleComponentValueRule>&);
Optional<MediaFeature> consume_media_feature(TokenStream<StyleComponentValueRule>&);
Optional<MediaQuery::MediaType> consume_media_type(TokenStream<StyleComponentValueRule>&);
OwnPtr<MediaCondition> parse_media_condition(TokenStream<StyleComponentValueRule>&, MediaCondition::AllowOr allow_or);
Optional<MediaFeature> parse_media_feature(TokenStream<StyleComponentValueRule>&);
Optional<MediaQuery::MediaType> parse_media_type(TokenStream<StyleComponentValueRule>&);
OwnPtr<MediaCondition> parse_media_in_parens(TokenStream<StyleComponentValueRule>&);
Optional<MediaFeatureValue> parse_media_feature_value(TokenStream<StyleComponentValueRule>&);
OwnPtr<Supports::Condition> parse_supports_condition(TokenStream<StyleComponentValueRule>&);