mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
style: Improve #[derive(Parse)].
I want to do this so that I can get rid of Either<>. The reasons for getting rid of either are multiple: * It doesn't generate as nice C++ code using cbindgen. * It isn't that nice to use either from Rust. * cbindgen has bugs with zero-sized types. I started using this for ColorOrAuto and a few others, for now. Differential Revision: https://phabricator.services.mozilla.com/D19844
This commit is contained in:
parent
6118e4d993
commit
73d5b82f9f
24 changed files with 238 additions and 362 deletions
|
@ -119,27 +119,25 @@ impl Parse for CounterStyleOrNone {
|
|||
if input.try(|i| i.expect_ident_matching("none")).is_ok() {
|
||||
return Ok(CounterStyleOrNone::None);
|
||||
}
|
||||
if input.try(|i| i.expect_function_matching("symbols")).is_ok() {
|
||||
return input.parse_nested_block(|input| {
|
||||
let symbols_type = input
|
||||
.try(|i| SymbolsType::parse(i))
|
||||
.unwrap_or(SymbolsType::Symbolic);
|
||||
let symbols = Symbols::parse(context, input)?;
|
||||
// There must be at least two symbols for alphabetic or
|
||||
// numeric system.
|
||||
if (symbols_type == SymbolsType::Alphabetic ||
|
||||
symbols_type == SymbolsType::Numeric) && symbols.0.len() < 2
|
||||
{
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
// Identifier is not allowed in symbols() function.
|
||||
if symbols.0.iter().any(|sym| !sym.is_allowed_in_symbols()) {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
Ok(CounterStyleOrNone::Symbols(symbols_type, symbols))
|
||||
});
|
||||
}
|
||||
Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
|
||||
input.expect_function_matching("symbols")?;
|
||||
input.parse_nested_block(|input| {
|
||||
let symbols_type = input
|
||||
.try(SymbolsType::parse)
|
||||
.unwrap_or(SymbolsType::Symbolic);
|
||||
let symbols = Symbols::parse(context, input)?;
|
||||
// There must be at least two symbols for alphabetic or
|
||||
// numeric system.
|
||||
if (symbols_type == SymbolsType::Alphabetic ||
|
||||
symbols_type == SymbolsType::Numeric) && symbols.0.len() < 2
|
||||
{
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
// Identifier is not allowed in symbols() function.
|
||||
if symbols.0.iter().any(|sym| !sym.is_allowed_in_symbols()) {
|
||||
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
|
||||
}
|
||||
Ok(CounterStyleOrNone::Symbols(symbols_type, symbols))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue