From 93fc9ab63a895b5d1204d7ddb4c1c7729a524a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 2 Dec 2017 16:14:26 +0100 Subject: [PATCH] style: Remove free parsing functions, use Integer::parse and Number::parse instead. --- .../properties/longhand/counters.mako.rs | 2 +- components/style/values/specified/mod.rs | 55 ++++++--------- .../style/values/specified/transform.rs | 68 +++++++++---------- 3 files changed, 57 insertions(+), 68 deletions(-) diff --git a/components/style/properties/longhand/counters.mako.rs b/components/style/properties/longhand/counters.mako.rs index b7b9cc21f4d..1ac7422cd24 100644 --- a/components/style/properties/longhand/counters.mako.rs +++ b/components/style/properties/longhand/counters.mako.rs @@ -334,7 +334,7 @@ Ok(t) => return Err(location.new_unexpected_token_error(t.clone())), Err(_) => break, }; - let counter_delta = input.try(|input| specified::parse_integer(context, input)) + let counter_delta = input.try(|input| specified::Integer::parse(context, input)) .unwrap_or(specified::Integer::new(default_value)); counters.push((counter_name, counter_delta)) } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 16401f4ddc0..65796120392 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -109,36 +109,12 @@ impl Parse for SpecifiedUrl { impl Eq for SpecifiedUrl {} } -/// Parse an `` value, handling `calc()` correctly. -pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - let location = input.current_source_location(); - // FIXME: remove early returns when lifetimes are non-lexical - match *input.next()? { - Token::Number { int_value: Some(v), .. } => return Ok(Integer::new(v)), - Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {} - ref t => return Err(location.new_unexpected_token_error(t.clone())) - } - - let result = input.parse_nested_block(|i| { - CalcNode::parse_integer(context, i) - })?; - - Ok(Integer::from_calc(result)) -} - -/// Parse a `` value, handling `calc()` correctly, and without length -/// limitations. -pub fn parse_number<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) - -> Result> { - parse_number_with_clamping_mode(context, input, AllowedNumericType::All) -} - /// Parse a `` value, with a given clamping mode. -pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext, - input: &mut Parser<'i, 't>, - clamping_mode: AllowedNumericType) - -> Result> { +fn parse_number_with_clamping_mode<'i, 't>( + context: &ParserContext, + input: &mut Parser<'i, 't>, + clamping_mode: AllowedNumericType, +) -> Result> { let location = input.current_source_location(); // FIXME: remove early returns when lifetimes are non-lexical match *input.next()? { @@ -200,7 +176,7 @@ pub struct Number { impl Parse for Number { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - parse_number(context, input) + parse_number_with_clamping_mode(context, input, AllowedNumericType::All) } } @@ -357,7 +333,7 @@ pub struct Opacity(Number); impl Parse for Opacity { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - parse_number(context, input).map(Opacity) + Number::parse(context, input).map(Opacity) } } @@ -416,7 +392,20 @@ impl Integer { impl Parse for Integer { fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { - parse_integer(context, input) + let location = input.current_source_location(); + + // FIXME: remove early returns when lifetimes are non-lexical + match *input.next()? { + Token::Number { int_value: Some(v), .. } => return Ok(Integer::new(v)), + Token::Function(ref name) if name.eq_ignore_ascii_case("calc") => {} + ref t => return Err(location.new_unexpected_token_error(t.clone())) + } + + let result = input.parse_nested_block(|i| { + CalcNode::parse_integer(context, i) + })?; + + Ok(Integer::from_calc(result)) } } @@ -427,7 +416,7 @@ impl Integer { input: &mut Parser<'i, 't>, min: i32 ) -> Result> { - match parse_integer(context, input) { + match Integer::parse(context, input) { // FIXME(emilio): The spec asks us to avoid rejecting it at parse // time except until computed value time. // diff --git a/components/style/values/specified/transform.rs b/components/style/values/specified/transform.rs index ca77bd7a723..4b49d2065d1 100644 --- a/components/style/values/specified/transform.rs +++ b/components/style/values/specified/transform.rs @@ -60,19 +60,19 @@ impl Transform { let result = match_ignore_ascii_case! { &function, "matrix" => { - let a = specified::parse_number(context, input)?; + let a = Number::parse(context, input)?; input.expect_comma()?; - let b = specified::parse_number(context, input)?; + let b = Number::parse(context, input)?; input.expect_comma()?; - let c = specified::parse_number(context, input)?; + let c = Number::parse(context, input)?; input.expect_comma()?; - let d = specified::parse_number(context, input)?; + let d = Number::parse(context, input)?; input.expect_comma()?; if !prefixed { // Standard matrix parsing. - let e = specified::parse_number(context, input)?; + let e = Number::parse(context, input)?; input.expect_comma()?; - let f = specified::parse_number(context, input)?; + let f = Number::parse(context, input)?; Ok(GenericTransformOperation::Matrix(Matrix { a, b, c, d, e, f })) } else { // Non-standard prefixed matrix parsing for -moz-transform. @@ -83,39 +83,39 @@ impl Transform { } }, "matrix3d" => { - let m11 = specified::parse_number(context, input)?; + let m11 = Number::parse(context, input)?; input.expect_comma()?; - let m12 = specified::parse_number(context, input)?; + let m12 = Number::parse(context, input)?; input.expect_comma()?; - let m13 = specified::parse_number(context, input)?; + let m13 = Number::parse(context, input)?; input.expect_comma()?; - let m14 = specified::parse_number(context, input)?; + let m14 = Number::parse(context, input)?; input.expect_comma()?; - let m21 = specified::parse_number(context, input)?; + let m21 = Number::parse(context, input)?; input.expect_comma()?; - let m22 = specified::parse_number(context, input)?; + let m22 = Number::parse(context, input)?; input.expect_comma()?; - let m23 = specified::parse_number(context, input)?; + let m23 = Number::parse(context, input)?; input.expect_comma()?; - let m24 = specified::parse_number(context, input)?; + let m24 = Number::parse(context, input)?; input.expect_comma()?; - let m31 = specified::parse_number(context, input)?; + let m31 = Number::parse(context, input)?; input.expect_comma()?; - let m32 = specified::parse_number(context, input)?; + let m32 = Number::parse(context, input)?; input.expect_comma()?; - let m33 = specified::parse_number(context, input)?; + let m33 = Number::parse(context, input)?; input.expect_comma()?; - let m34 = specified::parse_number(context, input)?; + let m34 = Number::parse(context, input)?; input.expect_comma()?; if !prefixed { // Standard matrix3d parsing. - let m41 = specified::parse_number(context, input)?; + let m41 = Number::parse(context, input)?; input.expect_comma()?; - let m42 = specified::parse_number(context, input)?; + let m42 = Number::parse(context, input)?; input.expect_comma()?; - let m43 = specified::parse_number(context, input)?; + let m43 = Number::parse(context, input)?; input.expect_comma()?; - let m44 = specified::parse_number(context, input)?; + let m44 = Number::parse(context, input)?; Ok(GenericTransformOperation::Matrix3D(Matrix3D { m11, m12, m13, m14, m21, m22, m23, m24, @@ -130,7 +130,7 @@ impl Transform { input.expect_comma()?; let m43 = LengthOrNumber::parse(context, input)?; input.expect_comma()?; - let m44 = specified::parse_number(context, input)?; + let m44 = Number::parse(context, input)?; Ok(GenericTransformOperation::PrefixedMatrix3D(Matrix3D { m11, m12, m13, m14, m21, m22, m23, m24, @@ -169,32 +169,32 @@ impl Transform { Ok(GenericTransformOperation::Translate3D(tx, ty, tz)) }, "scale" => { - let sx = specified::parse_number(context, input)?; + let sx = Number::parse(context, input)?; if input.try(|input| input.expect_comma()).is_ok() { - let sy = specified::parse_number(context, input)?; + let sy = Number::parse(context, input)?; Ok(GenericTransformOperation::Scale(sx, Some(sy))) } else { Ok(GenericTransformOperation::Scale(sx, None)) } }, "scalex" => { - let sx = specified::parse_number(context, input)?; + let sx = Number::parse(context, input)?; Ok(GenericTransformOperation::ScaleX(sx)) }, "scaley" => { - let sy = specified::parse_number(context, input)?; + let sy = Number::parse(context, input)?; Ok(GenericTransformOperation::ScaleY(sy)) }, "scalez" => { - let sz = specified::parse_number(context, input)?; + let sz = Number::parse(context, input)?; Ok(GenericTransformOperation::ScaleZ(sz)) }, "scale3d" => { - let sx = specified::parse_number(context, input)?; + let sx = Number::parse(context, input)?; input.expect_comma()?; - let sy = specified::parse_number(context, input)?; + let sy = Number::parse(context, input)?; input.expect_comma()?; - let sz = specified::parse_number(context, input)?; + let sz = Number::parse(context, input)?; Ok(GenericTransformOperation::Scale3D(sx, sy, sz)) }, "rotate" => { @@ -214,11 +214,11 @@ impl Transform { Ok(GenericTransformOperation::RotateZ(theta)) }, "rotate3d" => { - let ax = specified::parse_number(context, input)?; + let ax = Number::parse(context, input)?; input.expect_comma()?; - let ay = specified::parse_number(context, input)?; + let ay = Number::parse(context, input)?; input.expect_comma()?; - let az = specified::parse_number(context, input)?; + let az = Number::parse(context, input)?; input.expect_comma()?; let theta = specified::Angle::parse_with_unitless(context, input)?; // TODO(gw): Check that the axis can be normalized.