mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Move some parsing-only attributes to use #[parse(..)] instead of #[css(..)].
I need to admit I'm ambivalent about this one :). Bug: 1466609 Reviewed-by: xidorn MozReview-Commit-ID: F1jlfnQKXwo
This commit is contained in:
parent
8821ad72f4
commit
2c0a19e517
8 changed files with 39 additions and 29 deletions
|
@ -157,12 +157,12 @@ impl<'a> ParserContext<'a> {
|
|||
///
|
||||
/// The derive code understands the following attributes on each of the variants:
|
||||
///
|
||||
/// * `#[css(aliases = "foo,bar")]` can be used to alias a value with another
|
||||
/// * `#[parse(aliases = "foo,bar")]` can be used to alias a value with another
|
||||
/// at parse-time.
|
||||
///
|
||||
/// * `#[css(parse_condition = "function")]` can be used to make the parsing of
|
||||
/// the value conditional on `function`, which will be invoked with a
|
||||
/// `&ParserContext` reference.
|
||||
/// * `#[parse(condition = "function")]` can be used to make the parsing of the
|
||||
/// value conditional on `function`, which needs to fulfill
|
||||
/// `fn(&ParserContext) -> bool`.
|
||||
pub trait Parse: Sized {
|
||||
/// Parse a value of this type.
|
||||
///
|
||||
|
|
|
@ -594,7 +594,7 @@
|
|||
aliases.append(alias)
|
||||
%>
|
||||
% if aliases:
|
||||
#[css(aliases = "${','.join(aliases)}")]
|
||||
#[parse(aliases = "${','.join(aliases)}")]
|
||||
% endif
|
||||
% endif
|
||||
${to_camel_case(variant)},
|
||||
|
|
|
@ -53,9 +53,9 @@ pub enum Display {
|
|||
TableCaption,
|
||||
ListItem,
|
||||
None,
|
||||
#[css(aliases = "-webkit-flex")]
|
||||
#[parse(aliases = "-webkit-flex")]
|
||||
Flex,
|
||||
#[css(aliases = "-webkit-inline-flex")]
|
||||
#[parse(aliases = "-webkit-inline-flex")]
|
||||
InlineFlex,
|
||||
#[cfg(feature = "gecko")]
|
||||
Grid,
|
||||
|
@ -84,31 +84,31 @@ pub enum Display {
|
|||
#[cfg(feature = "gecko")]
|
||||
MozInlineBox,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozGrid,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozInlineGrid,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozGridGroup,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozGridLine,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozStack,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozInlineStack,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozDeck,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozPopup,
|
||||
#[cfg(feature = "gecko")]
|
||||
#[css(parse_condition = "moz_display_values_enabled")]
|
||||
#[parse(condition = "moz_display_values_enabled")]
|
||||
MozGroupbox,
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ pub fn derive_to_animated_value(stream: TokenStream) -> TokenStream {
|
|||
to_animated_value::derive(input).into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(Parse, attributes(css))]
|
||||
#[proc_macro_derive(Parse, attributes(css, parse))]
|
||||
pub fn derive_parse(stream: TokenStream) -> TokenStream {
|
||||
let input = syn::parse(stream).unwrap();
|
||||
parse::derive(input).into()
|
||||
|
@ -64,7 +64,7 @@ pub fn derive_to_css(stream: TokenStream) -> TokenStream {
|
|||
to_css::derive(input).into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(SpecifiedValueInfo, attributes(css, value_info))]
|
||||
#[proc_macro_derive(SpecifiedValueInfo, attributes(css, parse, value_info))]
|
||||
pub fn derive_specified_value_info(stream: TokenStream) -> TokenStream {
|
||||
let input = syn::parse(stream).unwrap();
|
||||
specified_value_info::derive(input).into()
|
||||
|
|
|
@ -4,10 +4,17 @@
|
|||
|
||||
use cg;
|
||||
use quote::Tokens;
|
||||
use syn::DeriveInput;
|
||||
use syn::{DeriveInput, Path};
|
||||
use synstructure;
|
||||
use to_css::CssVariantAttrs;
|
||||
|
||||
#[darling(attributes(parse), default)]
|
||||
#[derive(Default, FromVariant)]
|
||||
pub struct ParseVariantAttrs {
|
||||
pub aliases: Option<String>,
|
||||
pub condition: Option<Path>,
|
||||
}
|
||||
|
||||
pub fn derive(input: DeriveInput) -> Tokens {
|
||||
let name = &input.ident;
|
||||
let s = synstructure::Structure::new(&input);
|
||||
|
@ -20,18 +27,21 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
"Parse is only supported for single-variant enums for now"
|
||||
);
|
||||
|
||||
let variant_attrs = cg::parse_variant_attrs_from_ast::<CssVariantAttrs>(&variant.ast());
|
||||
if variant_attrs.skip {
|
||||
let css_variant_attrs =
|
||||
cg::parse_variant_attrs_from_ast::<CssVariantAttrs>(&variant.ast());
|
||||
let parse_attrs =
|
||||
cg::parse_variant_attrs_from_ast::<ParseVariantAttrs>(&variant.ast());
|
||||
if css_variant_attrs.skip {
|
||||
return match_body;
|
||||
}
|
||||
|
||||
let identifier = cg::to_css_identifier(
|
||||
&variant_attrs.keyword.unwrap_or(variant.ast().ident.as_ref().into()),
|
||||
&css_variant_attrs.keyword.unwrap_or(variant.ast().ident.as_ref().into()),
|
||||
);
|
||||
let ident = &variant.ast().ident;
|
||||
|
||||
saw_condition |= variant_attrs.parse_condition.is_some();
|
||||
let condition = match variant_attrs.parse_condition {
|
||||
saw_condition |= parse_attrs.condition.is_some();
|
||||
let condition = match parse_attrs.condition {
|
||||
Some(ref p) => quote! { if #p(context) },
|
||||
None => quote! { },
|
||||
};
|
||||
|
@ -41,7 +51,7 @@ pub fn derive(input: DeriveInput) -> Tokens {
|
|||
#identifier #condition => Ok(#name::#ident),
|
||||
};
|
||||
|
||||
let aliases = match variant_attrs.aliases {
|
||||
let aliases = match parse_attrs.aliases {
|
||||
Some(aliases) => aliases,
|
||||
None => return body,
|
||||
};
|
||||
|
|
|
@ -6,6 +6,7 @@ use cg;
|
|||
use quote::Tokens;
|
||||
use syn::{Data, DeriveInput, Fields, Ident, Type};
|
||||
use to_css::{CssFieldAttrs, CssInputAttrs, CssVariantAttrs};
|
||||
use parse::ParseVariantAttrs;
|
||||
|
||||
pub fn derive(mut input: DeriveInput) -> Tokens {
|
||||
let css_attrs = cg::parse_input_attrs::<CssInputAttrs>(&input);
|
||||
|
@ -33,10 +34,11 @@ pub fn derive(mut input: DeriveInput) -> Tokens {
|
|||
for v in e.variants.iter() {
|
||||
let css_attrs = cg::parse_variant_attrs::<CssVariantAttrs>(&v);
|
||||
let info_attrs = cg::parse_variant_attrs::<ValueInfoVariantAttrs>(&v);
|
||||
let parse_attrs = cg::parse_variant_attrs::<ParseVariantAttrs>(&v);
|
||||
if css_attrs.skip {
|
||||
continue;
|
||||
}
|
||||
if let Some(aliases) = css_attrs.aliases {
|
||||
if let Some(aliases) = parse_attrs.aliases {
|
||||
for alias in aliases.split(",") {
|
||||
values.push(alias.to_string());
|
||||
}
|
||||
|
|
|
@ -234,8 +234,6 @@ pub struct CssVariantAttrs {
|
|||
pub comma: bool,
|
||||
pub dimension: bool,
|
||||
pub keyword: Option<String>,
|
||||
pub aliases: Option<String>,
|
||||
pub parse_condition: Option<Path>,
|
||||
pub skip: bool,
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ pub type KeywordsCollectFn<'a> = &'a mut FnMut(&[&'static str]);
|
|||
/// name is listed in `collect_completion_keywords`.
|
||||
/// * If `#[css(skip)]` is found, the content inside the variant or
|
||||
/// field is ignored.
|
||||
/// * Values listed in `#[css(if_empty)]`, `#[css(aliases)]`, and
|
||||
/// * Values listed in `#[css(if_empty)]`, `#[parse(aliases)]`, and
|
||||
/// `#[css(keyword)]` are added into `collect_completion_keywords`.
|
||||
///
|
||||
/// In addition to `css` attributes, it also has `value_info` helper
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue