mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
CSS-wide keywords parsing in shorthand: use a single code path with IDs
… rather than generating similar code for each shorthand.
This commit is contained in:
parent
3075746edd
commit
a5b80e2d75
1 changed files with 18 additions and 22 deletions
|
@ -1540,30 +1540,26 @@ impl PropertyDeclaration {
|
|||
}
|
||||
}
|
||||
PropertyId::Shorthand(id) => {
|
||||
match id {
|
||||
% for shorthand in data.shorthands:
|
||||
ShorthandId::${shorthand.camel_case} => {
|
||||
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
Ok(keyword) => {
|
||||
% if shorthand.name == "all":
|
||||
declarations.all_shorthand = AllShorthand::CSSWideKeyword(keyword);
|
||||
% else:
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
declarations.push(PropertyDeclaration::CSSWideKeyword(
|
||||
LonghandId::${sub_property.camel_case},
|
||||
keyword,
|
||||
));
|
||||
% endfor
|
||||
% endif
|
||||
Ok(())
|
||||
},
|
||||
Err(_) => {
|
||||
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
|
||||
.map_err(|_| PropertyDeclarationParseError::InvalidValue("${shorthand.ident}".into()))
|
||||
}
|
||||
if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
if id == ShorthandId::All {
|
||||
declarations.all_shorthand = AllShorthand::CSSWideKeyword(keyword)
|
||||
} else {
|
||||
for &longhand in id.longhands() {
|
||||
declarations.push(PropertyDeclaration::CSSWideKeyword(longhand, keyword))
|
||||
}
|
||||
}
|
||||
% endfor
|
||||
Ok(())
|
||||
} else {
|
||||
match id {
|
||||
% for shorthand in data.shorthands:
|
||||
ShorthandId::${shorthand.camel_case} => {
|
||||
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
|
||||
.map_err(|_| PropertyDeclarationParseError::InvalidValue(
|
||||
"${shorthand.ident}".into()
|
||||
))
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue