mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Auto merge of #19463 - emilio:bye-parse-functions, r=jdm
style: Remove free parsing functions, use Integer::parse and Number::parse instead. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19463) <!-- Reviewable:end -->
This commit is contained in:
commit
14f757817e
3 changed files with 57 additions and 68 deletions
|
@ -334,7 +334,7 @@
|
||||||
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
Ok(t) => return Err(location.new_unexpected_token_error(t.clone())),
|
||||||
Err(_) => break,
|
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));
|
.unwrap_or(specified::Integer::new(default_value));
|
||||||
counters.push((counter_name, counter_delta))
|
counters.push((counter_name, counter_delta))
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,36 +109,12 @@ impl Parse for SpecifiedUrl {
|
||||||
impl Eq for SpecifiedUrl {}
|
impl Eq for SpecifiedUrl {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse an `<integer>` value, handling `calc()` correctly.
|
|
||||||
pub fn parse_integer<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
|
||||||
-> Result<Integer, ParseError<'i>> {
|
|
||||||
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 `<number>` value, handling `calc()` correctly, and without length
|
|
||||||
/// limitations.
|
|
||||||
pub fn parse_number<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
|
||||||
-> Result<Number, ParseError<'i>> {
|
|
||||||
parse_number_with_clamping_mode(context, input, AllowedNumericType::All)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parse a `<number>` value, with a given clamping mode.
|
/// Parse a `<number>` value, with a given clamping mode.
|
||||||
pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
|
fn parse_number_with_clamping_mode<'i, 't>(
|
||||||
input: &mut Parser<'i, 't>,
|
context: &ParserContext,
|
||||||
clamping_mode: AllowedNumericType)
|
input: &mut Parser<'i, 't>,
|
||||||
-> Result<Number, ParseError<'i>> {
|
clamping_mode: AllowedNumericType,
|
||||||
|
) -> Result<Number, ParseError<'i>> {
|
||||||
let location = input.current_source_location();
|
let location = input.current_source_location();
|
||||||
// FIXME: remove early returns when lifetimes are non-lexical
|
// FIXME: remove early returns when lifetimes are non-lexical
|
||||||
match *input.next()? {
|
match *input.next()? {
|
||||||
|
@ -200,7 +176,7 @@ pub struct Number {
|
||||||
|
|
||||||
impl Parse for Number {
|
impl Parse for Number {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
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 {
|
impl Parse for Opacity {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
parse_number(context, input).map(Opacity)
|
Number::parse(context, input).map(Opacity)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,7 +392,20 @@ impl Integer {
|
||||||
|
|
||||||
impl Parse for Integer {
|
impl Parse for Integer {
|
||||||
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
|
||||||
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>,
|
input: &mut Parser<'i, 't>,
|
||||||
min: i32
|
min: i32
|
||||||
) -> Result<Integer, ParseError<'i>> {
|
) -> Result<Integer, ParseError<'i>> {
|
||||||
match parse_integer(context, input) {
|
match Integer::parse(context, input) {
|
||||||
// FIXME(emilio): The spec asks us to avoid rejecting it at parse
|
// FIXME(emilio): The spec asks us to avoid rejecting it at parse
|
||||||
// time except until computed value time.
|
// time except until computed value time.
|
||||||
//
|
//
|
||||||
|
|
|
@ -60,19 +60,19 @@ impl Transform {
|
||||||
let result =
|
let result =
|
||||||
match_ignore_ascii_case! { &function,
|
match_ignore_ascii_case! { &function,
|
||||||
"matrix" => {
|
"matrix" => {
|
||||||
let a = specified::parse_number(context, input)?;
|
let a = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let b = specified::parse_number(context, input)?;
|
let b = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let c = specified::parse_number(context, input)?;
|
let c = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let d = specified::parse_number(context, input)?;
|
let d = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
if !prefixed {
|
if !prefixed {
|
||||||
// Standard matrix parsing.
|
// Standard matrix parsing.
|
||||||
let e = specified::parse_number(context, input)?;
|
let e = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
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 }))
|
Ok(GenericTransformOperation::Matrix(Matrix { a, b, c, d, e, f }))
|
||||||
} else {
|
} else {
|
||||||
// Non-standard prefixed matrix parsing for -moz-transform.
|
// Non-standard prefixed matrix parsing for -moz-transform.
|
||||||
|
@ -83,39 +83,39 @@ impl Transform {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"matrix3d" => {
|
"matrix3d" => {
|
||||||
let m11 = specified::parse_number(context, input)?;
|
let m11 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m12 = specified::parse_number(context, input)?;
|
let m12 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m13 = specified::parse_number(context, input)?;
|
let m13 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m14 = specified::parse_number(context, input)?;
|
let m14 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m21 = specified::parse_number(context, input)?;
|
let m21 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m22 = specified::parse_number(context, input)?;
|
let m22 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m23 = specified::parse_number(context, input)?;
|
let m23 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m24 = specified::parse_number(context, input)?;
|
let m24 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m31 = specified::parse_number(context, input)?;
|
let m31 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m32 = specified::parse_number(context, input)?;
|
let m32 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m33 = specified::parse_number(context, input)?;
|
let m33 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m34 = specified::parse_number(context, input)?;
|
let m34 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
if !prefixed {
|
if !prefixed {
|
||||||
// Standard matrix3d parsing.
|
// Standard matrix3d parsing.
|
||||||
let m41 = specified::parse_number(context, input)?;
|
let m41 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m42 = specified::parse_number(context, input)?;
|
let m42 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m43 = specified::parse_number(context, input)?;
|
let m43 = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m44 = specified::parse_number(context, input)?;
|
let m44 = Number::parse(context, input)?;
|
||||||
Ok(GenericTransformOperation::Matrix3D(Matrix3D {
|
Ok(GenericTransformOperation::Matrix3D(Matrix3D {
|
||||||
m11, m12, m13, m14,
|
m11, m12, m13, m14,
|
||||||
m21, m22, m23, m24,
|
m21, m22, m23, m24,
|
||||||
|
@ -130,7 +130,7 @@ impl Transform {
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m43 = LengthOrNumber::parse(context, input)?;
|
let m43 = LengthOrNumber::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let m44 = specified::parse_number(context, input)?;
|
let m44 = Number::parse(context, input)?;
|
||||||
Ok(GenericTransformOperation::PrefixedMatrix3D(Matrix3D {
|
Ok(GenericTransformOperation::PrefixedMatrix3D(Matrix3D {
|
||||||
m11, m12, m13, m14,
|
m11, m12, m13, m14,
|
||||||
m21, m22, m23, m24,
|
m21, m22, m23, m24,
|
||||||
|
@ -169,32 +169,32 @@ impl Transform {
|
||||||
Ok(GenericTransformOperation::Translate3D(tx, ty, tz))
|
Ok(GenericTransformOperation::Translate3D(tx, ty, tz))
|
||||||
},
|
},
|
||||||
"scale" => {
|
"scale" => {
|
||||||
let sx = specified::parse_number(context, input)?;
|
let sx = Number::parse(context, input)?;
|
||||||
if input.try(|input| input.expect_comma()).is_ok() {
|
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)))
|
Ok(GenericTransformOperation::Scale(sx, Some(sy)))
|
||||||
} else {
|
} else {
|
||||||
Ok(GenericTransformOperation::Scale(sx, None))
|
Ok(GenericTransformOperation::Scale(sx, None))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scalex" => {
|
"scalex" => {
|
||||||
let sx = specified::parse_number(context, input)?;
|
let sx = Number::parse(context, input)?;
|
||||||
Ok(GenericTransformOperation::ScaleX(sx))
|
Ok(GenericTransformOperation::ScaleX(sx))
|
||||||
},
|
},
|
||||||
"scaley" => {
|
"scaley" => {
|
||||||
let sy = specified::parse_number(context, input)?;
|
let sy = Number::parse(context, input)?;
|
||||||
Ok(GenericTransformOperation::ScaleY(sy))
|
Ok(GenericTransformOperation::ScaleY(sy))
|
||||||
},
|
},
|
||||||
"scalez" => {
|
"scalez" => {
|
||||||
let sz = specified::parse_number(context, input)?;
|
let sz = Number::parse(context, input)?;
|
||||||
Ok(GenericTransformOperation::ScaleZ(sz))
|
Ok(GenericTransformOperation::ScaleZ(sz))
|
||||||
},
|
},
|
||||||
"scale3d" => {
|
"scale3d" => {
|
||||||
let sx = specified::parse_number(context, input)?;
|
let sx = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let sy = specified::parse_number(context, input)?;
|
let sy = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let sz = specified::parse_number(context, input)?;
|
let sz = Number::parse(context, input)?;
|
||||||
Ok(GenericTransformOperation::Scale3D(sx, sy, sz))
|
Ok(GenericTransformOperation::Scale3D(sx, sy, sz))
|
||||||
},
|
},
|
||||||
"rotate" => {
|
"rotate" => {
|
||||||
|
@ -214,11 +214,11 @@ impl Transform {
|
||||||
Ok(GenericTransformOperation::RotateZ(theta))
|
Ok(GenericTransformOperation::RotateZ(theta))
|
||||||
},
|
},
|
||||||
"rotate3d" => {
|
"rotate3d" => {
|
||||||
let ax = specified::parse_number(context, input)?;
|
let ax = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let ay = specified::parse_number(context, input)?;
|
let ay = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let az = specified::parse_number(context, input)?;
|
let az = Number::parse(context, input)?;
|
||||||
input.expect_comma()?;
|
input.expect_comma()?;
|
||||||
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
let theta = specified::Angle::parse_with_unitless(context, input)?;
|
||||||
// TODO(gw): Check that the axis can be normalized.
|
// TODO(gw): Check that the axis can be normalized.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue