pub struct Group {
pub filters: Vec<Filter>,
pub root: Option<()>,
pub selectors: Vec<Selector>,
pub spread: Option<()>,
pub truncate: Option<()>,
}
Expand description
A Group is a set of grammar elements used to define a selection.
Fields§
§filters: Vec<Filter>
Filters.
root: Option<()>
Root marker.
selectors: Vec<Selector>
Selectors.
spread: Option<()>
Spread marker.
truncate: Option<()>
Truncate marker.
Implementations§
source§impl Group
impl Group
Group implementations.
sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new group.
Examples found in repository?
More examples
src/parser.rs (line 144)
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
pub fn selectors_parser(selectors: &str) -> Result<Vec<Group>, String> {
match GroupsParser::parse(Rule::groups, selectors) {
Ok(pairs) => {
let mut groups: Vec<Group> = Vec::new();
for pair in pairs {
let mut group = Group::new();
// Loop over the pairs converted as an iterator of the tokens
// which composed it.
for inner_pair in pair.into_inner() {
let inner_span = inner_pair.clone().as_span().as_str();
// Populate the group based on the rules found by the
// parser.
match inner_pair.as_rule() {
// Default
Rule::default => group
.selectors
.push(span_to_default(&get_chars_from_pair(inner_pair)[0].clone())),
Rule::filter_default => {
group.filters.push(Filter::Default(span_to_default(
&get_chars_from_pair(inner_pair.into_inner().next().unwrap())[0]
.clone(),
)))
}
// Index
Rule::index => group.selectors.push(span_to_index(inner_span)),
Rule::filter_index => group
.filters
.push(Filter::Default(span_to_index(inner_span))),
// Range
Rule::range => group.selectors.push(span_to_range(inner_pair)),
Rule::filter_range => group.filters.push(Filter::Default(span_to_range(
inner_pair.into_inner().next().unwrap(),
))),
// Property
Rule::property => group
.selectors
.push(Selector::Object(get_inner_object_from_pair(inner_pair))),
Rule::filter_property => group.filters.push(Filter::Default(
Selector::Object(get_inner_object_from_pair(inner_pair)),
)),
// Filter lens property.
Rule::filter_lens_property => group.filters.push(Filter::Lens(
Selector::Object(get_inner_object_from_pair(inner_pair)),
)),
// Root
Rule::root => group.root = Some(()),
// Spread
Rule::spread => group.spread = Some(()),
// Truncate
Rule::truncate => group.truncate = Some(()),
_ => (),
};
}
// Add the group.
groups.push(group);
}
Ok(groups)
}
Err(_) => Err(String::from("Error, unable to parse invalid selectors")),
}
}
Trait Implementations§
source§impl PartialEq<Group> for Group
impl PartialEq<Group> for Group
impl Eq for Group
impl StructuralEq for Group
impl StructuralPartialEq for Group
Auto Trait Implementations§
impl RefUnwindSafe for Group
impl Send for Group
impl Sync for Group
impl Unpin for Group
impl UnwindSafe for Group
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.