mirror of
https://github.com/servo/servo.git
synced 2025-08-10 07:55:33 +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,28 +1540,23 @@ impl PropertyDeclaration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PropertyId::Shorthand(id) => {
|
PropertyId::Shorthand(id) => {
|
||||||
|
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))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
match id {
|
match id {
|
||||||
% for shorthand in data.shorthands:
|
% for shorthand in data.shorthands:
|
||||||
ShorthandId::${shorthand.camel_case} => {
|
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)
|
shorthands::${shorthand.ident}::parse_into(declarations, context, input)
|
||||||
.map_err(|_| PropertyDeclarationParseError::InvalidValue("${shorthand.ident}".into()))
|
.map_err(|_| PropertyDeclarationParseError::InvalidValue(
|
||||||
}
|
"${shorthand.ident}".into()
|
||||||
}
|
))
|
||||||
}
|
}
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
@ -1569,6 +1564,7 @@ impl PropertyDeclaration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const MAX_SUB_PROPERTIES_PER_SHORTHAND_EXCEPT_ALL: usize =
|
const MAX_SUB_PROPERTIES_PER_SHORTHAND_EXCEPT_ALL: usize =
|
||||||
${max(len(s.sub_properties) for s in data.shorthands_except_all())};
|
${max(len(s.sub_properties) for s in data.shorthands_except_all())};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue