mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Revert try -> r#try change.
Since we're in an inconsistent state because mako files weren't updated, and it's really really ugly.
This commit is contained in:
parent
155caba595
commit
212b3e1311
47 changed files with 326 additions and 336 deletions
|
@ -39,7 +39,7 @@ impl ImageLayer {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(v) = input.r#try(|i| None_::parse(context, i)) {
|
||||
if let Ok(v) = input.try(|i| None_::parse(context, i)) {
|
||||
return Ok(Either::First(v));
|
||||
}
|
||||
Image::parse_with_cors_anonymous(context, input).map(Either::Second)
|
||||
|
@ -142,19 +142,19 @@ impl Parse for Image {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Image, ParseError<'i>> {
|
||||
if let Ok(url) = input.r#try(|input| SpecifiedImageUrl::parse(context, input)) {
|
||||
if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse(context, input)) {
|
||||
return Ok(generic::Image::Url(url));
|
||||
}
|
||||
if let Ok(gradient) = input.r#try(|i| Gradient::parse(context, i)) {
|
||||
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
||||
return Ok(generic::Image::Gradient(Box::new(gradient)));
|
||||
}
|
||||
#[cfg(feature = "servo")]
|
||||
{
|
||||
if let Ok(paint_worklet) = input.r#try(|i| PaintWorklet::parse(context, i)) {
|
||||
if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) {
|
||||
return Ok(generic::Image::PaintWorklet(paint_worklet));
|
||||
}
|
||||
}
|
||||
if let Ok(image_rect) = input.r#try(|input| MozImageRect::parse(context, input)) {
|
||||
if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
|
||||
return Ok(generic::Image::Rect(Box::new(image_rect)));
|
||||
}
|
||||
Ok(generic::Image::Element(Image::parse_element(input)?))
|
||||
|
@ -172,7 +172,7 @@ impl Image {
|
|||
|
||||
/// Parses a `-moz-element(# <element-id>)`.
|
||||
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
|
||||
input.r#try(|i| i.expect_function_matching("-moz-element"))?;
|
||||
input.try(|i| i.expect_function_matching("-moz-element"))?;
|
||||
let location = input.current_source_location();
|
||||
input.parse_nested_block(|i| match *i.next()? {
|
||||
Token::IDHash(ref id) => Ok(Atom::from(id.as_ref())),
|
||||
|
@ -190,7 +190,7 @@ impl Image {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Image, ParseError<'i>> {
|
||||
if let Ok(url) =
|
||||
input.r#try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input))
|
||||
input.try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input))
|
||||
{
|
||||
return Ok(generic::Image::Url(url));
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ impl Gradient {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input.r#try(|i| {
|
||||
input.try(|i| {
|
||||
let x = Component::parse(context, i)?;
|
||||
let y = Component::parse(context, i)?;
|
||||
|
||||
|
@ -413,13 +413,13 @@ impl Gradient {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(side) = input.r#try(|i| S::parse(context, i)) {
|
||||
if let Ok(side) = input.try(|i| S::parse(context, i)) {
|
||||
return Ok(Component::Side(side));
|
||||
}
|
||||
if let Ok(number) = input.r#try(|i| NumberOrPercentage::parse(context, i)) {
|
||||
if let Ok(number) = input.try(|i| NumberOrPercentage::parse(context, i)) {
|
||||
return Ok(Component::Number(number));
|
||||
}
|
||||
input.r#try(|i| i.expect_ident_matching("center"))?;
|
||||
input.try(|i| i.expect_ident_matching("center"))?;
|
||||
Ok(Component::Center)
|
||||
}
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ impl Gradient {
|
|||
};
|
||||
|
||||
let mut items = input
|
||||
.r#try(|i| {
|
||||
.try(|i| {
|
||||
i.expect_comma()?;
|
||||
i.parse_comma_separated(|i| {
|
||||
let function = i.expect_function()?.clone();
|
||||
|
@ -572,16 +572,16 @@ impl GradientKind {
|
|||
input: &mut Parser<'i, 't>,
|
||||
compat_mode: &mut CompatMode,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let direction =
|
||||
if let Ok(d) = input.r#try(|i| LineDirection::parse(context, i, compat_mode)) {
|
||||
input.expect_comma()?;
|
||||
d
|
||||
} else {
|
||||
match *compat_mode {
|
||||
CompatMode::Modern => LineDirection::Vertical(Y::Bottom),
|
||||
_ => LineDirection::Vertical(Y::Top),
|
||||
}
|
||||
};
|
||||
let direction = if let Ok(d) = input.try(|i| LineDirection::parse(context, i, compat_mode))
|
||||
{
|
||||
input.expect_comma()?;
|
||||
d
|
||||
} else {
|
||||
match *compat_mode {
|
||||
CompatMode::Modern => LineDirection::Vertical(Y::Bottom),
|
||||
_ => LineDirection::Vertical(Y::Top),
|
||||
}
|
||||
};
|
||||
Ok(generic::GradientKind::Linear(direction))
|
||||
}
|
||||
|
||||
|
@ -592,16 +592,16 @@ impl GradientKind {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
let (shape, position, angle, moz_position) = match *compat_mode {
|
||||
CompatMode::Modern => {
|
||||
let shape = input.r#try(|i| EndingShape::parse(context, i, *compat_mode));
|
||||
let position = input.r#try(|i| {
|
||||
let shape = input.try(|i| EndingShape::parse(context, i, *compat_mode));
|
||||
let position = input.try(|i| {
|
||||
i.expect_ident_matching("at")?;
|
||||
Position::parse(context, i)
|
||||
});
|
||||
(shape, position.ok(), None, None)
|
||||
},
|
||||
CompatMode::WebKit => {
|
||||
let position = input.r#try(|i| Position::parse(context, i));
|
||||
let shape = input.r#try(|i| {
|
||||
let position = input.try(|i| Position::parse(context, i));
|
||||
let shape = input.try(|i| {
|
||||
if position.is_ok() {
|
||||
i.expect_comma()?;
|
||||
}
|
||||
|
@ -620,13 +620,13 @@ impl GradientKind {
|
|||
// cover | contain
|
||||
// and <color-stop> = <color> [ <percentage> | <length> ]?
|
||||
CompatMode::Moz => {
|
||||
let mut position = input.r#try(|i| LegacyPosition::parse(context, i));
|
||||
let angle = input.r#try(|i| Angle::parse(context, i)).ok();
|
||||
let mut position = input.try(|i| LegacyPosition::parse(context, i));
|
||||
let angle = input.try(|i| Angle::parse(context, i)).ok();
|
||||
if position.is_err() {
|
||||
position = input.r#try(|i| LegacyPosition::parse(context, i));
|
||||
position = input.try(|i| LegacyPosition::parse(context, i));
|
||||
}
|
||||
|
||||
let shape = input.r#try(|i| {
|
||||
let shape = input.try(|i| {
|
||||
if position.is_ok() || angle.is_some() {
|
||||
i.expect_comma()?;
|
||||
}
|
||||
|
@ -768,18 +768,18 @@ impl LineDirection {
|
|||
compat_mode: &mut CompatMode,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut _angle = if *compat_mode == CompatMode::Moz {
|
||||
input.r#try(|i| Angle::parse(context, i)).ok()
|
||||
input.try(|i| Angle::parse(context, i)).ok()
|
||||
} else {
|
||||
// Gradients allow unitless zero angles as an exception, see:
|
||||
// https://github.com/w3c/csswg-drafts/issues/1162
|
||||
if let Ok(angle) = input.r#try(|i| Angle::parse_with_unitless(context, i)) {
|
||||
if let Ok(angle) = input.try(|i| Angle::parse_with_unitless(context, i)) {
|
||||
return Ok(LineDirection::Angle(angle));
|
||||
}
|
||||
None
|
||||
};
|
||||
|
||||
input.r#try(|i| {
|
||||
let to_ident = i.r#try(|i| i.expect_ident_matching("to"));
|
||||
input.try(|i| {
|
||||
let to_ident = i.try(|i| i.expect_ident_matching("to"));
|
||||
match *compat_mode {
|
||||
// `to` keyword is mandatory in modern syntax.
|
||||
CompatMode::Modern => to_ident?,
|
||||
|
@ -801,9 +801,9 @@ impl LineDirection {
|
|||
{
|
||||
// `-moz-` prefixed linear gradient can be both Angle and Position.
|
||||
if *compat_mode == CompatMode::Moz {
|
||||
let position = i.r#try(|i| LegacyPosition::parse(context, i)).ok();
|
||||
let position = i.try(|i| LegacyPosition::parse(context, i)).ok();
|
||||
if _angle.is_none() {
|
||||
_angle = i.r#try(|i| Angle::parse(context, i)).ok();
|
||||
_angle = i.try(|i| Angle::parse(context, i)).ok();
|
||||
};
|
||||
|
||||
if _angle.is_none() && position.is_none() {
|
||||
|
@ -813,14 +813,14 @@ impl LineDirection {
|
|||
}
|
||||
}
|
||||
|
||||
if let Ok(x) = i.r#try(X::parse) {
|
||||
if let Ok(y) = i.r#try(Y::parse) {
|
||||
if let Ok(x) = i.try(X::parse) {
|
||||
if let Ok(y) = i.try(Y::parse) {
|
||||
return Ok(LineDirection::Corner(x, y));
|
||||
}
|
||||
return Ok(LineDirection::Horizontal(x));
|
||||
}
|
||||
let y = Y::parse(i)?;
|
||||
if let Ok(x) = i.r#try(X::parse) {
|
||||
if let Ok(x) = i.try(X::parse) {
|
||||
return Ok(LineDirection::Corner(x, y));
|
||||
}
|
||||
Ok(LineDirection::Vertical(y))
|
||||
|
@ -850,20 +850,19 @@ impl EndingShape {
|
|||
input: &mut Parser<'i, 't>,
|
||||
compat_mode: CompatMode,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(extent) = input.r#try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) {
|
||||
if input.r#try(|i| i.expect_ident_matching("circle")).is_ok() {
|
||||
if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) {
|
||||
if input.try(|i| i.expect_ident_matching("circle")).is_ok() {
|
||||
return Ok(generic::EndingShape::Circle(Circle::Extent(extent)));
|
||||
}
|
||||
let _ = input.r#try(|i| i.expect_ident_matching("ellipse"));
|
||||
let _ = input.try(|i| i.expect_ident_matching("ellipse"));
|
||||
return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent)));
|
||||
}
|
||||
if input.r#try(|i| i.expect_ident_matching("circle")).is_ok() {
|
||||
if let Ok(extent) = input.r#try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode))
|
||||
{
|
||||
if input.try(|i| i.expect_ident_matching("circle")).is_ok() {
|
||||
if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) {
|
||||
return Ok(generic::EndingShape::Circle(Circle::Extent(extent)));
|
||||
}
|
||||
if compat_mode == CompatMode::Modern {
|
||||
if let Ok(length) = input.r#try(|i| Length::parse(context, i)) {
|
||||
if let Ok(length) = input.try(|i| Length::parse(context, i)) {
|
||||
return Ok(generic::EndingShape::Circle(Circle::Radius(length)));
|
||||
}
|
||||
}
|
||||
|
@ -871,13 +870,12 @@ impl EndingShape {
|
|||
ShapeExtent::FarthestCorner,
|
||||
)));
|
||||
}
|
||||
if input.r#try(|i| i.expect_ident_matching("ellipse")).is_ok() {
|
||||
if let Ok(extent) = input.r#try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode))
|
||||
{
|
||||
if input.try(|i| i.expect_ident_matching("ellipse")).is_ok() {
|
||||
if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) {
|
||||
return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent)));
|
||||
}
|
||||
if compat_mode == CompatMode::Modern {
|
||||
let pair: Result<_, ParseError> = input.r#try(|i| {
|
||||
let pair: Result<_, ParseError> = input.try(|i| {
|
||||
let x = LengthOrPercentage::parse(context, i)?;
|
||||
let y = LengthOrPercentage::parse(context, i)?;
|
||||
Ok((x, y))
|
||||
|
@ -893,10 +891,10 @@ impl EndingShape {
|
|||
// -moz- prefixed radial gradient doesn't allow EndingShape's Length or LengthOrPercentage
|
||||
// to come before shape keyword. Otherwise it conflicts with <position>.
|
||||
if compat_mode != CompatMode::Moz {
|
||||
if let Ok(length) = input.r#try(|i| Length::parse(context, i)) {
|
||||
if let Ok(y) = input.r#try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(length) = input.try(|i| Length::parse(context, i)) {
|
||||
if let Ok(y) = input.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if compat_mode == CompatMode::Modern {
|
||||
let _ = input.r#try(|i| i.expect_ident_matching("ellipse"));
|
||||
let _ = input.try(|i| i.expect_ident_matching("ellipse"));
|
||||
}
|
||||
return Ok(generic::EndingShape::Ellipse(Ellipse::Radii(
|
||||
length.into(),
|
||||
|
@ -904,7 +902,7 @@ impl EndingShape {
|
|||
)));
|
||||
}
|
||||
if compat_mode == CompatMode::Modern {
|
||||
let y = input.r#try(|i| {
|
||||
let y = input.try(|i| {
|
||||
i.expect_ident_matching("ellipse")?;
|
||||
LengthOrPercentage::parse(context, i)
|
||||
});
|
||||
|
@ -914,17 +912,17 @@ impl EndingShape {
|
|||
y,
|
||||
)));
|
||||
}
|
||||
let _ = input.r#try(|i| i.expect_ident_matching("circle"));
|
||||
let _ = input.try(|i| i.expect_ident_matching("circle"));
|
||||
}
|
||||
|
||||
return Ok(generic::EndingShape::Circle(Circle::Radius(length)));
|
||||
}
|
||||
}
|
||||
input.r#try(|i| {
|
||||
input.try(|i| {
|
||||
let x = Percentage::parse(context, i)?;
|
||||
let y = if let Ok(y) = i.r#try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
let y = if let Ok(y) = i.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if compat_mode == CompatMode::Modern {
|
||||
let _ = i.r#try(|i| i.expect_ident_matching("ellipse"));
|
||||
let _ = i.try(|i| i.expect_ident_matching("ellipse"));
|
||||
}
|
||||
y
|
||||
} else {
|
||||
|
@ -965,7 +963,7 @@ impl GradientItem {
|
|||
loop {
|
||||
input.parse_until_before(Delimiter::Comma, |input| {
|
||||
if seen_stop {
|
||||
if let Ok(hint) = input.r#try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(hint) = input.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
seen_stop = false;
|
||||
items.push(generic::GradientItem::InterpolationHint(hint));
|
||||
return Ok(());
|
||||
|
@ -974,7 +972,7 @@ impl GradientItem {
|
|||
|
||||
let stop = ColorStop::parse(context, input)?;
|
||||
|
||||
if let Ok(multi_position) = input.r#try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
if let Ok(multi_position) = input.try(|i| LengthOrPercentage::parse(context, i)) {
|
||||
let stop_color = stop.color.clone();
|
||||
items.push(generic::GradientItem::ColorStop(stop));
|
||||
items.push(generic::GradientItem::ColorStop(ColorStop {
|
||||
|
@ -1010,7 +1008,7 @@ impl Parse for ColorStop {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(ColorStop {
|
||||
color: Color::parse(context, input)?,
|
||||
position: input.r#try(|i| LengthOrPercentage::parse(context, i)).ok(),
|
||||
position: input.try(|i| LengthOrPercentage::parse(context, i)).ok(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1024,7 +1022,7 @@ impl Parse for PaintWorklet {
|
|||
input.parse_nested_block(|input| {
|
||||
let name = Atom::from(&**input.expect_ident()?);
|
||||
let arguments = input
|
||||
.r#try(|input| {
|
||||
.try(|input| {
|
||||
input.expect_comma()?;
|
||||
input.parse_comma_separated(|input| SpecifiedValue::parse(input))
|
||||
})
|
||||
|
@ -1039,7 +1037,7 @@ impl Parse for MozImageRect {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input.r#try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
||||
input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
||||
input.parse_nested_block(|i| {
|
||||
let string = i.expect_url_or_string()?;
|
||||
let url = SpecifiedImageUrl::parse_from_string(string.as_ref().to_owned(), context);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue