style: Reduce some code duplication and ugliness when parsing identifiers.

This commit is contained in:
Emilio Cobos Álvarez 2017-06-10 15:07:33 +02:00
parent ddfe8b0468
commit e3c4d03bde
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
12 changed files with 104 additions and 134 deletions

View file

@ -7,7 +7,6 @@
use cssparser::{Parser, serialize_identifier};
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use std::{fmt, mem, usize};
use style_traits::{ToCss, ParseError, StyleParseError};
use values::{CSSFloat, CustomIdent};
@ -350,12 +349,10 @@ impl Parse for RepeatCount {
Err(StyleParseError::UnspecifiedError.into())
}
} else {
let ident = input.expect_ident()?;
(match_ignore_ascii_case! { &ident,
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
"auto-fill" => Ok(RepeatCount::AutoFill),
"auto-fit" => Ok(RepeatCount::AutoFit),
_ => Err(()),
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
}
}
}
}

View file

@ -8,7 +8,6 @@
use counter_style::{Symbols, parse_counter_style_name};
use cssparser::Parser;
use parser::{Parse, ParserContext};
use selectors::parser::SelectorParseError;
use std::fmt;
use style_traits::{OneOrMoreCommaSeparated, ToCss, ParseError, StyleParseError};
use super::CustomIdent;
@ -328,13 +327,11 @@ impl<ColorType> SVGPaint<ColorType> {
impl<ColorType> SVGPaintKind<ColorType> {
/// Parse a keyword value only
fn parse_ident<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let ident = input.expect_ident()?;
(match_ignore_ascii_case! { &ident,
try_match_ident_ignore_ascii_case! { input.expect_ident()?,
"none" => Ok(SVGPaintKind::None),
"context-fill" => Ok(SVGPaintKind::ContextFill),
"context-stroke" => Ok(SVGPaintKind::ContextStroke),
_ => Err(())
}).map_err(|()| SelectorParseError::UnexpectedIdent(ident).into())
}
}
}