Small changes to AdditiveTuple struct.

This commit is contained in:
Xidorn Quan 2017-05-16 09:47:18 +10:00
parent fdb29e15a4
commit 0722031726

View file

@ -536,7 +536,7 @@ impl Parse for AdditiveSymbols {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let tuples = Vec::<AdditiveTuple>::parse(context, input)?; let tuples = Vec::<AdditiveTuple>::parse(context, input)?;
// FIXME maybe? https://github.com/w3c/csswg-drafts/issues/1220 // FIXME maybe? https://github.com/w3c/csswg-drafts/issues/1220
if tuples.windows(2).any(|window| window[0].value <= window[1].value) { if tuples.windows(2).any(|window| window[0].weight <= window[1].weight) {
return Err(()) return Err(())
} }
Ok(AdditiveSymbols(tuples)) Ok(AdditiveSymbols(tuples))
@ -552,8 +552,10 @@ impl ToCss for AdditiveSymbols {
/// <integer> && <symbol> /// <integer> && <symbol>
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct AdditiveTuple { pub struct AdditiveTuple {
value: u32, /// <integer>
symbol: Symbol, pub weight: u32,
/// <symbol>
pub symbol: Symbol,
} }
impl OneOrMoreCommaSeparated for AdditiveTuple {} impl OneOrMoreCommaSeparated for AdditiveTuple {}
@ -561,13 +563,13 @@ impl OneOrMoreCommaSeparated for AdditiveTuple {}
impl Parse for AdditiveTuple { impl Parse for AdditiveTuple {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> { fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let symbol = input.try(|input| Symbol::parse(context, input)); let symbol = input.try(|input| Symbol::parse(context, input));
let value = input.expect_integer()?; let weight = input.expect_integer()?;
if value < 0 { if weight < 0 {
return Err(()) return Err(())
} }
let symbol = symbol.or_else(|()| Symbol::parse(context, input))?; let symbol = symbol.or_else(|()| Symbol::parse(context, input))?;
Ok(AdditiveTuple { Ok(AdditiveTuple {
value: value as u32, weight: weight as u32,
symbol: symbol, symbol: symbol,
}) })
} }
@ -575,7 +577,7 @@ impl Parse for AdditiveTuple {
impl ToCss for AdditiveTuple { impl ToCss for AdditiveTuple {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write { fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
write!(dest, "{} ", self.value)?; write!(dest, "{} ", self.weight)?;
self.symbol.to_css(dest) self.symbol.to_css(dest)
} }
} }