diff options
-rw-r--r-- | components/selectors/Cargo.toml | 1 | ||||
-rw-r--r-- | components/selectors/README.md | 6 | ||||
-rw-r--r-- | components/selectors/attr.rs | 25 | ||||
-rw-r--r-- | components/selectors/build.rs | 2 | ||||
-rw-r--r-- | components/selectors/builder.rs | 10 | ||||
-rw-r--r-- | components/selectors/lib.rs | 19 | ||||
-rw-r--r-- | components/selectors/matching.rs | 2 | ||||
-rw-r--r-- | components/selectors/parser.rs | 61 | ||||
-rw-r--r-- | components/selectors/visitor.rs | 1 |
9 files changed, 58 insertions, 69 deletions
diff --git a/components/selectors/Cargo.toml b/components/selectors/Cargo.toml index e1726a312cd..f447a18f4d5 100644 --- a/components/selectors/Cargo.toml +++ b/components/selectors/Cargo.toml @@ -9,7 +9,6 @@ readme = "README.md" keywords = ["css", "selectors"] license = "MPL-2.0" build = "build.rs" -edition = "2018" [lib] name = "selectors" diff --git a/components/selectors/README.md b/components/selectors/README.md index ed30873a31f..dac4a7ff91a 100644 --- a/components/selectors/README.md +++ b/components/selectors/README.md @@ -1,11 +1,13 @@ rust-selectors ============== -* [Documentation](https://docs.rs/selectors) +* []( + https://travis-ci.com/servo/rust-selectors) +* [Documentation](https://docs.rs/selectors/) * [crates.io](https://crates.io/crates/selectors) CSS Selectors library for Rust. -Includes parsing and serialization of selectors, +Includes parsing and serilization of selectors, as well as matching against a generic tree of elements. Pseudo-elements and most pseudo-classes are generic as well. diff --git a/components/selectors/attr.rs b/components/selectors/attr.rs index ff4d2c561d6..e3122ea701e 100644 --- a/components/selectors/attr.rs +++ b/components/selectors/attr.rs @@ -5,19 +5,16 @@ use crate::parser::SelectorImpl; use cssparser::ToCss; use std::fmt; -#[cfg(feature = "shmem")] -use to_shmem_derive::ToShmem; -#[derive(Clone, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] -#[cfg_attr(feature = "shmem", shmem(no_bounds))] +#[derive(Clone, Eq, PartialEq, ToShmem)] +#[shmem(no_bounds)] pub struct AttrSelectorWithOptionalNamespace<Impl: SelectorImpl> { - #[cfg_attr(feature = "shmem", shmem(field_bound))] + #[shmem(field_bound)] pub namespace: Option<NamespaceConstraint<(Impl::NamespacePrefix, Impl::NamespaceUrl)>>, - #[cfg_attr(feature = "shmem", shmem(field_bound))] + #[shmem(field_bound)] pub local_name: Impl::LocalName, pub local_name_lower: Impl::LocalName, - #[cfg_attr(feature = "shmem", shmem(field_bound))] + #[shmem(field_bound)] pub operation: ParsedAttrSelectorOperation<Impl::AttrValue>, } @@ -30,8 +27,7 @@ impl<Impl: SelectorImpl> AttrSelectorWithOptionalNamespace<Impl> { } } -#[derive(Clone, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] +#[derive(Clone, Eq, PartialEq, ToShmem)] pub enum NamespaceConstraint<NamespaceUrl> { Any, @@ -39,8 +35,7 @@ pub enum NamespaceConstraint<NamespaceUrl> { Specific(NamespaceUrl), } -#[derive(Clone, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] +#[derive(Clone, Eq, PartialEq, ToShmem)] pub enum ParsedAttrSelectorOperation<AttrValue> { Exists, WithValue { @@ -80,8 +75,7 @@ impl<AttrValue> AttrSelectorOperation<AttrValue> { } } -#[derive(Clone, Copy, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] +#[derive(Clone, Copy, Eq, PartialEq, ToShmem)] pub enum AttrSelectorOperator { Equal, Includes, @@ -146,8 +140,7 @@ impl AttrSelectorOperator { /// The definition of whitespace per CSS Selectors Level 3 § 4. pub static SELECTOR_WHITESPACE: &[char] = &[' ', '\t', '\n', '\r', '\x0C']; -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] +#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)] pub enum ParsedCaseSensitivity { /// 's' was specified. ExplicitCaseSensitive, diff --git a/components/selectors/build.rs b/components/selectors/build.rs index a4b07b3d430..c5c3803991e 100644 --- a/components/selectors/build.rs +++ b/components/selectors/build.rs @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +extern crate phf_codegen; + use std::env; use std::fs::File; use std::io::{BufWriter, Write}; diff --git a/components/selectors/builder.rs b/components/selectors/builder.rs index 3539032b35e..63a6323c532 100644 --- a/components/selectors/builder.rs +++ b/components/selectors/builder.rs @@ -19,16 +19,12 @@ use crate::parser::{Combinator, Component, RelativeSelector, Selector, SelectorImpl}; use crate::sink::Push; -use bitflags::bitflags; -use derive_more::{Add, AddAssign}; use servo_arc::{Arc, HeaderWithLength, ThinArc}; use smallvec::{self, SmallVec}; use std::cmp; use std::iter; use std::ptr; use std::slice; -#[cfg(feature = "shmem")] -use to_shmem_derive::ToShmem; /// Top-level SelectorBuilder struct. This should be stack-allocated by the /// consumer and never moved (because it contains a lot of inline data that @@ -182,8 +178,7 @@ fn split_from_end<T>(s: &[T], at: usize) -> (&[T], &[T]) { bitflags! { /// Flags that indicate at which point of parsing a selector are we. - #[derive(Default)] - #[cfg_attr(feature = "shmem", derive(ToShmem))] + #[derive(Default, ToShmem)] pub (crate) struct SelectorFlags : u8 { const HAS_PSEUDO = 1 << 0; const HAS_SLOTTED = 1 << 1; @@ -192,8 +187,7 @@ bitflags! { } } -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] +#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)] pub struct SpecificityAndFlags { /// There are two free bits here, since we use ten bits for each specificity /// kind (id, class, element). diff --git a/components/selectors/lib.rs b/components/selectors/lib.rs index 17f81c535b6..d71d3c84876 100644 --- a/components/selectors/lib.rs +++ b/components/selectors/lib.rs @@ -5,6 +5,25 @@ // Make |cargo bench| work. #![cfg_attr(feature = "bench", feature(test))] +#[macro_use] +extern crate bitflags; +#[macro_use] +extern crate cssparser; +#[macro_use] +extern crate debug_unreachable; +#[macro_use] +extern crate derive_more; +extern crate fxhash; +#[macro_use] +extern crate log; +extern crate phf; +extern crate precomputed_hash; +extern crate servo_arc; +extern crate smallvec; +extern crate to_shmem; +#[macro_use] +extern crate to_shmem_derive; + pub mod attr; pub mod bloom; mod builder; diff --git a/components/selectors/matching.rs b/components/selectors/matching.rs index 05704923b60..83bc878797a 100644 --- a/components/selectors/matching.rs +++ b/components/selectors/matching.rs @@ -15,8 +15,6 @@ use crate::parser::{ }; use crate::tree::Element; use bitflags::bitflags; -use debug_unreachable::debug_unreachable; -use log::debug; use smallvec::SmallVec; use std::borrow::Borrow; use std::iter; diff --git a/components/selectors/parser.rs b/components/selectors/parser.rs index f9017b95b9b..2c44da8018e 100644 --- a/components/selectors/parser.rs +++ b/components/selectors/parser.rs @@ -14,21 +14,17 @@ use crate::sink::Push; use crate::visitor::SelectorListKind; pub use crate::visitor::SelectorVisitor; use bitflags::bitflags; -use cssparser::{match_ignore_ascii_case, parse_nth}; +use cssparser::parse_nth; use cssparser::{BasicParseError, BasicParseErrorKind, ParseError, ParseErrorKind}; use cssparser::{CowRcStr, Delimiter, SourceLocation}; use cssparser::{Parser as CssParser, ToCss, Token}; -use debug_unreachable::debug_unreachable; use precomputed_hash::PrecomputedHash; use servo_arc::{HeaderWithLength, ThinArc, UniqueArc}; -use size_of_test::size_of_test; use smallvec::SmallVec; use std::borrow::{Borrow, Cow}; use std::fmt::{self, Debug}; use std::iter::Rev; use std::slice; -#[cfg(feature = "shmem")] -use to_shmem_derive::ToShmem; /// A trait that represents a pseudo-element. pub trait PseudoElement: Sized + ToCss { @@ -168,8 +164,6 @@ impl SelectorParsingState { pub type SelectorParseError<'i> = ParseError<'i, SelectorParseErrorKind<'i>>; -size_of_test!(SelectorParseError, 48); - #[derive(Clone, Debug, PartialEq)] pub enum SelectorParseErrorKind<'i> { NoQualifiedNameInAttributeSelector(Token<'i>), @@ -194,8 +188,6 @@ pub enum SelectorParseErrorKind<'i> { ClassNeedsIdent(Token<'i>), } -size_of_test!(SelectorParseErrorKind, 40); - macro_rules! with_all_bounds { ( [ $( $InSelector: tt )* ] @@ -298,9 +290,6 @@ pub trait Parser<'i> { true } - /// Parses non-tree-structural pseudo-classes. Tree structural pseudo-classes, - /// like `:first-child`, are built into this library. - /// /// This function can return an "Err" pseudo-element in order to support CSS2.1 /// pseudo-elements. fn parse_non_ts_pseudo_class( @@ -363,11 +352,10 @@ pub trait Parser<'i> { } } -#[derive(Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] -#[cfg_attr(feature = "shmem", shmem(no_bounds))] +#[derive(Clone, Debug, Eq, PartialEq, ToShmem)] +#[shmem(no_bounds)] pub struct SelectorList<Impl: SelectorImpl>( - #[cfg_attr(feature = "shmem", shmem(field_bound))] pub SmallVec<[Selector<Impl>; 1]>, + #[shmem(field_bound)] pub SmallVec<[Selector<Impl>; 1]>, ); /// Whether or not we're using forgiving parsing mode @@ -643,12 +631,10 @@ pub fn namespace_empty_string<Impl: SelectorImpl>() -> Impl::NamespaceUrl { /// /// This reordering doesn't change the semantics of selector matching, and we /// handle it in to_css to make it invisible to serialization. -#[derive(Clone, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] -#[cfg_attr(feature = "shmem", shmem(no_bounds))] +#[derive(Clone, Eq, PartialEq, ToShmem)] +#[shmem(no_bounds)] pub struct Selector<Impl: SelectorImpl>( - #[cfg_attr(feature = "shmem", shmem(field_bound))] - ThinArc<SpecificityAndFlags, Component<Impl>>, + #[shmem(field_bound)] ThinArc<SpecificityAndFlags, Component<Impl>>, ); impl<Impl: SelectorImpl> Selector<Impl> { @@ -1299,8 +1285,7 @@ impl<'a, Impl: SelectorImpl> Iterator for AncestorIter<'a, Impl> { } } -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] +#[derive(Clone, Copy, Debug, Eq, PartialEq, ToShmem)] pub enum Combinator { Child, // > Descendant, // space @@ -1541,10 +1526,10 @@ impl CombinatorComposition { for combinator in CombinatorIter::new(inner_selector.iter_skip_relative_selector_anchor()) { match combinator { Combinator::Descendant | Combinator::Child => { - result.insert(CombinatorComposition::DESCENDANTS); + result.insert(Self::DESCENDANTS); }, Combinator::NextSibling | Combinator::LaterSibling => { - result.insert(CombinatorComposition::SIBLINGS); + result.insert(Self::SIBLINGS); }, Combinator::Part | Combinator::PseudoElement | Combinator::SlotAssignment => { continue @@ -1637,17 +1622,16 @@ impl<Impl: SelectorImpl> RelativeSelector<Impl> { /// optimal packing and cache performance, see [1]. /// /// [1] https://bugzilla.mozilla.org/show_bug.cgi?id=1357973 -#[derive(Clone, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] -#[cfg_attr(feature = "shmem", shmem(no_bounds))] +#[derive(Clone, Eq, PartialEq, ToShmem)] +#[shmem(no_bounds)] pub enum Component<Impl: SelectorImpl> { LocalName(LocalName<Impl>), - ID(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::Identifier), - Class(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::Identifier), + ID(#[shmem(field_bound)] Impl::Identifier), + Class(#[shmem(field_bound)] Impl::Identifier), AttributeInNoNamespaceExists { - #[cfg_attr(feature = "shmem", shmem(field_bound))] + #[shmem(field_bound)] local_name: Impl::LocalName, local_name_lower: Impl::LocalName, }, @@ -1655,7 +1639,7 @@ pub enum Component<Impl: SelectorImpl> { AttributeInNoNamespace { local_name: Impl::LocalName, operator: AttrSelectorOperator, - #[cfg_attr(feature = "shmem", shmem(field_bound))] + #[shmem(field_bound)] value: Impl::AttrValue, case_sensitivity: ParsedCaseSensitivity, }, @@ -1680,7 +1664,7 @@ pub enum Component<Impl: SelectorImpl> { ParentSelector, Nth(NthSelectorData), NthOf(NthOfSelectorData<Impl>), - NonTSPseudoClass(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::NonTSPseudoClass), + NonTSPseudoClass(#[shmem(field_bound)] Impl::NonTSPseudoClass), /// The ::slotted() pseudo-element: /// /// https://drafts.csswg.org/css-scoping/#slotted-pseudo @@ -1695,7 +1679,7 @@ pub enum Component<Impl: SelectorImpl> { Slotted(Selector<Impl>), /// The `::part` pseudo-element. /// https://drafts.csswg.org/css-shadow-parts/#part - Part(#[cfg_attr(feature = "shmem", shmem(field_bound))] Box<[Impl::Identifier]>), + Part(#[shmem(field_bound)] Box<[Impl::Identifier]>), /// The `:host` pseudo-class: /// /// https://drafts.csswg.org/css-scoping/#host-selector @@ -1726,7 +1710,7 @@ pub enum Component<Impl: SelectorImpl> { /// Same comment as above re. the argument. Has(Box<[RelativeSelector<Impl>]>), /// An implementation-dependent pseudo-element selector. - PseudoElement(#[cfg_attr(feature = "shmem", shmem(field_bound))] Impl::PseudoElement), + PseudoElement(#[shmem(field_bound)] Impl::PseudoElement), Combinator(Combinator), @@ -1886,11 +1870,10 @@ impl<Impl: SelectorImpl> Component<Impl> { } } -#[derive(Clone, Eq, PartialEq)] -#[cfg_attr(feature = "shmem", derive(ToShmem))] -#[cfg_attr(feature = "shmem", shmem(no_bounds))] +#[derive(Clone, Eq, PartialEq, ToShmem)] +#[shmem(no_bounds)] pub struct LocalName<Impl: SelectorImpl> { - #[cfg_attr(feature = "shmem", shmem(field_bound))] + #[shmem(field_bound)] pub name: Impl::LocalName, pub lower_name: Impl::LocalName, } diff --git a/components/selectors/visitor.rs b/components/selectors/visitor.rs index 8b9e3ac3966..785c12813a6 100644 --- a/components/selectors/visitor.rs +++ b/components/selectors/visitor.rs @@ -8,7 +8,6 @@ use crate::attr::NamespaceConstraint; use crate::parser::{Combinator, Component, Selector, SelectorImpl}; -use bitflags::bitflags; /// A trait to visit selector properties. /// |