stylo: make font-variant-* longhands parsing more tolerant.

Avoid early returning Err() in parsers, so we could let the the caller
of the parsers to handle the rest of input, and return error if it requires
parsing entirely.

The point is let returning Err() stay inside input.try(), so we can count
on input.try() to restore the position when parsing invalid idents.

From gecko bug: Bug 1356134 (https://bugzilla.mozilla.org/show_bug.cgi?id=1356134)
This commit is contained in:
Jeremy Chen 2017-06-09 03:38:23 +00:00
parent d28324d9eb
commit 97ef40ee88

View file

@ -1376,21 +1376,21 @@ ${helpers.single_keyword_system("font-kerning",
return Ok(SpecifiedValue::Value(result)) return Ok(SpecifiedValue::Value(result))
} }
while let Ok(ident) = input.try(|input| input.expect_ident()) { while let Ok(flag) = input.try(|input| {
let flag = match_ignore_ascii_case! { &ident, Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"stylistic" => Some(STYLISTIC), "stylistic" => STYLISTIC,
"historical-forms" => Some(HISTORICAL_FORMS), "historical-forms" => HISTORICAL_FORMS,
"styleset" => Some(STYLESET), "styleset" => STYLESET,
"character-variant" => Some(CHARACTER_VARIANT), "character-variant" => CHARACTER_VARIANT,
"swash" => Some(SWASH), "swash" => SWASH,
"ornaments" => Some(ORNAMENTS), "ornaments" => ORNAMENTS,
"annotation" => Some(ANNOTATION), "annotation" => ANNOTATION,
_ => None, _ => return Err(()),
}; })
let flag = match flag { }) {
Some(flag) if !result.intersects(flag) => flag, if result.intersects(flag) {
_ => return Err(SelectorParseError::UnexpectedIdent(ident).into()), return Err(StyleParseError::UnspecifiedError.into())
}; }
result.insert(flag); result.insert(flag);
} }
@ -1406,9 +1406,9 @@ ${helpers.single_keyword_system("font-kerning",
macro_rules! exclusive_value { macro_rules! exclusive_value {
(($value:ident, $set:expr) => $ident:ident) => { (($value:ident, $set:expr) => $ident:ident) => {
if $value.intersects($set) { if $value.intersects($set) {
None return Err(())
} else { } else {
Some($ident) $ident
} }
} }
} }
@ -1521,8 +1521,8 @@ macro_rules! exclusive_value {
return Ok(SpecifiedValue::Value(result)) return Ok(SpecifiedValue::Value(result))
} }
while let Ok(ident) = input.try(|input| input.expect_ident()) { while let Ok(flag) = input.try(|input| {
let flag = match_ignore_ascii_case! { &ident, Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"jis78" => "jis78" =>
exclusive_value!((result, ${east_asian_variant_values}) => JIS78), exclusive_value!((result, ${east_asian_variant_values}) => JIS78),
"jis83" => "jis83" =>
@ -1541,12 +1541,9 @@ macro_rules! exclusive_value {
exclusive_value!((result, ${east_asian_width_values}) => PROPORTIONAL_WIDTH), exclusive_value!((result, ${east_asian_width_values}) => PROPORTIONAL_WIDTH),
"ruby" => "ruby" =>
exclusive_value!((result, RUBY) => RUBY), exclusive_value!((result, RUBY) => RUBY),
_ => None, _ => return Err(()),
}; })
let flag = match flag { }) {
Some(flag) => flag,
None => return Err(SelectorParseError::UnexpectedIdent(ident).into()),
};
result.insert(flag); result.insert(flag);
} }
@ -1681,8 +1678,8 @@ macro_rules! exclusive_value {
return Ok(SpecifiedValue::Value(NONE)) return Ok(SpecifiedValue::Value(NONE))
} }
while let Ok(ident) = input.try(|input| input.expect_ident()) { while let Ok(flag) = input.try(|input| {
let flag = match_ignore_ascii_case! { &ident, Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"common-ligatures" => "common-ligatures" =>
exclusive_value!((result, ${common_lig_values}) => COMMON_LIGATURES), exclusive_value!((result, ${common_lig_values}) => COMMON_LIGATURES),
"no-common-ligatures" => "no-common-ligatures" =>
@ -1699,12 +1696,9 @@ macro_rules! exclusive_value {
exclusive_value!((result, ${contextual_alt_values}) => CONTEXTUAL), exclusive_value!((result, ${contextual_alt_values}) => CONTEXTUAL),
"no-contextual" => "no-contextual" =>
exclusive_value!((result, ${contextual_alt_values}) => NO_CONTEXTUAL), exclusive_value!((result, ${contextual_alt_values}) => NO_CONTEXTUAL),
_ => None, _ => return Err(()),
}; })
let flag = match flag { }) {
Some(flag) => flag,
None => return Err(SelectorParseError::UnexpectedIdent(ident).into()),
};
result.insert(flag); result.insert(flag);
} }
@ -1832,14 +1826,14 @@ macro_rules! exclusive_value {
return Ok(SpecifiedValue::Value(result)) return Ok(SpecifiedValue::Value(result))
} }
while let Ok(ident) = input.try(|input| input.expect_ident()) { while let Ok(flag) = input.try(|input| {
let flag = match_ignore_ascii_case! { &ident, Ok(match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?,
"ordinal" => "ordinal" =>
exclusive_value!((result, ORDINAL) => ORDINAL), exclusive_value!((result, ORDINAL) => ORDINAL),
"slashed-zero" => "slashed-zero" =>
exclusive_value!((result, SLASHED_ZERO) => SLASHED_ZERO), exclusive_value!((result, SLASHED_ZERO) => SLASHED_ZERO),
"lining-nums" => "lining-nums" =>
exclusive_value!((result, ${numeric_figure_values}) => LINING_NUMS ), exclusive_value!((result, ${numeric_figure_values}) => LINING_NUMS),
"oldstyle-nums" => "oldstyle-nums" =>
exclusive_value!((result, ${numeric_figure_values}) => OLDSTYLE_NUMS), exclusive_value!((result, ${numeric_figure_values}) => OLDSTYLE_NUMS),
"proportional-nums" => "proportional-nums" =>
@ -1850,12 +1844,9 @@ macro_rules! exclusive_value {
exclusive_value!((result, ${numeric_fraction_values}) => DIAGONAL_FRACTIONS), exclusive_value!((result, ${numeric_fraction_values}) => DIAGONAL_FRACTIONS),
"stacked-fractions" => "stacked-fractions" =>
exclusive_value!((result, ${numeric_fraction_values}) => STACKED_FRACTIONS), exclusive_value!((result, ${numeric_fraction_values}) => STACKED_FRACTIONS),
_ => None, _ => return Err(()),
}; })
let flag = match flag { }) {
Some(flag) => flag,
None => return Err(SelectorParseError::UnexpectedIdent(ident).into()),
};
result.insert(flag); result.insert(flag);
} }