1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
5 //! Various macro helpers.
7 macro_rules! exclusive_value {
8 (($value:ident, $set:expr) => $ident:path) => {
9 if $value.intersects($set) {
17 #[cfg(feature = "gecko")]
18 macro_rules! impl_gecko_keyword_conversions {
19 ($name:ident, $utype:ty) => {
20 impl From<$utype> for $name {
21 fn from(bits: $utype) -> $name {
22 $name::from_gecko_keyword(bits)
26 impl From<$name> for $utype {
27 fn from(v: $name) -> $utype {
34 macro_rules! trivial_to_computed_value {
36 impl $crate::values::computed::ToComputedValue for $name {
37 type ComputedValue = $name;
39 fn to_computed_value(&self, _: &$crate::values::computed::Context) -> Self {
43 fn from_computed_value(other: &Self) -> Self {
50 /// A macro to parse an identifier, or return an `UnexpectedIdent` error
53 /// FIXME(emilio): The fact that `UnexpectedIdent` is a `SelectorParseError`
54 /// doesn't make a lot of sense to me.
55 macro_rules! try_match_ident_ignore_ascii_case {
56 ($input:expr, $( $match_body:tt )*) => {{
57 let location = $input.current_source_location();
58 let ident = $input.expect_ident_cloned()?;
59 match_ignore_ascii_case! { &ident,
61 _ => return Err(location.new_custom_error(
62 ::selectors::parser::SelectorParseErrorKind::UnexpectedIdent(ident.clone())
68 macro_rules! define_keyword_type {
69 ($name:ident, $css:expr) => {
70 #[allow(missing_docs)]
74 ComputeSquaredDistance,
88 impl fmt::Debug for $name {
89 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
94 impl $crate::parser::Parse for $name {
96 _context: &$crate::parser::ParserContext,
97 input: &mut ::cssparser::Parser<'i, 't>,
98 ) -> Result<$name, ::style_traits::ParseError<'i>> {
100 .expect_ident_matching($css)
102 .map_err(|e| e.into())
108 #[cfg(feature = "servo")]
109 macro_rules! local_name {
111 $crate::values::GenericAtomIdent(html5ever::local_name!($s))
115 #[cfg(feature = "servo")]
118 $crate::values::GenericAtomIdent(html5ever::ns!())
121 $crate::values::GenericAtomIdent(html5ever::ns!($s))
125 #[cfg(feature = "gecko")]
126 macro_rules! local_name {
128 $crate::values::AtomIdent(atom!($s))