Make use of Selector::None to remove Option<Selector> where possible
This commit is contained in:
parent
c615c5806c
commit
70b384c199
@ -188,7 +188,7 @@ pub struct RuleSet {
|
|||||||
selector: Selector,
|
selector: Selector,
|
||||||
rules: Vec<Stmt>,
|
rules: Vec<Stmt>,
|
||||||
// potential optimization: we don't *need* to own the selector
|
// potential optimization: we don't *need* to own the selector
|
||||||
super_selector: Option<Selector>,
|
super_selector: Selector,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
@ -328,7 +328,7 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
| TokenKind::Symbol(Symbol::Hash)
|
| TokenKind::Symbol(Symbol::Hash)
|
||||||
| TokenKind::Symbol(Symbol::Colon)
|
| TokenKind::Symbol(Symbol::Colon)
|
||||||
| TokenKind::Symbol(Symbol::Mul)
|
| TokenKind::Symbol(Symbol::Mul)
|
||||||
| TokenKind::Symbol(Symbol::Period) => rules.extend(self.eat_rules(&None)),
|
| TokenKind::Symbol(Symbol::Period) => rules.extend(self.eat_rules(Selector::None)),
|
||||||
TokenKind::Whitespace(_) | TokenKind::Symbol(_) => {
|
TokenKind::Whitespace(_) | TokenKind::Symbol(_) => {
|
||||||
self.lexer.next();
|
self.lexer.next();
|
||||||
continue;
|
continue;
|
||||||
@ -339,13 +339,13 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
StyleSheet { rules }
|
StyleSheet { rules }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn eat_rules(&mut self, super_selector: &Option<Selector>) -> Vec<Stmt> {
|
fn eat_rules(&mut self, super_selector: Selector) -> Vec<Stmt> {
|
||||||
let mut stmts = Vec::new();
|
let mut stmts = Vec::new();
|
||||||
while let Ok(tok) = self.eat_expr() {
|
while let Ok(tok) = self.eat_expr() {
|
||||||
match tok {
|
match tok {
|
||||||
Expr::Style(s) => stmts.push(Stmt::Style(s)),
|
Expr::Style(s) => stmts.push(Stmt::Style(s)),
|
||||||
Expr::Selector(s) => {
|
Expr::Selector(s) => {
|
||||||
let rules = self.eat_rules(&Some(s.clone()));
|
let rules = self.eat_rules(super_selector.clone().zip(s.clone()));
|
||||||
stmts.push(Stmt::RuleSet(RuleSet {
|
stmts.push(Stmt::RuleSet(RuleSet {
|
||||||
super_selector: super_selector.clone(),
|
super_selector: super_selector.clone(),
|
||||||
selector: s,
|
selector: s,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user