mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
CSS-wide keywords parsing in longhands: use a single code path with IDs
… rather than generating similar code for every longhand property.
This commit is contained in:
parent
a5b80e2d75
commit
8a8614eccd
2 changed files with 42 additions and 38 deletions
|
@ -452,9 +452,6 @@
|
||||||
}
|
}
|
||||||
pub fn parse_declared<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
pub fn parse_declared<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||||
-> Result<PropertyDeclaration, ParseError<'i>> {
|
-> Result<PropertyDeclaration, ParseError<'i>> {
|
||||||
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
|
||||||
Ok(keyword) => Ok(PropertyDeclaration::CSSWideKeyword(LonghandId::${property.camel_case}, keyword)),
|
|
||||||
Err(_) => {
|
|
||||||
input.look_for_var_functions();
|
input.look_for_var_functions();
|
||||||
let start = input.position();
|
let start = input.position();
|
||||||
let specified = parse_specified(context, input);
|
let specified = parse_specified(context, input);
|
||||||
|
@ -476,8 +473,6 @@
|
||||||
}
|
}
|
||||||
specified.map(|s| PropertyDeclaration::${property.camel_case}(s))
|
specified.map(|s| PropertyDeclaration::${property.camel_case}(s))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
% endif
|
% endif
|
||||||
}
|
}
|
||||||
</%def>
|
</%def>
|
||||||
|
|
|
@ -1521,6 +1521,10 @@ impl PropertyDeclaration {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
PropertyId::Longhand(id) => {
|
PropertyId::Longhand(id) => {
|
||||||
|
if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||||
|
declarations.push(PropertyDeclaration::CSSWideKeyword(id, keyword))
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
match id {
|
match id {
|
||||||
% for property in data.longhands:
|
% for property in data.longhands:
|
||||||
LonghandId::${property.camel_case} => {
|
LonghandId::${property.camel_case} => {
|
||||||
|
@ -1530,7 +1534,11 @@ impl PropertyDeclaration {
|
||||||
declarations.push(value);
|
declarations.push(value);
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
Err(_) => Err(PropertyDeclarationParseError::InvalidValue("${property.ident}".into())),
|
Err(_) => {
|
||||||
|
Err(PropertyDeclarationParseError::InvalidValue(
|
||||||
|
"${property.ident}".into()
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
% else:
|
% else:
|
||||||
Err(PropertyDeclarationParseError::UnknownProperty)
|
Err(PropertyDeclarationParseError::UnknownProperty)
|
||||||
|
@ -1539,6 +1547,7 @@ impl PropertyDeclaration {
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
PropertyId::Shorthand(id) => {
|
PropertyId::Shorthand(id) => {
|
||||||
if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) {
|
if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||||
if id == ShorthandId::All {
|
if id == ShorthandId::All {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue