Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive more Parse implementations (fixes #19827) #19903

Merged
merged 7 commits into from Feb 1, 2018

Rename #[parse(aliases)] to #[css(aliases)]

  • Loading branch information
nox committed Feb 1, 2018
commit 579cef6a69681e07b5d22ac54678d608549dd5d4
@@ -28,9 +28,9 @@ pub enum Display {
Table, InlineTable, TableRowGroup, TableHeaderGroup,
TableFooterGroup, TableRow, TableColumnGroup,
TableColumn, TableCell, TableCaption, ListItem, None,
#[parse(aliases = "-webkit-flex")]
#[css(aliases = "-webkit-flex")]

This comment has been minimized.

@emilio

emilio Feb 1, 2018

Member

nice :)

Flex,
#[parse(aliases = "-webkit-inline-flex")]
#[css(aliases = "-webkit-inline-flex")]
InlineFlex,
#[cfg(feature = "gecko")]
Grid,
@@ -39,7 +39,7 @@ pub fn derive_to_animated_value(stream: TokenStream) -> TokenStream {
to_animated_value::derive(input).to_string().parse().unwrap()
}

#[proc_macro_derive(Parse, attributes(parse))]
#[proc_macro_derive(Parse, attributes(css))]
pub fn derive_parse(stream: TokenStream) -> TokenStream {
let input = syn::parse_derive_input(&stream.to_string()).unwrap();
parse::derive(input).to_string().parse().unwrap()
@@ -6,6 +6,7 @@ use cg;
use quote::Tokens;
use syn::DeriveInput;
use synstructure;
use to_css::CssVariantAttrs;

pub fn derive(input: DeriveInput) -> Tokens {
let name = &input.ident;
@@ -19,7 +20,7 @@ pub fn derive(input: DeriveInput) -> Tokens {
"Parse is only supported for single-variant enums for now"
);

let variant_attrs = cg::parse_variant_attrs::<ParseVariantAttrs>(variant);
let variant_attrs = cg::parse_variant_attrs::<CssVariantAttrs>(variant);
let identifier = cg::to_css_identifier(variant.ident.as_ref());
let ident = &variant.ident;

@@ -87,11 +88,3 @@ pub fn derive(input: DeriveInput) -> Tokens {
#methods_impl
}
}

#[darling(attributes(parse), default)]
#[derive(Default, FromVariant)]
struct ParseVariantAttrs {
/// The comma-separated list of aliases this variant should be aliased to at
/// parse time.
aliases: Option<String>,
}
@@ -123,11 +123,12 @@ struct CssInputAttrs {

#[darling(attributes(css), default)]
#[derive(Default, FromVariant)]
struct CssVariantAttrs {
function: Option<Function>,
iterable: bool,
comma: bool,
dimension: bool,
pub struct CssVariantAttrs {
pub function: Option<Function>,
pub iterable: bool,
pub comma: bool,
pub dimension: bool,
pub aliases: Option<String>,
}

#[darling(attributes(css), default)]
@@ -136,7 +137,7 @@ struct CssFieldAttrs {
ignore_bound: bool,
}

struct Function {
pub struct Function {
name: Option<Ident>,
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.