1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 18:17:44 +00:00

LibWeb: Make CSS 'An+B' parsing spec-compliant

Parsing this pattern from CSS tokens turns out to be slightly crazy, but
thankfully well documented in the spec.

The spec lists the cases in order of simple -> complicated, but this
would cause problems in code, since `<n-dimension> <signed-.integer>`
would never by reached, as `<n-dimension>` comes before. Instead, I
have grouped them by their first token.

Also renamed the NthChildPattern class to ANPlusBPattern, to match spec
terminology.
This commit is contained in:
Sam Atkins 2021-07-24 21:22:44 +01:00 committed by Andreas Kling
parent 8d0ff98eff
commit 6034fc0ee6
7 changed files with 333 additions and 92 deletions

View file

@ -33,11 +33,15 @@ public:
};
Type type { Type::Invalid };
struct NthChildPattern {
int step_size { 0 };
int offset = { 0 };
struct ANPlusBPattern {
int step_size { 0 }; // "A"
int offset = { 0 }; // "B"
static NthChildPattern parse(StringView const& args);
static ANPlusBPattern parse(StringView const& args);
String to_string() const
{
return String::formatted("{}n{:+}", step_size, offset);
}
};
struct PseudoClass {
@ -66,7 +70,7 @@ public:
// FIXME: We don't need this field on every single SimpleSelector, but it's also annoying to malloc it somewhere.
// Only used when "pseudo_class" is "NthChild" or "NthLastChild".
NthChildPattern nth_child_pattern;
ANPlusBPattern nth_child_pattern;
SelectorList not_selector {};
};