Auto merge of #19578 - emilio:parse-keyword, r=Manishearth,canaltinova

Allow deriving Parse on keywords.

This makes patches like #19576 much easier.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/19578)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-12-15 14:55:49 -06:00 committed by GitHub
commit e631d167bf
7 changed files with 145 additions and 51 deletions

View file

@ -149,8 +149,10 @@ pub trait Parse : Sized {
/// Parse a value of this type.
///
/// Returns an error on failure.
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>>;
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>>;
}
impl<T> Parse for Vec<T>

View file

@ -46,11 +46,13 @@ impl BackgroundSize {
}
/// One of the keywords for `background-repeat`.
define_css_keyword_enum! { RepeatKeyword:
"repeat" => Repeat,
"space" => Space,
"round" => Round,
"no-repeat" => NoRepeat
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
#[allow(missing_docs)]
pub enum RepeatKeyword {
Repeat,
Space,
Round,
NoRepeat,
}
/// The specified value for the `background-repeat` property.

View file

@ -42,17 +42,21 @@ pub enum PositionComponent<S> {
Side(S, Option<LengthOrPercentage>),
}
define_css_keyword_enum! { X:
"left" => Left,
"right" => Right,
/// A keyword for the X direction.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
#[allow(missing_docs)]
pub enum X {
Left,
Right,
}
add_impls_for_keyword_enum!(X);
define_css_keyword_enum! { Y:
"top" => Top,
"bottom" => Bottom,
/// A keyword for the Y direction.
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, Parse, PartialEq, ToComputedValue, ToCss)]
#[allow(missing_docs)]
pub enum Y {
Top,
Bottom,
}
add_impls_for_keyword_enum!(Y);
impl Parse for Position {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {