mirror of
https://github.com/servo/servo.git
synced 2025-08-09 23:45:35 +01:00
style: Switch all callsites of try() to try_parse() in the style crate.
Fully automated via: $ rg -l '\.try\(' | xargs sed -i 's/\.try(/.try_parse(/g' $ cd servo/components/style && cargo +nightly fmt Differential Revision: https://phabricator.services.mozilla.com/D80099
This commit is contained in:
parent
5af0d7ca7c
commit
685e749cfc
56 changed files with 469 additions and 403 deletions
|
@ -194,25 +194,28 @@ impl ContentDistribution {
|
|||
// when this function is updated.
|
||||
|
||||
// Try to parse normal first
|
||||
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(ContentDistribution::normal());
|
||||
}
|
||||
|
||||
// Parse <baseline-position>, but only on the block axis.
|
||||
if axis == AxisDirection::Block {
|
||||
if let Ok(value) = input.try(parse_baseline) {
|
||||
if let Ok(value) = input.try_parse(parse_baseline) {
|
||||
return Ok(ContentDistribution::new(value));
|
||||
}
|
||||
}
|
||||
|
||||
// <content-distribution>
|
||||
if let Ok(value) = input.try(parse_content_distribution) {
|
||||
if let Ok(value) = input.try_parse(parse_content_distribution) {
|
||||
return Ok(ContentDistribution::new(value));
|
||||
}
|
||||
|
||||
// <overflow-position>? <content-position>
|
||||
let overflow_position = input
|
||||
.try(parse_overflow_position)
|
||||
.try_parse(parse_overflow_position)
|
||||
.unwrap_or(AlignFlags::empty());
|
||||
|
||||
let content_position = try_match_ident_ignore_ascii_case! { input,
|
||||
|
@ -426,18 +429,18 @@ impl SelfAlignment {
|
|||
//
|
||||
// It's weird that this accepts <baseline-position>, but not
|
||||
// justify-content...
|
||||
if let Ok(value) = input.try(parse_baseline) {
|
||||
if let Ok(value) = input.try_parse(parse_baseline) {
|
||||
return Ok(SelfAlignment(value));
|
||||
}
|
||||
|
||||
// auto | normal | stretch
|
||||
if let Ok(value) = input.try(parse_auto_normal_stretch) {
|
||||
if let Ok(value) = input.try_parse(parse_auto_normal_stretch) {
|
||||
return Ok(SelfAlignment(value));
|
||||
}
|
||||
|
||||
// <overflow-position>? <self-position>
|
||||
let overflow_position = input
|
||||
.try(parse_overflow_position)
|
||||
.try_parse(parse_overflow_position)
|
||||
.unwrap_or(AlignFlags::empty());
|
||||
let self_position = parse_self_position(input, axis)?;
|
||||
Ok(SelfAlignment(overflow_position | self_position))
|
||||
|
@ -564,17 +567,17 @@ impl Parse for AlignItems {
|
|||
// this function is updated.
|
||||
|
||||
// <baseline-position>
|
||||
if let Ok(baseline) = input.try(parse_baseline) {
|
||||
if let Ok(baseline) = input.try_parse(parse_baseline) {
|
||||
return Ok(AlignItems(baseline));
|
||||
}
|
||||
|
||||
// normal | stretch
|
||||
if let Ok(value) = input.try(parse_normal_stretch) {
|
||||
if let Ok(value) = input.try_parse(parse_normal_stretch) {
|
||||
return Ok(AlignItems(value));
|
||||
}
|
||||
// <overflow-position>? <self-position>
|
||||
let overflow = input
|
||||
.try(parse_overflow_position)
|
||||
.try_parse(parse_overflow_position)
|
||||
.unwrap_or(AlignFlags::empty());
|
||||
let self_position = parse_self_position(input, AxisDirection::Block)?;
|
||||
Ok(AlignItems(self_position | overflow))
|
||||
|
@ -623,23 +626,23 @@ impl Parse for JustifyItems {
|
|||
//
|
||||
// It's weird that this accepts <baseline-position>, but not
|
||||
// justify-content...
|
||||
if let Ok(baseline) = input.try(parse_baseline) {
|
||||
if let Ok(baseline) = input.try_parse(parse_baseline) {
|
||||
return Ok(JustifyItems(baseline));
|
||||
}
|
||||
|
||||
// normal | stretch
|
||||
if let Ok(value) = input.try(parse_normal_stretch) {
|
||||
if let Ok(value) = input.try_parse(parse_normal_stretch) {
|
||||
return Ok(JustifyItems(value));
|
||||
}
|
||||
|
||||
// legacy | [ legacy && [ left | right | center ] ]
|
||||
if let Ok(value) = input.try(parse_legacy) {
|
||||
if let Ok(value) = input.try_parse(parse_legacy) {
|
||||
return Ok(JustifyItems(value));
|
||||
}
|
||||
|
||||
// <overflow-position>? <self-position>
|
||||
let overflow = input
|
||||
.try(parse_overflow_position)
|
||||
.try_parse(parse_overflow_position)
|
||||
.unwrap_or(AlignFlags::empty());
|
||||
let self_position = parse_self_position(input, AxisDirection::Inline)?;
|
||||
Ok(JustifyItems(overflow | self_position))
|
||||
|
@ -795,7 +798,7 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result<AlignFlags, ParseE
|
|||
// when this function is updated.
|
||||
let flags = try_match_ident_ignore_ascii_case! { input,
|
||||
"legacy" => {
|
||||
let flags = input.try(parse_left_right_center)
|
||||
let flags = input.try_parse(parse_left_right_center)
|
||||
.unwrap_or(AlignFlags::empty());
|
||||
|
||||
return Ok(AlignFlags::LEGACY | flags)
|
||||
|
|
|
@ -22,9 +22,10 @@ impl Parse for BackgroundSize {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(width) = input.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) {
|
||||
if let Ok(width) = input.try_parse(|i| NonNegativeLengthPercentageOrAuto::parse(context, i))
|
||||
{
|
||||
let height = input
|
||||
.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i))
|
||||
.try_parse(|i| NonNegativeLengthPercentageOrAuto::parse(context, i))
|
||||
.unwrap_or(NonNegativeLengthPercentageOrAuto::auto());
|
||||
return Ok(GenericBackgroundSize::ExplicitSize { width, height });
|
||||
}
|
||||
|
@ -136,7 +137,7 @@ impl Parse for BackgroundRepeat {
|
|||
},
|
||||
};
|
||||
|
||||
let vertical = input.try(BackgroundRepeatKeyword::parse).ok();
|
||||
let vertical = input.try_parse(BackgroundRepeatKeyword::parse).ok();
|
||||
Ok(BackgroundRepeat(horizontal, vertical.unwrap_or(horizontal)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ where
|
|||
return false; // already parsed this component
|
||||
}
|
||||
|
||||
*component = input.try(|i| U::parse(context, i)).ok();
|
||||
*component = input.try_parse(|i| U::parse(context, i)).ok();
|
||||
component.is_some()
|
||||
}
|
||||
|
||||
|
@ -112,17 +112,17 @@ impl Parse for ClipPath {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(ClipPath::None);
|
||||
}
|
||||
|
||||
if is_clip_path_path_enabled(context) {
|
||||
if let Ok(p) = input.try(|i| Path::parse(context, i)) {
|
||||
if let Ok(p) = input.try_parse(|i| Path::parse(context, i)) {
|
||||
return Ok(ClipPath::Path(p));
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
|
||||
if let Ok(url) = input.try_parse(|i| SpecifiedUrl::parse(context, i)) {
|
||||
return Ok(ClipPath::Url(url));
|
||||
}
|
||||
|
||||
|
@ -138,11 +138,11 @@ impl Parse for ShapeOutside {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
// Need to parse this here so that `Image::parse_with_cors_anonymous`
|
||||
// doesn't parse it.
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(ShapeOutside::None);
|
||||
}
|
||||
|
||||
if let Ok(image) = input.try(|i| Image::parse_with_cors_anonymous(context, i)) {
|
||||
if let Ok(image) = input.try_parse(|i| Image::parse_with_cors_anonymous(context, i)) {
|
||||
debug_assert_ne!(image, Image::None);
|
||||
return Ok(ShapeOutside::Image(image));
|
||||
}
|
||||
|
@ -189,7 +189,10 @@ impl InsetRect {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let rect = Rect::parse_with(context, input, LengthPercentage::parse)?;
|
||||
let round = if input.try(|i| i.expect_ident_matching("round")).is_ok() {
|
||||
let round = if input
|
||||
.try_parse(|i| i.expect_ident_matching("round"))
|
||||
.is_ok()
|
||||
{
|
||||
BorderRadius::parse(context, input)?
|
||||
} else {
|
||||
BorderRadius::zero()
|
||||
|
@ -214,9 +217,9 @@ impl Circle {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let radius = input
|
||||
.try(|i| ShapeRadius::parse(context, i))
|
||||
.try_parse(|i| ShapeRadius::parse(context, i))
|
||||
.unwrap_or_default();
|
||||
let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() {
|
||||
let position = if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() {
|
||||
Position::parse(context, input)?
|
||||
} else {
|
||||
Position::center()
|
||||
|
@ -242,14 +245,14 @@ impl Ellipse {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let (a, b) = input
|
||||
.try(|i| -> Result<_, ParseError> {
|
||||
.try_parse(|i| -> Result<_, ParseError> {
|
||||
Ok((
|
||||
ShapeRadius::parse(context, i)?,
|
||||
ShapeRadius::parse(context, i)?,
|
||||
))
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() {
|
||||
let position = if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() {
|
||||
Position::parse(context, input)?
|
||||
} else {
|
||||
Position::center()
|
||||
|
@ -280,7 +283,7 @@ impl Polygon {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let fill = input
|
||||
.try(|i| -> Result<_, ParseError> {
|
||||
.try_parse(|i| -> Result<_, ParseError> {
|
||||
let fill = FillRule::parse(i)?;
|
||||
i.expect_comma()?; // only eat the comma if there is something before it
|
||||
Ok(fill)
|
||||
|
@ -317,7 +320,7 @@ impl Path {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let fill = input
|
||||
.try(|i| -> Result<_, ParseError> {
|
||||
.try_parse(|i| -> Result<_, ParseError> {
|
||||
let fill = FillRule::parse(i)?;
|
||||
i.expect_comma()?;
|
||||
Ok(fill)
|
||||
|
|
|
@ -121,7 +121,8 @@ impl BorderSideWidth {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(length) = input.try(|i| NonNegativeLength::parse_quirky(context, i, allow_quirks))
|
||||
if let Ok(length) =
|
||||
input.try_parse(|i| NonNegativeLength::parse_quirky(context, i, allow_quirks))
|
||||
{
|
||||
return Ok(BorderSideWidth::Length(length));
|
||||
}
|
||||
|
@ -178,10 +179,10 @@ impl Parse for BorderImageSlice {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut fill = input.try(|i| i.expect_ident_matching("fill")).is_ok();
|
||||
let mut fill = input.try_parse(|i| i.expect_ident_matching("fill")).is_ok();
|
||||
let offsets = Rect::parse_with(context, input, NonNegativeNumberOrPercentage::parse)?;
|
||||
if !fill {
|
||||
fill = input.try(|i| i.expect_ident_matching("fill")).is_ok();
|
||||
fill = input.try_parse(|i| i.expect_ident_matching("fill")).is_ok();
|
||||
}
|
||||
Ok(GenericBorderImageSlice { offsets, fill })
|
||||
}
|
||||
|
@ -193,7 +194,7 @@ impl Parse for BorderRadius {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let widths = Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?;
|
||||
let heights = if input.try(|i| i.expect_delim('/')).is_ok() {
|
||||
let heights = if input.try_parse(|i| i.expect_delim('/')).is_ok() {
|
||||
Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?
|
||||
} else {
|
||||
widths.clone()
|
||||
|
@ -301,7 +302,7 @@ impl Parse for BorderImageRepeat {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let horizontal = BorderImageRepeatKeyword::parse(input)?;
|
||||
let vertical = input.try(BorderImageRepeatKeyword::parse).ok();
|
||||
let vertical = input.try_parse(BorderImageRepeatKeyword::parse).ok();
|
||||
Ok(BorderImageRepeat(
|
||||
horizontal,
|
||||
vertical.unwrap_or(horizontal),
|
||||
|
|
|
@ -530,30 +530,30 @@ impl Parse for Display {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Display, ParseError<'i>> {
|
||||
// Parse all combinations of <display-inside/outside>? and `list-item`? first.
|
||||
let mut got_list_item = input.try(parse_list_item).is_ok();
|
||||
let mut got_list_item = input.try_parse(parse_list_item).is_ok();
|
||||
let mut inside = if got_list_item {
|
||||
input.try(parse_display_inside_for_list_item)
|
||||
input.try_parse(parse_display_inside_for_list_item)
|
||||
} else {
|
||||
input.try(parse_display_inside)
|
||||
input.try_parse(parse_display_inside)
|
||||
};
|
||||
// <display-listitem> = <display-outside>? && [ flow | flow-root ]? && list-item
|
||||
// https://drafts.csswg.org/css-display/#typedef-display-listitem
|
||||
if !got_list_item && is_valid_inside_for_list_item(&inside) {
|
||||
got_list_item = input.try(parse_list_item).is_ok();
|
||||
got_list_item = input.try_parse(parse_list_item).is_ok();
|
||||
}
|
||||
let outside = input.try(parse_display_outside);
|
||||
let outside = input.try_parse(parse_display_outside);
|
||||
if outside.is_ok() {
|
||||
if !got_list_item && (inside.is_err() || is_valid_inside_for_list_item(&inside)) {
|
||||
got_list_item = input.try(parse_list_item).is_ok();
|
||||
got_list_item = input.try_parse(parse_list_item).is_ok();
|
||||
}
|
||||
if inside.is_err() {
|
||||
inside = if got_list_item {
|
||||
input.try(parse_display_inside_for_list_item)
|
||||
input.try_parse(parse_display_inside_for_list_item)
|
||||
} else {
|
||||
input.try(parse_display_inside)
|
||||
input.try_parse(parse_display_inside)
|
||||
};
|
||||
if !got_list_item && is_valid_inside_for_list_item(&inside) {
|
||||
got_list_item = input.try(parse_list_item).is_ok();
|
||||
got_list_item = input.try_parse(parse_list_item).is_ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -677,7 +677,8 @@ impl Parse for VerticalAlign {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes))
|
||||
if let Ok(lp) =
|
||||
input.try_parse(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes))
|
||||
{
|
||||
return Ok(GenericVerticalAlign::Length(lp));
|
||||
}
|
||||
|
@ -697,7 +698,7 @@ impl Parse for AnimationIterationCount {
|
|||
input: &mut ::cssparser::Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("infinite"))
|
||||
.try_parse(|input| input.expect_ident_matching("infinite"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(GenericAnimationIterationCount::Infinite);
|
||||
|
@ -761,7 +762,7 @@ impl Parse for AnimationName {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) {
|
||||
if let Ok(name) = input.try_parse(|input| KeyframesName::parse(context, input)) {
|
||||
return Ok(AnimationName(Some(name)));
|
||||
}
|
||||
|
||||
|
@ -860,7 +861,7 @@ impl Parse for ScrollSnapType {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("none"))
|
||||
.try_parse(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(ScrollSnapType::none());
|
||||
|
@ -868,7 +869,7 @@ impl Parse for ScrollSnapType {
|
|||
|
||||
let axis = ScrollSnapAxis::parse(input)?;
|
||||
let strictness = input
|
||||
.try(ScrollSnapStrictness::parse)
|
||||
.try_parse(ScrollSnapStrictness::parse)
|
||||
.unwrap_or(ScrollSnapStrictness::Proximity);
|
||||
Ok(Self { axis, strictness })
|
||||
}
|
||||
|
@ -955,7 +956,9 @@ impl Parse for ScrollSnapAlign {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<ScrollSnapAlign, ParseError<'i>> {
|
||||
let block = ScrollSnapAlignKeyword::parse(input)?;
|
||||
let inline = input.try(ScrollSnapAlignKeyword::parse).unwrap_or(block);
|
||||
let inline = input
|
||||
.try_parse(ScrollSnapAlignKeyword::parse)
|
||||
.unwrap_or(block);
|
||||
Ok(ScrollSnapAlign { block, inline })
|
||||
}
|
||||
}
|
||||
|
@ -1150,7 +1153,7 @@ impl Parse for WillChange {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("auto"))
|
||||
.try_parse(|input| input.expect_ident_matching("auto"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(Self::default());
|
||||
|
@ -1238,14 +1241,14 @@ impl Parse for TouchAction {
|
|||
"none" => Ok(TouchAction::NONE),
|
||||
"manipulation" => Ok(TouchAction::MANIPULATION),
|
||||
"pan-x" => {
|
||||
if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("pan-y")).is_ok() {
|
||||
Ok(TouchAction::PAN_X | TouchAction::PAN_Y)
|
||||
} else {
|
||||
Ok(TouchAction::PAN_X)
|
||||
}
|
||||
},
|
||||
"pan-y" => {
|
||||
if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("pan-x")).is_ok() {
|
||||
Ok(TouchAction::PAN_X | TouchAction::PAN_Y)
|
||||
} else {
|
||||
Ok(TouchAction::PAN_Y)
|
||||
|
@ -1323,7 +1326,7 @@ impl Parse for Contain {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Contain, ParseError<'i>> {
|
||||
let mut result = Contain::empty();
|
||||
while let Ok(name) = input.try(|i| i.expect_ident_cloned()) {
|
||||
while let Ok(name) = input.try_parse(|i| i.expect_ident_cloned()) {
|
||||
let flag = match_ignore_ascii_case! { &name,
|
||||
"size" => Some(Contain::SIZE),
|
||||
"layout" => Some(Contain::LAYOUT),
|
||||
|
|
|
@ -356,7 +356,7 @@ impl Parse for Color {
|
|||
input.reset(&start);
|
||||
|
||||
let compontent_parser = ColorComponentParser(&*context);
|
||||
match input.try(|i| CSSParserColor::parse_with(&compontent_parser, i)) {
|
||||
match input.try_parse(|i| CSSParserColor::parse_with(&compontent_parser, i)) {
|
||||
Ok(value) => Ok(match value {
|
||||
CSSParserColor::CurrentColor => Color::CurrentColor,
|
||||
CSSParserColor::RGBA(rgba) => Color::Numeric {
|
||||
|
@ -367,7 +367,7 @@ impl Parse for Color {
|
|||
Err(e) => {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(system) = input.try(|i| SystemColor::parse(context, i)) {
|
||||
if let Ok(system) = input.try_parse(|i| SystemColor::parse(context, i)) {
|
||||
return Ok(Color::System(system));
|
||||
}
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ impl Color {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input.try(|i| Self::parse(context, i)).or_else(|e| {
|
||||
input.try_parse(|i| Self::parse(context, i)).or_else(|e| {
|
||||
if !allow_quirks.allowed(context.quirks_mode) {
|
||||
return Err(e);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ fn parse_counters<'i, 't>(
|
|||
default_value: i32,
|
||||
) -> Result<Vec<CounterPair<Integer>>, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("none"))
|
||||
.try_parse(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(vec![]);
|
||||
|
@ -69,7 +69,7 @@ fn parse_counters<'i, 't>(
|
|||
};
|
||||
|
||||
let value = input
|
||||
.try(|input| Integer::parse(context, input))
|
||||
.try_parse(|input| Integer::parse(context, input))
|
||||
.unwrap_or(Integer::new(default_value));
|
||||
counters.push(CounterPair { name, value });
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ impl Content {
|
|||
#[cfg(feature = "servo")]
|
||||
fn parse_counter_style(_: &ParserContext, input: &mut Parser) -> ListStyleType {
|
||||
input
|
||||
.try(|input| {
|
||||
.try_parse(|input| {
|
||||
input.expect_comma()?;
|
||||
ListStyleType::parse(input)
|
||||
})
|
||||
|
@ -101,7 +101,7 @@ impl Content {
|
|||
#[cfg(feature = "gecko")]
|
||||
fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyle {
|
||||
input
|
||||
.try(|input| {
|
||||
.try_parse(|input| {
|
||||
input.expect_comma()?;
|
||||
CounterStyle::parse(context, input)
|
||||
})
|
||||
|
@ -119,13 +119,13 @@ impl Parse for Content {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("normal"))
|
||||
.try_parse(|input| input.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(generics::Content::Normal);
|
||||
}
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("none"))
|
||||
.try_parse(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(generics::Content::None);
|
||||
|
@ -136,7 +136,7 @@ impl Parse for Content {
|
|||
loop {
|
||||
#[cfg(any(feature = "gecko", feature = "servo-layout-2020"))]
|
||||
{
|
||||
if let Ok(url) = input.try(|i| SpecifiedImageUrl::parse(context, i)) {
|
||||
if let Ok(url) = input.try_parse(|i| SpecifiedImageUrl::parse(context, i)) {
|
||||
content.push(generics::ContentItem::Url(url));
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -21,10 +21,10 @@ impl Parse for TimingFunction {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(keyword) = input.try(TimingKeyword::parse) {
|
||||
if let Ok(keyword) = input.try_parse(TimingKeyword::parse) {
|
||||
return Ok(GenericTimingFunction::Keyword(keyword));
|
||||
}
|
||||
if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) {
|
||||
if let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) {
|
||||
let position = match_ignore_ascii_case! { &ident,
|
||||
"step-start" => StepPosition::Start,
|
||||
"step-end" => StepPosition::End,
|
||||
|
@ -57,7 +57,7 @@ impl Parse for TimingFunction {
|
|||
},
|
||||
"steps" => {
|
||||
let steps = Integer::parse_positive(context, i)?;
|
||||
let position = i.try(|i| {
|
||||
let position = i.try_parse(|i| {
|
||||
i.expect_comma()?;
|
||||
StepPosition::parse(context, i)
|
||||
}).unwrap_or(StepPosition::End);
|
||||
|
|
|
@ -141,7 +141,7 @@ impl Parse for BoxShadow {
|
|||
loop {
|
||||
if !inset {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("inset"))
|
||||
.try_parse(|input| input.expect_ident_matching("inset"))
|
||||
.is_ok()
|
||||
{
|
||||
inset = true;
|
||||
|
@ -156,7 +156,7 @@ impl Parse for BoxShadow {
|
|||
.try::<_, _, ParseError>(|i| Length::parse_non_negative(context, i))
|
||||
{
|
||||
Ok(blur) => {
|
||||
let spread = i.try(|i| Length::parse(context, i)).ok();
|
||||
let spread = i.try_parse(|i| Length::parse(context, i)).ok();
|
||||
(Some(blur.into()), spread)
|
||||
},
|
||||
Err(_) => (None, None),
|
||||
|
@ -169,7 +169,7 @@ impl Parse for BoxShadow {
|
|||
}
|
||||
}
|
||||
if color.is_none() {
|
||||
if let Ok(value) = input.try(|i| Color::parse(context, i)) {
|
||||
if let Ok(value) = input.try_parse(|i| Color::parse(context, i)) {
|
||||
color = Some(value);
|
||||
continue;
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ impl Parse for Filter {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) {
|
||||
if let Ok(url) = input.try_parse(|i| SpecifiedUrl::parse(context, i)) {
|
||||
return Ok(GenericFilter::Url(url));
|
||||
}
|
||||
}
|
||||
|
@ -242,22 +242,22 @@ impl Parse for Filter {
|
|||
input.parse_nested_block(|i| {
|
||||
match_ignore_ascii_case! { &*function,
|
||||
"blur" => Ok(GenericFilter::Blur(
|
||||
i.try(|i| NonNegativeLength::parse(context, i))
|
||||
i.try_parse(|i| NonNegativeLength::parse(context, i))
|
||||
.unwrap_or(Zero::zero()),
|
||||
)),
|
||||
"brightness" => Ok(GenericFilter::Brightness(
|
||||
i.try(|i| NonNegativeFactor::parse(context, i))
|
||||
i.try_parse(|i| NonNegativeFactor::parse(context, i))
|
||||
.unwrap_or(NonNegativeFactor::one()),
|
||||
)),
|
||||
"contrast" => Ok(GenericFilter::Contrast(
|
||||
i.try(|i| NonNegativeFactor::parse(context, i))
|
||||
i.try_parse(|i| NonNegativeFactor::parse(context, i))
|
||||
.unwrap_or(NonNegativeFactor::one()),
|
||||
)),
|
||||
"grayscale" => {
|
||||
// Values of amount over 100% are allowed but UAs must clamp the values to 1.
|
||||
// https://drafts.fxtf.org/filter-effects/#funcdef-filter-grayscale
|
||||
Ok(GenericFilter::Grayscale(
|
||||
i.try(|i| ZeroToOneFactor::parse(context, i))
|
||||
i.try_parse(|i| ZeroToOneFactor::parse(context, i))
|
||||
.unwrap_or(ZeroToOneFactor::one()),
|
||||
))
|
||||
},
|
||||
|
@ -265,7 +265,7 @@ impl Parse for Filter {
|
|||
// We allow unitless zero here, see:
|
||||
// https://github.com/w3c/fxtf-drafts/issues/228
|
||||
Ok(GenericFilter::HueRotate(
|
||||
i.try(|i| Angle::parse_with_unitless(context, i))
|
||||
i.try_parse(|i| Angle::parse_with_unitless(context, i))
|
||||
.unwrap_or(Zero::zero()),
|
||||
))
|
||||
},
|
||||
|
@ -273,7 +273,7 @@ impl Parse for Filter {
|
|||
// Values of amount over 100% are allowed but UAs must clamp the values to 1.
|
||||
// https://drafts.fxtf.org/filter-effects/#funcdef-filter-invert
|
||||
Ok(GenericFilter::Invert(
|
||||
i.try(|i| ZeroToOneFactor::parse(context, i))
|
||||
i.try_parse(|i| ZeroToOneFactor::parse(context, i))
|
||||
.unwrap_or(ZeroToOneFactor::one()),
|
||||
))
|
||||
},
|
||||
|
@ -281,19 +281,19 @@ impl Parse for Filter {
|
|||
// Values of amount over 100% are allowed but UAs must clamp the values to 1.
|
||||
// https://drafts.fxtf.org/filter-effects/#funcdef-filter-opacity
|
||||
Ok(GenericFilter::Opacity(
|
||||
i.try(|i| ZeroToOneFactor::parse(context, i))
|
||||
i.try_parse(|i| ZeroToOneFactor::parse(context, i))
|
||||
.unwrap_or(ZeroToOneFactor::one()),
|
||||
))
|
||||
},
|
||||
"saturate" => Ok(GenericFilter::Saturate(
|
||||
i.try(|i| NonNegativeFactor::parse(context, i))
|
||||
i.try_parse(|i| NonNegativeFactor::parse(context, i))
|
||||
.unwrap_or(NonNegativeFactor::one()),
|
||||
)),
|
||||
"sepia" => {
|
||||
// Values of amount over 100% are allowed but UAs must clamp the values to 1.
|
||||
// https://drafts.fxtf.org/filter-effects/#funcdef-filter-sepia
|
||||
Ok(GenericFilter::Sepia(
|
||||
i.try(|i| ZeroToOneFactor::parse(context, i))
|
||||
i.try_parse(|i| ZeroToOneFactor::parse(context, i))
|
||||
.unwrap_or(ZeroToOneFactor::one()),
|
||||
))
|
||||
},
|
||||
|
@ -312,12 +312,14 @@ impl Parse for SimpleShadow {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let color = input.try(|i| Color::parse(context, i)).ok();
|
||||
let color = input.try_parse(|i| Color::parse(context, i)).ok();
|
||||
let horizontal = Length::parse(context, input)?;
|
||||
let vertical = Length::parse(context, input)?;
|
||||
let blur = input.try(|i| Length::parse_non_negative(context, i)).ok();
|
||||
let blur = input
|
||||
.try_parse(|i| Length::parse_non_negative(context, i))
|
||||
.ok();
|
||||
let blur = blur.map(NonNegative::<Length>);
|
||||
let color = color.or_else(|| input.try(|i| Color::parse(context, i)).ok());
|
||||
let color = color.or_else(|| input.try_parse(|i| Color::parse(context, i)).ok());
|
||||
|
||||
Ok(SimpleShadow {
|
||||
color,
|
||||
|
|
|
@ -171,7 +171,7 @@ impl Parse for AbsoluteFontWeight {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(number) = input.try(|input| Number::parse(context, input)) {
|
||||
if let Ok(number) = input.try_parse(|input| Number::parse(context, input)) {
|
||||
// We could add another AllowedNumericType value, but it doesn't
|
||||
// seem worth it just for a single property with such a weird range,
|
||||
// so we do the clamping here manually.
|
||||
|
@ -223,7 +223,7 @@ impl Parse for SpecifiedFontStyle {
|
|||
"normal" => generics::FontStyle::Normal,
|
||||
"italic" => generics::FontStyle::Italic,
|
||||
"oblique" => {
|
||||
let angle = input.try(|input| Self::parse_angle(context, input))
|
||||
let angle = input.try_parse(|input| Self::parse_angle(context, input))
|
||||
.unwrap_or_else(|_| Self::default_angle());
|
||||
|
||||
generics::FontStyle::Oblique(angle)
|
||||
|
@ -453,7 +453,9 @@ impl Parse for FontStretch {
|
|||
//
|
||||
// Values less than 0% are not allowed and are treated as parse
|
||||
// errors.
|
||||
if let Ok(percentage) = input.try(|input| Percentage::parse_non_negative(context, input)) {
|
||||
if let Ok(percentage) =
|
||||
input.try_parse(|input| Percentage::parse_non_negative(context, input))
|
||||
{
|
||||
return Ok(FontStretch::Stretch(percentage));
|
||||
}
|
||||
|
||||
|
@ -996,13 +998,13 @@ impl FontSize {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<FontSize, ParseError<'i>> {
|
||||
if let Ok(lp) =
|
||||
input.try(|i| LengthPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
if let Ok(lp) = input
|
||||
.try_parse(|i| LengthPercentage::parse_non_negative_quirky(context, i, allow_quirks))
|
||||
{
|
||||
return Ok(FontSize::Length(lp));
|
||||
}
|
||||
|
||||
if let Ok(kw) = input.try(FontSizeKeyword::parse) {
|
||||
if let Ok(kw) = input.try_parse(FontSizeKeyword::parse) {
|
||||
return Ok(FontSize::Keyword(KeywordInfo::new(kw)));
|
||||
}
|
||||
|
||||
|
@ -1155,7 +1157,7 @@ impl Parse for FontVariantAlternates {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<FontVariantAlternates, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("normal"))
|
||||
.try_parse(|input| input.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(FontVariantAlternates::Value(Default::default()));
|
||||
|
@ -1171,7 +1173,7 @@ impl Parse for FontVariantAlternates {
|
|||
parsed_alternates |= $flag;
|
||||
)
|
||||
);
|
||||
while let Ok(_) = input.try(|input| match *input.next()? {
|
||||
while let Ok(_) = input.try_parse(|input| match *input.next()? {
|
||||
Token::Ident(ref value) if value.eq_ignore_ascii_case("historical-forms") => {
|
||||
check_if_parsed!(input, VariantAlternatesParsingFlags::HISTORICAL_FORMS);
|
||||
alternates.push(VariantAlternates::HistoricalForms);
|
||||
|
@ -1386,13 +1388,13 @@ impl Parse for FontVariantEastAsian {
|
|||
let mut result = VariantEastAsian::empty();
|
||||
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("normal"))
|
||||
.try_parse(|input| input.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(FontVariantEastAsian::Value(result));
|
||||
}
|
||||
|
||||
while let Ok(flag) = input.try(|input| {
|
||||
while let Ok(flag) = input.try_parse(|input| {
|
||||
Ok(
|
||||
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
|
||||
"jis78" =>
|
||||
|
@ -1610,19 +1612,19 @@ impl Parse for FontVariantLigatures {
|
|||
let mut result = VariantLigatures::empty();
|
||||
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("normal"))
|
||||
.try_parse(|input| input.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(FontVariantLigatures::Value(result));
|
||||
}
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("none"))
|
||||
.try_parse(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(FontVariantLigatures::Value(VariantLigatures::NONE));
|
||||
}
|
||||
|
||||
while let Ok(flag) = input.try(|input| {
|
||||
while let Ok(flag) = input.try_parse(|input| {
|
||||
Ok(
|
||||
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
|
||||
"common-ligatures" =>
|
||||
|
@ -1819,13 +1821,13 @@ impl Parse for FontVariantNumeric {
|
|||
let mut result = VariantNumeric::empty();
|
||||
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("normal"))
|
||||
.try_parse(|input| input.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(FontVariantNumeric::Value(result));
|
||||
}
|
||||
|
||||
while let Ok(flag) = input.try(|input| {
|
||||
while let Ok(flag) = input.try_parse(|input| {
|
||||
Ok(
|
||||
match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
|
||||
"ordinal" =>
|
||||
|
@ -1969,14 +1971,14 @@ impl Parse for FontSynthesis {
|
|||
"none" => Ok(result),
|
||||
"weight" => {
|
||||
result.weight = true;
|
||||
if input.try(|input| input.expect_ident_matching("style")).is_ok() {
|
||||
if input.try_parse(|input| input.expect_ident_matching("style")).is_ok() {
|
||||
result.style = true;
|
||||
}
|
||||
Ok(result)
|
||||
},
|
||||
"style" => {
|
||||
result.style = true;
|
||||
if input.try(|input| input.expect_ident_matching("weight")).is_ok() {
|
||||
if input.try_parse(|input| input.expect_ident_matching("weight")).is_ok() {
|
||||
result.weight = true;
|
||||
}
|
||||
Ok(result)
|
||||
|
@ -2096,7 +2098,7 @@ impl Parse for FontLanguageOverride {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<FontLanguageOverride, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("normal"))
|
||||
.try_parse(|input| input.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(FontLanguageOverride::Normal);
|
||||
|
@ -2163,7 +2165,7 @@ fn parse_one_feature_value<'i, 't>(
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Integer, ParseError<'i>> {
|
||||
if let Ok(integer) = input.try(|i| Integer::parse_non_negative(context, i)) {
|
||||
if let Ok(integer) = input.try_parse(|i| Integer::parse_non_negative(context, i)) {
|
||||
return Ok(integer);
|
||||
}
|
||||
|
||||
|
@ -2181,7 +2183,7 @@ impl Parse for FeatureTagValue<Integer> {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
let tag = FontTag::parse(context, input)?;
|
||||
let value = input
|
||||
.try(|i| parse_one_feature_value(context, i))
|
||||
.try_parse(|i| parse_one_feature_value(context, i))
|
||||
.unwrap_or_else(|_| Integer::new(1));
|
||||
|
||||
Ok(Self { tag, value })
|
||||
|
@ -2318,7 +2320,7 @@ impl Parse for MozScriptLevel {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<MozScriptLevel, ParseError<'i>> {
|
||||
// We don't bother to handle calc here.
|
||||
if let Ok(i) = input.try(|i| i.expect_integer()) {
|
||||
if let Ok(i) = input.try_parse(|i| i.expect_integer()) {
|
||||
return Ok(MozScriptLevel::Relative(i));
|
||||
}
|
||||
input.expect_ident_matching("auto")?;
|
||||
|
|
|
@ -52,11 +52,11 @@ impl Parse for TrackBreadth<LengthPercentage> {
|
|||
// NonNegativeLengthPercentage instead.
|
||||
//
|
||||
// Though it seems these cannot be animated so it's ~ok.
|
||||
if let Ok(lp) = input.try(|i| LengthPercentage::parse_non_negative(context, i)) {
|
||||
if let Ok(lp) = input.try_parse(|i| LengthPercentage::parse_non_negative(context, i)) {
|
||||
return Ok(TrackBreadth::Breadth(lp));
|
||||
}
|
||||
|
||||
if let Ok(f) = input.try(parse_flex) {
|
||||
if let Ok(f) = input.try_parse(parse_flex) {
|
||||
return Ok(TrackBreadth::Fr(f));
|
||||
}
|
||||
|
||||
|
@ -69,14 +69,17 @@ impl Parse for TrackSize<LengthPercentage> {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(b) = input.try(|i| TrackBreadth::parse(context, i)) {
|
||||
if let Ok(b) = input.try_parse(|i| TrackBreadth::parse(context, i)) {
|
||||
return Ok(TrackSize::Breadth(b));
|
||||
}
|
||||
|
||||
if input.try(|i| i.expect_function_matching("minmax")).is_ok() {
|
||||
if input
|
||||
.try_parse(|i| i.expect_function_matching("minmax"))
|
||||
.is_ok()
|
||||
{
|
||||
return input.parse_nested_block(|input| {
|
||||
let inflexible_breadth =
|
||||
match input.try(|i| LengthPercentage::parse_non_negative(context, i)) {
|
||||
match input.try_parse(|i| LengthPercentage::parse_non_negative(context, i)) {
|
||||
Ok(lp) => TrackBreadth::Breadth(lp),
|
||||
Err(..) => TrackBreadth::parse_keyword(input)?,
|
||||
};
|
||||
|
@ -119,7 +122,7 @@ pub fn parse_line_names<'i, 't>(
|
|||
input.expect_square_bracket_block()?;
|
||||
input.parse_nested_block(|input| {
|
||||
let mut values = vec![];
|
||||
while let Ok((loc, ident)) = input.try(|i| -> Result<_, CssParseError<()>> {
|
||||
while let Ok((loc, ident)) = input.try_parse(|i| -> Result<_, CssParseError<()>> {
|
||||
Ok((i.current_source_location(), i.expect_ident_cloned()?))
|
||||
}) {
|
||||
let ident = CustomIdent::from_ident(loc, &ident, &["span", "auto"])?;
|
||||
|
@ -150,7 +153,7 @@ impl TrackRepeat<LengthPercentage, Integer> {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<(Self, RepeatType), ParseError<'i>> {
|
||||
input
|
||||
.try(|i| i.expect_function_matching("repeat").map_err(|e| e.into()))
|
||||
.try_parse(|i| i.expect_function_matching("repeat").map_err(|e| e.into()))
|
||||
.and_then(|_| {
|
||||
input.parse_nested_block(|input| {
|
||||
let count = RepeatCount::parse(context, input)?;
|
||||
|
@ -169,8 +172,8 @@ impl TrackRepeat<LengthPercentage, Integer> {
|
|||
let mut current_names;
|
||||
|
||||
loop {
|
||||
current_names = input.try(parse_line_names).unwrap_or_default();
|
||||
if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) {
|
||||
current_names = input.try_parse(parse_line_names).unwrap_or_default();
|
||||
if let Ok(track_size) = input.try_parse(|i| TrackSize::parse(context, i)) {
|
||||
if !track_size.is_fixed() {
|
||||
if is_auto {
|
||||
// should be <fixed-size> for <auto-repeat>
|
||||
|
@ -224,8 +227,9 @@ impl Parse for TrackList<LengthPercentage, Integer> {
|
|||
// assume that everything is <fixed-size>. This flag is useful when we encounter <auto-repeat>
|
||||
let mut at_least_one_not_fixed = false;
|
||||
loop {
|
||||
current_names.extend_from_slice(&mut input.try(parse_line_names).unwrap_or_default());
|
||||
if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) {
|
||||
current_names
|
||||
.extend_from_slice(&mut input.try_parse(parse_line_names).unwrap_or_default());
|
||||
if let Ok(track_size) = input.try_parse(|i| TrackSize::parse(context, i)) {
|
||||
if !track_size.is_fixed() {
|
||||
at_least_one_not_fixed = true;
|
||||
if auto_repeat_index.is_some() {
|
||||
|
@ -238,7 +242,7 @@ impl Parse for TrackList<LengthPercentage, Integer> {
|
|||
names.push(vec.into());
|
||||
values.push(TrackListValue::TrackSize(track_size));
|
||||
} else if let Ok((repeat, type_)) =
|
||||
input.try(|i| TrackRepeat::parse_with_repeat_type(context, i))
|
||||
input.try_parse(|i| TrackRepeat::parse_with_repeat_type(context, i))
|
||||
{
|
||||
match type_ {
|
||||
RepeatType::Normal => {
|
||||
|
@ -312,7 +316,7 @@ impl Parse for GridTemplateComponent<LengthPercentage, Integer> {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(GridTemplateComponent::None);
|
||||
}
|
||||
|
||||
|
@ -327,12 +331,15 @@ impl GridTemplateComponent<LengthPercentage, Integer> {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if allow_grid_template_subgrids() {
|
||||
if let Ok(t) = input.try(|i| LineNameList::parse(context, i)) {
|
||||
if let Ok(t) = input.try_parse(|i| LineNameList::parse(context, i)) {
|
||||
return Ok(GridTemplateComponent::Subgrid(Box::new(t)));
|
||||
}
|
||||
}
|
||||
if allow_grid_template_masonry() {
|
||||
if input.try(|i| i.expect_ident_matching("masonry")).is_ok() {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("masonry"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(GridTemplateComponent::Masonry);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,24 +132,24 @@ impl Parse for Image {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Image, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(generic::Image::None);
|
||||
}
|
||||
if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse(context, input)) {
|
||||
if let Ok(url) = input.try_parse(|input| SpecifiedImageUrl::parse(context, input)) {
|
||||
return Ok(generic::Image::Url(url));
|
||||
}
|
||||
if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) {
|
||||
if let Ok(gradient) = input.try_parse(|i| Gradient::parse(context, i)) {
|
||||
return Ok(generic::Image::Gradient(Box::new(gradient)));
|
||||
}
|
||||
#[cfg(feature = "servo-layout-2013")]
|
||||
{
|
||||
if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) {
|
||||
if let Ok(paint_worklet) = input.try_parse(|i| PaintWorklet::parse(context, i)) {
|
||||
return Ok(generic::Image::PaintWorklet(paint_worklet));
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) {
|
||||
if let Ok(image_rect) = input.try_parse(|input| MozImageRect::parse(context, input)) {
|
||||
return Ok(generic::Image::Rect(Box::new(image_rect)));
|
||||
}
|
||||
Ok(generic::Image::Element(Image::parse_element(input)?))
|
||||
|
@ -171,7 +171,7 @@ impl Image {
|
|||
/// Parses a `-moz-element(# <element-id>)`.
|
||||
#[cfg(feature = "gecko")]
|
||||
fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Atom, ParseError<'i>> {
|
||||
input.try(|i| i.expect_function_matching("-moz-element"))?;
|
||||
input.try_parse(|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())),
|
||||
|
@ -189,7 +189,7 @@ impl Image {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Image, ParseError<'i>> {
|
||||
if let Ok(url) =
|
||||
input.try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input))
|
||||
input.try_parse(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input))
|
||||
{
|
||||
return Ok(generic::Image::Url(url));
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ impl Gradient {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input.try(|i| {
|
||||
input.try_parse(|i| {
|
||||
let x = Component::parse(context, i)?;
|
||||
let y = Component::parse(context, i)?;
|
||||
|
||||
|
@ -450,7 +450,7 @@ impl Gradient {
|
|||
reverse_stops: bool,
|
||||
) -> Result<LengthPercentageItemList, ParseError<'i>> {
|
||||
let mut items = input
|
||||
.try(|i| {
|
||||
.try_parse(|i| {
|
||||
i.expect_comma()?;
|
||||
i.parse_comma_separated(|i| {
|
||||
let function = i.expect_function()?.clone();
|
||||
|
@ -551,18 +551,19 @@ impl Gradient {
|
|||
repeating: bool,
|
||||
mut compat_mode: GradientCompatMode,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let direction =
|
||||
if let Ok(d) = input.try(|i| LineDirection::parse(context, i, &mut compat_mode)) {
|
||||
input.expect_comma()?;
|
||||
d
|
||||
} else {
|
||||
match compat_mode {
|
||||
GradientCompatMode::Modern => {
|
||||
LineDirection::Vertical(VerticalPositionKeyword::Bottom)
|
||||
},
|
||||
_ => LineDirection::Vertical(VerticalPositionKeyword::Top),
|
||||
}
|
||||
};
|
||||
let direction = if let Ok(d) =
|
||||
input.try_parse(|i| LineDirection::parse(context, i, &mut compat_mode))
|
||||
{
|
||||
input.expect_comma()?;
|
||||
d
|
||||
} else {
|
||||
match compat_mode {
|
||||
GradientCompatMode::Modern => {
|
||||
LineDirection::Vertical(VerticalPositionKeyword::Bottom)
|
||||
},
|
||||
_ => LineDirection::Vertical(VerticalPositionKeyword::Top),
|
||||
}
|
||||
};
|
||||
let items = Gradient::parse_stops(context, input)?;
|
||||
|
||||
Ok(Gradient::Linear {
|
||||
|
@ -582,16 +583,16 @@ impl Gradient {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
let (shape, position) = match compat_mode {
|
||||
GradientCompatMode::Modern => {
|
||||
let shape = input.try(|i| EndingShape::parse(context, i, compat_mode));
|
||||
let position = input.try(|i| {
|
||||
let shape = input.try_parse(|i| EndingShape::parse(context, i, compat_mode));
|
||||
let position = input.try_parse(|i| {
|
||||
i.expect_ident_matching("at")?;
|
||||
Position::parse(context, i)
|
||||
});
|
||||
(shape, position.ok())
|
||||
},
|
||||
_ => {
|
||||
let position = input.try(|i| Position::parse(context, i));
|
||||
let shape = input.try(|i| {
|
||||
let position = input.try_parse(|i| Position::parse(context, i));
|
||||
let shape = input.try_parse(|i| {
|
||||
if position.is_ok() {
|
||||
i.expect_comma()?;
|
||||
}
|
||||
|
@ -626,13 +627,13 @@ impl Gradient {
|
|||
input: &mut Parser<'i, 't>,
|
||||
repeating: bool,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let angle = input.try(|i| {
|
||||
let angle = input.try_parse(|i| {
|
||||
i.expect_ident_matching("from")?;
|
||||
// Spec allows unitless zero start angles
|
||||
// https://drafts.csswg.org/css-images-4/#valdef-conic-gradient-angle
|
||||
Angle::parse_with_unitless(context, i)
|
||||
});
|
||||
let position = input.try(|i| {
|
||||
let position = input.try_parse(|i| {
|
||||
i.expect_ident_matching("at")?;
|
||||
Position::parse(context, i)
|
||||
});
|
||||
|
@ -713,12 +714,12 @@ impl LineDirection {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
// Gradients allow unitless zero angles as an exception, see:
|
||||
// https://github.com/w3c/csswg-drafts/issues/1162
|
||||
if let Ok(angle) = input.try(|i| Angle::parse_with_unitless(context, i)) {
|
||||
if let Ok(angle) = input.try_parse(|i| Angle::parse_with_unitless(context, i)) {
|
||||
return Ok(LineDirection::Angle(angle));
|
||||
}
|
||||
|
||||
input.try(|i| {
|
||||
let to_ident = i.try(|i| i.expect_ident_matching("to"));
|
||||
input.try_parse(|i| {
|
||||
let to_ident = i.try_parse(|i| i.expect_ident_matching("to"));
|
||||
match *compat_mode {
|
||||
// `to` keyword is mandatory in modern syntax.
|
||||
GradientCompatMode::Modern => to_ident?,
|
||||
|
@ -738,14 +739,14 @@ impl LineDirection {
|
|||
_ => {},
|
||||
}
|
||||
|
||||
if let Ok(x) = i.try(HorizontalPositionKeyword::parse) {
|
||||
if let Ok(y) = i.try(VerticalPositionKeyword::parse) {
|
||||
if let Ok(x) = i.try_parse(HorizontalPositionKeyword::parse) {
|
||||
if let Ok(y) = i.try_parse(VerticalPositionKeyword::parse) {
|
||||
return Ok(LineDirection::Corner(x, y));
|
||||
}
|
||||
return Ok(LineDirection::Horizontal(x));
|
||||
}
|
||||
let y = VerticalPositionKeyword::parse(i)?;
|
||||
if let Ok(x) = i.try(HorizontalPositionKeyword::parse) {
|
||||
if let Ok(x) = i.try_parse(HorizontalPositionKeyword::parse) {
|
||||
return Ok(LineDirection::Corner(x, y));
|
||||
}
|
||||
Ok(LineDirection::Vertical(y))
|
||||
|
@ -759,19 +760,28 @@ impl EndingShape {
|
|||
input: &mut Parser<'i, 't>,
|
||||
compat_mode: GradientCompatMode,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
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() {
|
||||
if let Ok(extent) = input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode))
|
||||
{
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("circle"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(generic::EndingShape::Circle(Circle::Extent(extent)));
|
||||
}
|
||||
let _ = input.try(|i| i.expect_ident_matching("ellipse"));
|
||||
let _ = input.try_parse(|i| i.expect_ident_matching("ellipse"));
|
||||
return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent)));
|
||||
}
|
||||
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)) {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("circle"))
|
||||
.is_ok()
|
||||
{
|
||||
if let Ok(extent) =
|
||||
input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode))
|
||||
{
|
||||
return Ok(generic::EndingShape::Circle(Circle::Extent(extent)));
|
||||
}
|
||||
if compat_mode == GradientCompatMode::Modern {
|
||||
if let Ok(length) = input.try(|i| NonNegativeLength::parse(context, i)) {
|
||||
if let Ok(length) = input.try_parse(|i| NonNegativeLength::parse(context, i)) {
|
||||
return Ok(generic::EndingShape::Circle(Circle::Radius(length)));
|
||||
}
|
||||
}
|
||||
|
@ -779,12 +789,17 @@ impl EndingShape {
|
|||
ShapeExtent::FarthestCorner,
|
||||
)));
|
||||
}
|
||||
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)) {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("ellipse"))
|
||||
.is_ok()
|
||||
{
|
||||
if let Ok(extent) =
|
||||
input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode))
|
||||
{
|
||||
return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent)));
|
||||
}
|
||||
if compat_mode == GradientCompatMode::Modern {
|
||||
let pair: Result<_, ParseError> = input.try(|i| {
|
||||
let pair: Result<_, ParseError> = input.try_parse(|i| {
|
||||
let x = NonNegativeLengthPercentage::parse(context, i)?;
|
||||
let y = NonNegativeLengthPercentage::parse(context, i)?;
|
||||
Ok((x, y))
|
||||
|
@ -797,10 +812,10 @@ impl EndingShape {
|
|||
ShapeExtent::FarthestCorner,
|
||||
)));
|
||||
}
|
||||
if let Ok(length) = input.try(|i| NonNegativeLength::parse(context, i)) {
|
||||
if let Ok(y) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
if let Ok(length) = input.try_parse(|i| NonNegativeLength::parse(context, i)) {
|
||||
if let Ok(y) = input.try_parse(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
if compat_mode == GradientCompatMode::Modern {
|
||||
let _ = input.try(|i| i.expect_ident_matching("ellipse"));
|
||||
let _ = input.try_parse(|i| i.expect_ident_matching("ellipse"));
|
||||
}
|
||||
return Ok(generic::EndingShape::Ellipse(Ellipse::Radii(
|
||||
NonNegative(LengthPercentage::from(length.0)),
|
||||
|
@ -808,7 +823,7 @@ impl EndingShape {
|
|||
)));
|
||||
}
|
||||
if compat_mode == GradientCompatMode::Modern {
|
||||
let y = input.try(|i| {
|
||||
let y = input.try_parse(|i| {
|
||||
i.expect_ident_matching("ellipse")?;
|
||||
NonNegativeLengthPercentage::parse(context, i)
|
||||
});
|
||||
|
@ -818,16 +833,16 @@ impl EndingShape {
|
|||
y,
|
||||
)));
|
||||
}
|
||||
let _ = input.try(|i| i.expect_ident_matching("circle"));
|
||||
let _ = input.try_parse(|i| i.expect_ident_matching("circle"));
|
||||
}
|
||||
|
||||
return Ok(generic::EndingShape::Circle(Circle::Radius(length)));
|
||||
}
|
||||
input.try(|i| {
|
||||
input.try_parse(|i| {
|
||||
let x = Percentage::parse_non_negative(context, i)?;
|
||||
let y = if let Ok(y) = i.try(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
let y = if let Ok(y) = i.try_parse(|i| NonNegativeLengthPercentage::parse(context, i)) {
|
||||
if compat_mode == GradientCompatMode::Modern {
|
||||
let _ = i.try(|i| i.expect_ident_matching("ellipse"));
|
||||
let _ = i.try_parse(|i| i.expect_ident_matching("ellipse"));
|
||||
}
|
||||
y
|
||||
} else {
|
||||
|
@ -875,7 +890,7 @@ impl<T> generic::GradientItem<Color, T> {
|
|||
loop {
|
||||
input.parse_until_before(Delimiter::Comma, |input| {
|
||||
if seen_stop {
|
||||
if let Ok(hint) = input.try(|i| parse_position(context, i)) {
|
||||
if let Ok(hint) = input.try_parse(|i| parse_position(context, i)) {
|
||||
seen_stop = false;
|
||||
items.push(generic::GradientItem::InterpolationHint(hint));
|
||||
return Ok(());
|
||||
|
@ -884,7 +899,7 @@ impl<T> generic::GradientItem<Color, T> {
|
|||
|
||||
let stop = generic::ColorStop::parse(context, input, parse_position)?;
|
||||
|
||||
if let Ok(multi_position) = input.try(|i| parse_position(context, i)) {
|
||||
if let Ok(multi_position) = input.try_parse(|i| parse_position(context, i)) {
|
||||
let stop_color = stop.color.clone();
|
||||
items.push(stop.into_item());
|
||||
items.push(
|
||||
|
@ -927,7 +942,7 @@ impl<T> generic::ColorStop<Color, T> {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(generic::ColorStop {
|
||||
color: Color::parse(context, input)?,
|
||||
position: input.try(|i| parse_position(context, i)).ok(),
|
||||
position: input.try_parse(|i| parse_position(context, i)).ok(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -941,7 +956,7 @@ impl Parse for PaintWorklet {
|
|||
input.parse_nested_block(|input| {
|
||||
let name = Atom::from(&**input.expect_ident()?);
|
||||
let arguments = input
|
||||
.try(|input| {
|
||||
.try_parse(|input| {
|
||||
input.expect_comma()?;
|
||||
input.parse_comma_separated(|input| SpecifiedValue::parse(input))
|
||||
})
|
||||
|
@ -965,7 +980,7 @@ impl Parse for MozImageRect {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
input.try(|i| i.expect_function_matching("-moz-image-rect"))?;
|
||||
input.try_parse(|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(
|
||||
|
|
|
@ -1226,12 +1226,12 @@ impl Size {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(l) = input.try(computed::ExtremumLength::parse) {
|
||||
if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) {
|
||||
return Ok(GenericSize::ExtremumLength(l));
|
||||
}
|
||||
}
|
||||
|
||||
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
return Ok(GenericSize::Auto);
|
||||
}
|
||||
|
||||
|
@ -1267,12 +1267,12 @@ impl MaxSize {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
#[cfg(feature = "gecko")]
|
||||
{
|
||||
if let Ok(l) = input.try(computed::ExtremumLength::parse) {
|
||||
if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) {
|
||||
return Ok(GenericMaxSize::ExtremumLength(l));
|
||||
}
|
||||
}
|
||||
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(GenericMaxSize::None);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,10 +75,10 @@ impl Parse for ListStyleType {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(style) = input.try(|i| CounterStyle::parse(context, i)) {
|
||||
if let Ok(style) = input.try_parse(|i| CounterStyle::parse(context, i)) {
|
||||
return Ok(ListStyleType::CounterStyle(style));
|
||||
}
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(ListStyleType::None);
|
||||
}
|
||||
Ok(ListStyleType::String(
|
||||
|
@ -155,14 +155,14 @@ impl Parse for Quotes {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Quotes, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("auto"))
|
||||
.try_parse(|input| input.expect_ident_matching("auto"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(Quotes::Auto);
|
||||
}
|
||||
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("none"))
|
||||
.try_parse(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(Quotes::QuoteList(QuoteList::default()));
|
||||
|
|
|
@ -50,7 +50,7 @@ pub use self::effects::{BoxShadow, Filter, SimpleShadow};
|
|||
pub use self::flex::FlexBasis;
|
||||
pub use self::font::{FontFamily, FontLanguageOverride, FontStyle};
|
||||
pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric};
|
||||
pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontSizeKeyword};
|
||||
pub use self::font::{FontSize, FontSizeAdjust, FontSizeKeyword, FontStretch, FontSynthesis};
|
||||
pub use self::font::{FontVariantAlternates, FontWeight};
|
||||
pub use self::font::{FontVariantEastAsian, FontVariationSettings};
|
||||
pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom};
|
||||
|
@ -148,7 +148,7 @@ impl AngleOrPercentage {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_unitless_zero: AllowUnitlessZeroAngle,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(per) = input.try(|i| Percentage::parse(context, i)) {
|
||||
if let Ok(per) = input.try_parse(|i| Percentage::parse(context, i)) {
|
||||
return Ok(AngleOrPercentage::Percentage(per));
|
||||
}
|
||||
|
||||
|
@ -431,7 +431,9 @@ impl NumberOrPercentage {
|
|||
input: &mut Parser<'i, 't>,
|
||||
type_: AllowedNumericType,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(context, i, type_)) {
|
||||
if let Ok(per) =
|
||||
input.try_parse(|i| Percentage::parse_with_clamping_mode(context, i, type_))
|
||||
{
|
||||
return Ok(NumberOrPercentage::Percentage(per));
|
||||
}
|
||||
|
||||
|
@ -750,7 +752,7 @@ impl ClipRect {
|
|||
let bottom;
|
||||
let left;
|
||||
|
||||
if input.try(|input| input.expect_comma()).is_ok() {
|
||||
if input.try_parse(|input| input.expect_comma()).is_ok() {
|
||||
right = parse_argument(context, input, allow_quirks)?;
|
||||
input.expect_comma()?;
|
||||
bottom = parse_argument(context, input, allow_quirks)?;
|
||||
|
@ -782,7 +784,7 @@ impl ClipRectOrAuto {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(v) = input.try(|i| ClipRect::parse_quirky(context, i, allow_quirks)) {
|
||||
if let Ok(v) = input.try_parse(|i| ClipRect::parse_quirky(context, i, allow_quirks)) {
|
||||
return Ok(generics::GenericClipRectOrAuto::Rect(v));
|
||||
}
|
||||
input.expect_ident_matching("auto")?;
|
||||
|
@ -866,8 +868,8 @@ impl Attr {
|
|||
) -> Result<Attr, ParseError<'i>> {
|
||||
// Syntax is `[namespace? `|`]? ident`
|
||||
// no spaces allowed
|
||||
let first = input.try(|i| i.expect_ident_cloned()).ok();
|
||||
if let Ok(token) = input.try(|i| i.next_including_whitespace().map(|t| t.clone())) {
|
||||
let first = input.try_parse(|i| i.expect_ident_cloned()).ok();
|
||||
if let Ok(token) = input.try_parse(|i| i.next_including_whitespace().map(|t| t.clone())) {
|
||||
match token {
|
||||
Token::Delim('|') => {
|
||||
let location = input.current_source_location();
|
||||
|
|
|
@ -39,18 +39,20 @@ impl Parse for RayFunction<Angle> {
|
|||
let mut contain = false;
|
||||
loop {
|
||||
if angle.is_none() {
|
||||
angle = input.try(|i| Angle::parse(context, i)).ok();
|
||||
angle = input.try_parse(|i| Angle::parse(context, i)).ok();
|
||||
}
|
||||
|
||||
if size.is_none() {
|
||||
size = input.try(RaySize::parse).ok();
|
||||
size = input.try_parse(RaySize::parse).ok();
|
||||
if size.is_some() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if !contain {
|
||||
contain = input.try(|i| i.expect_ident_matching("contain")).is_ok();
|
||||
contain = input
|
||||
.try_parse(|i| i.expect_ident_matching("contain"))
|
||||
.is_ok();
|
||||
if contain {
|
||||
continue;
|
||||
}
|
||||
|
@ -76,7 +78,7 @@ impl Parse for OffsetPath {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
// Parse none.
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(OffsetPath::none());
|
||||
}
|
||||
|
||||
|
@ -166,12 +168,12 @@ impl Parse for OffsetRotate {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
let mut direction = input.try(OffsetRotateDirection::parse);
|
||||
let angle = input.try(|i| Angle::parse(context, i));
|
||||
let mut direction = input.try_parse(OffsetRotateDirection::parse);
|
||||
let angle = input.try_parse(|i| Angle::parse(context, i));
|
||||
if direction.is_err() {
|
||||
// The direction and angle could be any order, so give it a change to parse
|
||||
// direction again.
|
||||
direction = input.try(OffsetRotateDirection::parse);
|
||||
direction = input.try_parse(OffsetRotateDirection::parse);
|
||||
}
|
||||
|
||||
if direction.is_err() && angle.is_err() {
|
||||
|
|
|
@ -56,7 +56,7 @@ impl Parse for OutlineStyle {
|
|||
_context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<OutlineStyle, ParseError<'i>> {
|
||||
if let Ok(border_style) = input.try(BorderStyle::parse) {
|
||||
if let Ok(border_style) = input.try_parse(BorderStyle::parse) {
|
||||
if let BorderStyle::Hidden = border_style {
|
||||
return Err(input
|
||||
.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into())));
|
||||
|
|
|
@ -116,28 +116,31 @@ impl Position {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
match input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) {
|
||||
match input.try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) {
|
||||
Ok(x_pos @ PositionComponent::Center) => {
|
||||
if let Ok(y_pos) =
|
||||
input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks))
|
||||
input.try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks))
|
||||
{
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
}
|
||||
let x_pos = input
|
||||
.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks))
|
||||
.try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks))
|
||||
.unwrap_or(x_pos);
|
||||
let y_pos = PositionComponent::Center;
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
},
|
||||
Ok(PositionComponent::Side(x_keyword, lp)) => {
|
||||
if input.try(|i| i.expect_ident_matching("center")).is_ok() {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("center"))
|
||||
.is_ok()
|
||||
{
|
||||
let x_pos = PositionComponent::Side(x_keyword, lp);
|
||||
let y_pos = PositionComponent::Center;
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
}
|
||||
if let Ok(y_keyword) = input.try(VerticalPositionKeyword::parse) {
|
||||
if let Ok(y_keyword) = input.try_parse(VerticalPositionKeyword::parse) {
|
||||
let y_lp = input
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
let x_pos = PositionComponent::Side(x_keyword, lp);
|
||||
let y_pos = PositionComponent::Side(y_keyword, y_lp);
|
||||
|
@ -148,30 +151,30 @@ impl Position {
|
|||
return Ok(Self::new(x_pos, y_pos));
|
||||
},
|
||||
Ok(x_pos @ PositionComponent::Length(_)) => {
|
||||
if let Ok(y_keyword) = input.try(VerticalPositionKeyword::parse) {
|
||||
if let Ok(y_keyword) = input.try_parse(VerticalPositionKeyword::parse) {
|
||||
let y_pos = PositionComponent::Side(y_keyword, None);
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
}
|
||||
if let Ok(y_lp) =
|
||||
input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
{
|
||||
let y_pos = PositionComponent::Length(y_lp);
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
}
|
||||
let y_pos = PositionComponent::Center;
|
||||
let _ = input.try(|i| i.expect_ident_matching("center"));
|
||||
let _ = input.try_parse(|i| i.expect_ident_matching("center"));
|
||||
return Ok(Self::new(x_pos, y_pos));
|
||||
},
|
||||
Err(_) => {},
|
||||
}
|
||||
let y_keyword = VerticalPositionKeyword::parse(input)?;
|
||||
let lp_and_x_pos: Result<_, ParseError> = input.try(|i| {
|
||||
let lp_and_x_pos: Result<_, ParseError> = input.try_parse(|i| {
|
||||
let y_lp = i
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
if let Ok(x_keyword) = i.try(HorizontalPositionKeyword::parse) {
|
||||
if let Ok(x_keyword) = i.try_parse(HorizontalPositionKeyword::parse) {
|
||||
let x_lp = i
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
let x_pos = PositionComponent::Side(x_keyword, x_lp);
|
||||
return Ok((y_lp, x_pos));
|
||||
|
@ -250,15 +253,20 @@ impl<S: Parse> PositionComponent<S> {
|
|||
input: &mut Parser<'i, 't>,
|
||||
allow_quirks: AllowQuirks,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("center")).is_ok() {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("center"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(PositionComponent::Center);
|
||||
}
|
||||
if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) {
|
||||
if let Ok(lp) =
|
||||
input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
{
|
||||
return Ok(PositionComponent::Length(lp));
|
||||
}
|
||||
let keyword = S::parse(context, input)?;
|
||||
let lp = input
|
||||
.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks))
|
||||
.ok();
|
||||
Ok(PositionComponent::Side(keyword, lp))
|
||||
}
|
||||
|
@ -730,7 +738,7 @@ impl Parse for TemplateAreas {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut strings = vec![];
|
||||
while let Ok(string) =
|
||||
input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into()))
|
||||
input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned().into()))
|
||||
{
|
||||
strings.push(string);
|
||||
}
|
||||
|
@ -889,10 +897,10 @@ impl Parse for AspectRatio {
|
|||
use crate::values::generics::position::PreferredRatio;
|
||||
|
||||
let location = input.current_source_location();
|
||||
let mut auto = input.try(|i| i.expect_ident_matching("auto"));
|
||||
let ratio = input.try(|i| Ratio::parse(context, i));
|
||||
let mut auto = input.try_parse(|i| i.expect_ident_matching("auto"));
|
||||
let ratio = input.try_parse(|i| Ratio::parse(context, i));
|
||||
if auto.is_err() {
|
||||
auto = input.try(|i| i.expect_ident_matching("auto"));
|
||||
auto = input.try_parse(|i| i.expect_ident_matching("auto"));
|
||||
}
|
||||
|
||||
if auto.is_err() && ratio.is_err() {
|
||||
|
|
|
@ -87,7 +87,7 @@ impl Parse for SourceSizeOrLength {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(size) = input.try(|input| SourceSize::parse(context, input)) {
|
||||
if let Ok(size) = input.try_parse(|input| SourceSize::parse(context, input)) {
|
||||
return Ok(SourceSizeOrLength::SourceSize(size));
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,8 @@ macro_rules! parse_svg_length {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(lp) = input.try(|i| <$lp>::parse_quirky(context, i, AllowQuirks::Always))
|
||||
if let Ok(lp) =
|
||||
input.try_parse(|i| <$lp>::parse_quirky(context, i, AllowQuirks::Always))
|
||||
{
|
||||
return Ok(generic::SVGLength::LengthPercentage(lp));
|
||||
}
|
||||
|
@ -71,7 +72,7 @@ impl Parse for SVGStrokeDashArray {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(values) = input.try(|i| {
|
||||
if let Ok(values) = input.try_parse(|i| {
|
||||
CommaWithSpace::parse(i, |i| {
|
||||
NonNegativeLengthPercentage::parse_quirky(context, i, AllowQuirks::Always)
|
||||
})
|
||||
|
@ -161,7 +162,7 @@ impl Parse for SVGPaintOrder {
|
|||
_context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<SVGPaintOrder, ParseError<'i>> {
|
||||
if let Ok(()) = input.try(|i| i.expect_ident_matching("normal")) {
|
||||
if let Ok(()) = input.try_parse(|i| i.expect_ident_matching("normal")) {
|
||||
return Ok(SVGPaintOrder::normal());
|
||||
}
|
||||
|
||||
|
@ -172,7 +173,7 @@ impl Parse for SVGPaintOrder {
|
|||
let mut pos = 0;
|
||||
|
||||
loop {
|
||||
let result: Result<_, ParseError> = input.try(|input| {
|
||||
let result: Result<_, ParseError> = input.try_parse(|input| {
|
||||
try_match_ident_ignore_ascii_case! { input,
|
||||
"fill" => Ok(PaintOrder::Fill),
|
||||
"stroke" => Ok(PaintOrder::Stroke),
|
||||
|
|
|
@ -41,11 +41,16 @@ impl Parse for InitialLetter {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("normal")).is_ok() {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("normal"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(GenericInitialLetter::Normal);
|
||||
}
|
||||
let size = Number::parse_at_least_one(context, input)?;
|
||||
let sink = input.try(|i| Integer::parse_positive(context, i)).ok();
|
||||
let sink = input
|
||||
.try_parse(|i| Integer::parse_positive(context, i))
|
||||
.ok();
|
||||
Ok(GenericInitialLetter::Specified(size, sink))
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +166,7 @@ impl Parse for TextOverflow {
|
|||
) -> Result<TextOverflow, ParseError<'i>> {
|
||||
let first = TextOverflowSide::parse(context, input)?;
|
||||
let second = input
|
||||
.try(|input| TextOverflowSide::parse(context, input))
|
||||
.try_parse(|input| TextOverflowSide::parse(context, input))
|
||||
.ok();
|
||||
Ok(TextOverflow { first, second })
|
||||
}
|
||||
|
@ -251,7 +256,7 @@ impl Parse for TextDecorationLine {
|
|||
// ensure we don't return an error if we don't consume the whole thing
|
||||
// because we find an invalid identifier or other kind of token.
|
||||
loop {
|
||||
let flag: Result<_, ParseError<'i>> = input.try(|input| {
|
||||
let flag: Result<_, ParseError<'i>> = input.try_parse(|input| {
|
||||
let flag = try_match_ident_ignore_ascii_case! { input,
|
||||
"none" if result.is_empty() => TextDecorationLine::NONE,
|
||||
"underline" => TextDecorationLine::UNDERLINE,
|
||||
|
@ -791,22 +796,22 @@ impl Parse for TextEmphasisStyle {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("none"))
|
||||
.try_parse(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(TextEmphasisStyle::None);
|
||||
}
|
||||
|
||||
if let Ok(s) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) {
|
||||
if let Ok(s) = input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned())) {
|
||||
// Handle <string>
|
||||
return Ok(TextEmphasisStyle::String(s.into()));
|
||||
}
|
||||
|
||||
// Handle a pair of keywords
|
||||
let mut shape = input.try(TextEmphasisShapeKeyword::parse).ok();
|
||||
let fill = input.try(TextEmphasisFillMode::parse).ok();
|
||||
let mut shape = input.try_parse(TextEmphasisShapeKeyword::parse).ok();
|
||||
let fill = input.try_parse(TextEmphasisFillMode::parse).ok();
|
||||
if shape.is_none() {
|
||||
shape = input.try(TextEmphasisShapeKeyword::parse).ok();
|
||||
shape = input.try_parse(TextEmphasisShapeKeyword::parse).ok();
|
||||
}
|
||||
|
||||
if shape.is_none() && fill.is_none() {
|
||||
|
@ -922,7 +927,7 @@ impl Parse for TextEmphasisPosition {
|
|||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if let Ok(horizontal) =
|
||||
input.try(|input| TextEmphasisHorizontalWritingModeValue::parse(input))
|
||||
input.try_parse(|input| TextEmphasisHorizontalWritingModeValue::parse(input))
|
||||
{
|
||||
let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?;
|
||||
Ok(TextEmphasisPosition(horizontal, vertical))
|
||||
|
|
|
@ -68,7 +68,7 @@ impl Transform {
|
|||
use style_traits::{Separator, Space};
|
||||
|
||||
if input
|
||||
.try(|input| input.expect_ident_matching("none"))
|
||||
.try_parse(|input| input.expect_ident_matching("none"))
|
||||
.is_ok()
|
||||
{
|
||||
return Ok(generic::Transform::none());
|
||||
|
@ -137,7 +137,7 @@ impl Transform {
|
|||
},
|
||||
"translate" => {
|
||||
let sx = specified::LengthPercentage::parse(context, input)?;
|
||||
if input.try(|input| input.expect_comma()).is_ok() {
|
||||
if input.try_parse(|input| input.expect_comma()).is_ok() {
|
||||
let sy = specified::LengthPercentage::parse(context, input)?;
|
||||
Ok(generic::TransformOperation::Translate(sx, sy))
|
||||
} else {
|
||||
|
@ -166,7 +166,7 @@ impl Transform {
|
|||
},
|
||||
"scale" => {
|
||||
let sx = NumberOrPercentage::parse(context, input)?.to_number();
|
||||
if input.try(|input| input.expect_comma()).is_ok() {
|
||||
if input.try_parse(|input| input.expect_comma()).is_ok() {
|
||||
let sy = NumberOrPercentage::parse(context, input)?.to_number();
|
||||
Ok(generic::TransformOperation::Scale(sx, sy))
|
||||
} else {
|
||||
|
@ -222,7 +222,7 @@ impl Transform {
|
|||
},
|
||||
"skew" => {
|
||||
let ax = specified::Angle::parse_with_unitless(context, input)?;
|
||||
if input.try(|input| input.expect_comma()).is_ok() {
|
||||
if input.try_parse(|input| input.expect_comma()).is_ok() {
|
||||
let ay = specified::Angle::parse_with_unitless(context, input)?;
|
||||
Ok(generic::TransformOperation::Skew(ax, ay))
|
||||
} else {
|
||||
|
@ -282,17 +282,17 @@ impl Parse for TransformOrigin {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
let parse_depth = |input: &mut Parser| {
|
||||
input
|
||||
.try(|i| Length::parse(context, i))
|
||||
.try_parse(|i| Length::parse(context, i))
|
||||
.unwrap_or(Length::zero())
|
||||
};
|
||||
match input.try(|i| OriginComponent::parse(context, i)) {
|
||||
match input.try_parse(|i| OriginComponent::parse(context, i)) {
|
||||
Ok(x_origin @ OriginComponent::Center) => {
|
||||
if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) {
|
||||
if let Ok(y_origin) = input.try_parse(|i| OriginComponent::parse(context, i)) {
|
||||
let depth = parse_depth(input);
|
||||
return Ok(Self::new(x_origin, y_origin, depth));
|
||||
}
|
||||
let y_origin = OriginComponent::Center;
|
||||
if let Ok(x_keyword) = input.try(HorizontalPositionKeyword::parse) {
|
||||
if let Ok(x_keyword) = input.try_parse(HorizontalPositionKeyword::parse) {
|
||||
let x_origin = OriginComponent::Side(x_keyword);
|
||||
let depth = parse_depth(input);
|
||||
return Ok(Self::new(x_origin, y_origin, depth));
|
||||
|
@ -301,7 +301,7 @@ impl Parse for TransformOrigin {
|
|||
return Ok(Self::new(x_origin, y_origin, depth));
|
||||
},
|
||||
Ok(x_origin) => {
|
||||
if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) {
|
||||
if let Ok(y_origin) = input.try_parse(|i| OriginComponent::parse(context, i)) {
|
||||
let depth = parse_depth(input);
|
||||
return Ok(Self::new(x_origin, y_origin, depth));
|
||||
}
|
||||
|
@ -313,12 +313,15 @@ impl Parse for TransformOrigin {
|
|||
}
|
||||
let y_keyword = VerticalPositionKeyword::parse(input)?;
|
||||
let y_origin = OriginComponent::Side(y_keyword);
|
||||
if let Ok(x_keyword) = input.try(HorizontalPositionKeyword::parse) {
|
||||
if let Ok(x_keyword) = input.try_parse(HorizontalPositionKeyword::parse) {
|
||||
let x_origin = OriginComponent::Side(x_keyword);
|
||||
let depth = parse_depth(input);
|
||||
return Ok(Self::new(x_origin, y_origin, depth));
|
||||
}
|
||||
if input.try(|i| i.expect_ident_matching("center")).is_ok() {
|
||||
if input
|
||||
.try_parse(|i| i.expect_ident_matching("center"))
|
||||
.is_ok()
|
||||
{
|
||||
let x_origin = OriginComponent::Center;
|
||||
let depth = parse_depth(input);
|
||||
return Ok(Self::new(x_origin, y_origin, depth));
|
||||
|
@ -368,7 +371,7 @@ impl Parse for Rotate {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(generic::Rotate::None);
|
||||
}
|
||||
|
||||
|
@ -376,9 +379,11 @@ impl Parse for Rotate {
|
|||
//
|
||||
// The rotate axis and angle could be in any order, so we parse angle twice to cover
|
||||
// two cases. i.e. `<number>{3} <angle>` or `<angle> <number>{3}`
|
||||
let angle = input.try(|i| specified::Angle::parse(context, i)).ok();
|
||||
let angle = input
|
||||
.try_parse(|i| specified::Angle::parse(context, i))
|
||||
.ok();
|
||||
let axis = input
|
||||
.try(|i| {
|
||||
.try_parse(|i| {
|
||||
Ok(try_match_ident_ignore_ascii_case! { i,
|
||||
"x" => (Number::new(1.), Number::new(0.), Number::new(0.)),
|
||||
"y" => (Number::new(0.), Number::new(1.), Number::new(0.)),
|
||||
|
@ -386,7 +391,7 @@ impl Parse for Rotate {
|
|||
})
|
||||
})
|
||||
.or_else(|_: ParseError| -> Result<_, ParseError> {
|
||||
input.try(|i| {
|
||||
input.try_parse(|i| {
|
||||
Ok((
|
||||
Number::parse(context, i)?,
|
||||
Number::parse(context, i)?,
|
||||
|
@ -415,13 +420,13 @@ impl Parse for Translate {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(generic::Translate::None);
|
||||
}
|
||||
|
||||
let tx = specified::LengthPercentage::parse(context, input)?;
|
||||
if let Ok(ty) = input.try(|i| specified::LengthPercentage::parse(context, i)) {
|
||||
if let Ok(tz) = input.try(|i| specified::Length::parse(context, i)) {
|
||||
if let Ok(ty) = input.try_parse(|i| specified::LengthPercentage::parse(context, i)) {
|
||||
if let Ok(tz) = input.try_parse(|i| specified::Length::parse(context, i)) {
|
||||
// 'translate: <length-percentage> <length-percentage> <length>'
|
||||
return Ok(generic::Translate::Translate(tx, ty, tz));
|
||||
}
|
||||
|
@ -454,14 +459,14 @@ impl Parse for Scale {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(generic::Scale::None);
|
||||
}
|
||||
|
||||
let sx = NumberOrPercentage::parse(context, input)?.to_number();
|
||||
if let Ok(sy) = input.try(|i| NumberOrPercentage::parse(context, i)) {
|
||||
if let Ok(sy) = input.try_parse(|i| NumberOrPercentage::parse(context, i)) {
|
||||
let sy = sy.to_number();
|
||||
if let Ok(sz) = input.try(|i| NumberOrPercentage::parse(context, i)) {
|
||||
if let Ok(sz) = input.try_parse(|i| NumberOrPercentage::parse(context, i)) {
|
||||
// 'scale: <number> <number> <number>'
|
||||
return Ok(generic::Scale::Scale(sx, sy, sz.to_number()));
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ impl Parse for Cursor {
|
|||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut images = vec![];
|
||||
loop {
|
||||
match input.try(|input| CursorImage::parse(context, input)) {
|
||||
match input.try_parse(|input| CursorImage::parse(context, input)) {
|
||||
Ok(image) => images.push(image),
|
||||
Err(_) => break,
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ impl Parse for CursorImage {
|
|||
let mut hotspot_x = Number::zero();
|
||||
let mut hotspot_y = Number::zero();
|
||||
|
||||
if let Ok(x) = input.try(|input| Number::parse(context, input)) {
|
||||
if let Ok(x) = input.try_parse(|input| Number::parse(context, input)) {
|
||||
has_hotspot = true;
|
||||
hotspot_x = x;
|
||||
hotspot_y = Number::parse(context, input)?;
|
||||
|
@ -136,7 +136,7 @@ impl Parse for ScrollbarColor {
|
|||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>,
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
if input.try(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
|
||||
return Ok(generics::ScrollbarColor::Auto);
|
||||
}
|
||||
Ok(generics::ScrollbarColor::Colors {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue