style: Get rid of parse_specified.

It has a single use, and I don't think we should use it in the future.
This commit is contained in:
Emilio Cobos Álvarez 2017-11-07 23:38:22 +01:00
parent 693c3dcfb2
commit 7adad61db8
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
3 changed files with 39 additions and 30 deletions

View file

@ -402,14 +402,10 @@
% endif % endif
} }
% if not property.derived_from: % if not property.derived_from:
pub fn parse_specified<'i, 't>( pub fn parse_declared<'i, 't>(
context: &ParserContext, context: &ParserContext,
input: &mut Parser<'i, 't>, input: &mut Parser<'i, 't>,
% if property.boxed: ) -> Result<PropertyDeclaration, ParseError<'i>> {
) -> Result<Box<SpecifiedValue>, ParseError<'i>> {
% else:
) -> Result<SpecifiedValue, ParseError<'i>> {
% endif
% if property.allow_quirks: % if property.allow_quirks:
parse_quirky(context, input, specified::AllowQuirks::Yes) parse_quirky(context, input, specified::AllowQuirks::Yes)
% else: % else:
@ -418,13 +414,6 @@
% if property.boxed: % if property.boxed:
.map(Box::new) .map(Box::new)
% endif % endif
}
pub fn parse_declared<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<PropertyDeclaration, ParseError<'i>> {
parse_specified(context, input)
.map(PropertyDeclaration::${property.camel_case}) .map(PropertyDeclaration::${property.camel_case})
} }
% endif % endif
@ -938,6 +927,8 @@
// Define property that supports prefixed intrinsic size keyword values for gecko. // Define property that supports prefixed intrinsic size keyword values for gecko.
// E.g. -moz-max-content, -moz-min-content, etc. // E.g. -moz-max-content, -moz-min-content, etc.
//
// FIXME(emilio): This feels a lot like a huge hack, get rid of this.
<%def name="gecko_size_type(name, length_type, initial_value, logical, **kwargs)"> <%def name="gecko_size_type(name, length_type, initial_value, logical, **kwargs)">
<%call expr="longhand(name, <%call expr="longhand(name,
predefined_type=length_type, predefined_type=length_type,
@ -982,20 +973,32 @@
use values::computed::${length_type}; use values::computed::${length_type};
${length_type}::${initial_value} ${length_type}::${initial_value}
} }
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<SpecifiedValue, ParseError<'i>> { impl Parse for SpecifiedValue {
% if logical: fn parse<'i, 't>(
let ret = ${length_type}::parse(context, input); context: &ParserContext,
% else: input: &mut Parser<'i, 't>,
let ret = ${length_type}::parse_quirky(context, input, AllowQuirks::Yes); ) -> Result<SpecifiedValue, ParseError<'i>> {
% endif % if logical:
// Keyword values don't make sense in the block direction; don't parse them let ret = ${length_type}::parse(context, input);
% if "block" in name: % else:
if let Ok(${length_type}::ExtremumLength(..)) = ret { let ret = ${length_type}::parse_quirky(context, input, AllowQuirks::Yes);
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) % endif
} // Keyword values don't make sense in the block direction; don't parse them
% endif % if "block" in name:
ret.map(SpecifiedValue) if let Ok(${length_type}::ExtremumLength(..)) = ret {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
}
% endif
ret.map(SpecifiedValue)
}
}
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<SpecifiedValue, ParseError<'i>> {
SpecifiedValue::parse(context, input)
} }
impl ToComputedValue for SpecifiedValue { impl ToComputedValue for SpecifiedValue {

View file

@ -160,6 +160,11 @@ ${helpers.predefined_type("order", "Integer", "0",
animation_value_type="ComputedValue", animation_value_type="ComputedValue",
spec="https://drafts.csswg.org/css-flexbox/#order-property")} spec="https://drafts.csswg.org/css-flexbox/#order-property")}
// FIXME(emilio): All the sizes stuff, and the MozLength values should be
// unified with Servo, or at least be less hacky.
//
// The block direction ones don't even accept extremum lengths during parsing,
// and should be converted to just LengthOrPercentage.
% if product == "gecko": % if product == "gecko":
// FIXME: Gecko doesn't support content value yet. // FIXME: Gecko doesn't support content value yet.
${helpers.gecko_size_type("flex-basis", "MozLength", "auto()", ${helpers.gecko_size_type("flex-basis", "MozLength", "auto()",

View file

@ -48,6 +48,7 @@
spec="https://drafts.csswg.org/css-flexbox/#flex-property"> spec="https://drafts.csswg.org/css-flexbox/#flex-property">
use parser::Parse; use parser::Parse;
use values::specified::NonNegativeNumber; use values::specified::NonNegativeNumber;
use properties::longhands::flex_basis::SpecifiedValue as FlexBasis;
fn parse_flexibility<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) fn parse_flexibility<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(NonNegativeNumber, Option<NonNegativeNumber>),ParseError<'i>> { -> Result<(NonNegativeNumber, Option<NonNegativeNumber>),ParseError<'i>> {
@ -66,7 +67,7 @@
return Ok(expanded! { return Ok(expanded! {
flex_grow: NonNegativeNumber::new(0.0), flex_grow: NonNegativeNumber::new(0.0),
flex_shrink: NonNegativeNumber::new(0.0), flex_shrink: NonNegativeNumber::new(0.0),
flex_basis: longhands::flex_basis::SpecifiedValue::auto(), flex_basis: FlexBasis::auto(),
}) })
} }
loop { loop {
@ -78,7 +79,7 @@
} }
} }
if basis.is_none() { if basis.is_none() {
if let Ok(value) = input.try(|input| longhands::flex_basis::parse_specified(context, input)) { if let Ok(value) = input.try(|input| FlexBasis::parse(context, input)) {
basis = Some(value); basis = Some(value);
continue continue
} }
@ -96,7 +97,7 @@
// browsers currently agree on using `0%`. This is a spec // browsers currently agree on using `0%`. This is a spec
// change which hasn't been adopted by browsers: // change which hasn't been adopted by browsers:
// https://github.com/w3c/csswg-drafts/commit/2c446befdf0f686217905bdd7c92409f6bd3921b // https://github.com/w3c/csswg-drafts/commit/2c446befdf0f686217905bdd7c92409f6bd3921b
flex_basis: basis.unwrap_or(longhands::flex_basis::SpecifiedValue::zero_percent()), flex_basis: basis.unwrap_or(FlexBasis::zero_percent()),
}) })
} }
</%helpers:shorthand> </%helpers:shorthand>