From 8a8614eccd2fdf3f9756de91ee1feccf9afdb813 Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 12 Jul 2017 21:50:45 +0200 Subject: [PATCH] CSS-wide keywords parsing in longhands: use a single code path with IDs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … rather than generating similar code for every longhand property. --- components/style/properties/helpers.mako.rs | 43 ++++++++----------- .../style/properties/properties.mako.rs | 37 ++++++++++------ 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 22c514793756..46205c1b6278 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -452,31 +452,26 @@ } pub fn parse_declared<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - match input.try(|i| CSSWideKeyword::parse(context, i)) { - Ok(keyword) => Ok(PropertyDeclaration::CSSWideKeyword(LonghandId::${property.camel_case}, keyword)), - Err(_) => { - input.look_for_var_functions(); - 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)) - } + input.look_for_var_functions(); + 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 } diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 7c010846cb68..67b49db71c52 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1521,22 +1521,31 @@ impl PropertyDeclaration { Ok(()) } PropertyId::Longhand(id) => { - match id { - % for property in data.longhands: - LonghandId::${property.camel_case} => { - % if not property.derived_from: - match longhands::${property.ident}::parse_declared(context, input) { - Ok(value) => { - declarations.push(value); - Ok(()) - }, - Err(_) => Err(PropertyDeclarationParseError::InvalidValue("${property.ident}".into())), + if let Ok(keyword) = input.try(|i| CSSWideKeyword::parse(context, i)) { + declarations.push(PropertyDeclaration::CSSWideKeyword(id, keyword)) + Ok(()) + } else { + match id { + % for property in data.longhands: + LonghandId::${property.camel_case} => { + % if not property.derived_from: + match longhands::${property.ident}::parse_declared(context, input) { + Ok(value) => { + declarations.push(value); + Ok(()) + }, + Err(_) => { + Err(PropertyDeclarationParseError::InvalidValue( + "${property.ident}".into() + )) + } + } + % else: + Err(PropertyDeclarationParseError::UnknownProperty) + % endif } - % else: - Err(PropertyDeclarationParseError::UnknownProperty) - % endif + % endfor } - % endfor } } PropertyId::Shorthand(id) => {