mirror of
https://github.com/servo/servo.git
synced 2025-06-24 09:04:33 +01:00
var() functions in longhands: use a single code path with IDs
… rather than generating similar code for every longhand property
This commit is contained in:
parent
252e52e24e
commit
54f1325a49
2 changed files with 39 additions and 46 deletions
|
@ -452,26 +452,7 @@
|
||||||
}
|
}
|
||||||
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>> {
|
||||||
input.look_for_var_functions();
|
parse_specified(context, input).map(PropertyDeclaration::${property.camel_case})
|
||||||
let start = input.position();
|
|
||||||
let specified = parse_specified(context, input);
|
|
||||||
if specified.is_err() {
|
|
||||||
while let Ok(_) = input.next() {} // Look for var() after the error.
|
|
||||||
}
|
|
||||||
let var = input.seen_var_functions();
|
|
||||||
if specified.is_err() && var {
|
|
||||||
input.reset(start);
|
|
||||||
let (first_token_type, css) =
|
|
||||||
::custom_properties::parse_non_custom_with_var(input)?;
|
|
||||||
return Ok(PropertyDeclaration::WithVariables(LonghandId::${property.camel_case},
|
|
||||||
Arc::new(UnparsedValue {
|
|
||||||
css: css.into_owned(),
|
|
||||||
first_token_type: first_token_type,
|
|
||||||
url_data: context.url_data.clone(),
|
|
||||||
from_shorthand: None,
|
|
||||||
})))
|
|
||||||
}
|
|
||||||
specified.map(|s| PropertyDeclaration::${property.camel_case}(s))
|
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -1521,32 +1521,44 @@ impl PropertyDeclaration {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
PropertyId::Longhand(id) => {
|
PropertyId::Longhand(id) => {
|
||||||
if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) {
|
input.try(|i| CSSWideKeyword::parse(context, i)).map(|keyword| {
|
||||||
declarations.push(PropertyDeclaration::CSSWideKeyword(id, keyword));
|
PropertyDeclaration::CSSWideKeyword(id, keyword)
|
||||||
Ok(())
|
}).or_else(|_| {
|
||||||
} else {
|
input.look_for_var_functions();
|
||||||
match id {
|
let start = input.position();
|
||||||
% for property in data.longhands:
|
input.parse_entirely(|input| {
|
||||||
LonghandId::${property.camel_case} => {
|
match id {
|
||||||
% if not property.derived_from:
|
% for property in data.longhands:
|
||||||
match longhands::${property.ident}::parse_declared(context, input) {
|
LonghandId::${property.camel_case} => {
|
||||||
Ok(value) => {
|
% if not property.derived_from:
|
||||||
declarations.push(value);
|
longhands::${property.ident}::parse_declared(context, input)
|
||||||
Ok(())
|
% else:
|
||||||
},
|
Err(PropertyDeclarationParseError::UnknownProperty)
|
||||||
Err(_) => {
|
% endif
|
||||||
Err(PropertyDeclarationParseError::InvalidValue(
|
}
|
||||||
"${property.ident}".into()
|
% endfor
|
||||||
))
|
}
|
||||||
}
|
}).or_else(|_| {
|
||||||
}
|
while let Ok(_) = input.next() {} // Look for var() after the error.
|
||||||
% else:
|
if input.seen_var_functions() {
|
||||||
Err(PropertyDeclarationParseError::UnknownProperty)
|
input.reset(start);
|
||||||
% endif
|
let (first_token_type, css) =
|
||||||
}
|
::custom_properties::parse_non_custom_with_var(input).map_err(|_| {
|
||||||
% endfor
|
PropertyDeclarationParseError::InvalidValue(id.name().into())
|
||||||
}
|
})?;
|
||||||
}
|
Ok(PropertyDeclaration::WithVariables(id, Arc::new(UnparsedValue {
|
||||||
|
css: css.into_owned(),
|
||||||
|
first_token_type: first_token_type,
|
||||||
|
url_data: context.url_data.clone(),
|
||||||
|
from_shorthand: None,
|
||||||
|
})))
|
||||||
|
} else {
|
||||||
|
Err(PropertyDeclarationParseError::InvalidValue(id.name().into()))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}).map(|declaration| {
|
||||||
|
declarations.push(declaration)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
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)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue