зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #19463 - style: Remove free parsing functions, use Integer::parse and Number::parse instead (from emilio:bye-parse-functions); r=jdm
Source-Repo: https://github.com/servo/servo Source-Revision: 14f757817e16a873e60035c1946ae82535038641 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : ebb08a34ecae53148c89dc1118b7422e21211d94
This commit is contained in:
Родитель
d339014f90
Коммит
6ac9b1e2d9
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -109,36 +109,12 @@ impl Parse 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.
|
||||
pub fn parse_number_with_clamping_mode<'i, 't>(context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
clamping_mode: AllowedNumericType)
|
||||
-> Result<Number, ParseError<'i>> {
|
||||
fn parse_number_with_clamping_mode<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
clamping_mode: AllowedNumericType,
|
||||
) -> Result<Number, ParseError<'i>> {
|
||||
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<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 {
|
||||
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 {
|
||||
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>,
|
||||
min: i32
|
||||
) -> 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
|
||||
// time except until computed value time.
|
||||
//
|
||||
|
|
|
@ -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.
|
||||
|
|
Загрузка…
Ссылка в новой задаче