mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 12:37:45 +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:
parent
8d0ff98eff
commit
6034fc0ee6
7 changed files with 333 additions and 92 deletions
|
@ -100,11 +100,34 @@ public:
|
|||
}
|
||||
|
||||
bool is(NumberType number_type) const { return is(Token::Type::Number) && m_number_type == number_type; }
|
||||
|
||||
int integer() const
|
||||
StringView number_string_value() const
|
||||
{
|
||||
VERIFY(m_type == Type::Number);
|
||||
return m_value.string_view();
|
||||
}
|
||||
int to_integer() const
|
||||
{
|
||||
VERIFY(m_type == Type::Number && m_number_type == NumberType::Integer);
|
||||
return m_value.string_view().to_int().value();
|
||||
return number_string_value().to_int().value();
|
||||
}
|
||||
bool is_integer_value_signed() const { return number_string_value().starts_with('-') || number_string_value().starts_with('+'); }
|
||||
|
||||
StringView dimension_unit() const
|
||||
{
|
||||
VERIFY(m_type == Type::Dimension);
|
||||
return m_unit.string_view();
|
||||
}
|
||||
StringView dimension_value() const
|
||||
{
|
||||
VERIFY(m_type == Type::Dimension);
|
||||
return m_value.string_view();
|
||||
}
|
||||
int dimension_value_int() const { return dimension_value().to_int().value(); }
|
||||
|
||||
NumberType number_type() const
|
||||
{
|
||||
VERIFY((m_type == Type::Number) || (m_type == Type::Dimension));
|
||||
return m_number_type;
|
||||
}
|
||||
|
||||
Type mirror_variant() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue