Move around clones on selectors

This commit is contained in:
ConnorSkees 2020-01-05 20:55:58 -05:00
parent 61a6b5eeeb
commit 362a9b4ca2

View File

@ -137,26 +137,24 @@ impl<'a> SelectorParser<'a> {
fn consume_selector(&mut self) -> Option<Selector> { fn consume_selector(&mut self) -> Option<Selector> {
if let Some(tok) = self.tokens.next() { if let Some(tok) = self.tokens.next() {
let selector = match tok.kind { let selector = match &tok.kind {
TokenKind::Symbol(Symbol::Period) => match self TokenKind::Symbol(Symbol::Period) => match self
.tokens .tokens
.next() .next()
.expect("expected ident after `.`") .expect("expected ident after `.`")
.clone()
.kind .kind
{ {
TokenKind::Ident(tok) => Selector::Class(tok), TokenKind::Ident(ref tok) => Selector::Class(tok.clone()),
_ => todo!("there should normally be an ident after `.`"), _ => todo!("there should normally be an ident after `.`"),
}, },
TokenKind::Symbol(Symbol::Mul) => Selector::Universal, TokenKind::Symbol(Symbol::Mul) => Selector::Universal,
TokenKind::Symbol(Symbol::Hash) => match self TokenKind::Symbol(Symbol::Hash) => match &self
.tokens .tokens
.next() .next()
.expect("expected ident after `#`") .expect("expected ident after `#`")
.clone()
.kind .kind
{ {
TokenKind::Ident(tok) => Selector::Id(tok), TokenKind::Ident(ref tok) => Selector::Id(tok.clone()),
_ => todo!("there should normally be an ident after `#`"), _ => todo!("there should normally be an ident after `#`"),
}, },
TokenKind::Symbol(Symbol::Colon) => { TokenKind::Symbol(Symbol::Colon) => {
@ -164,15 +162,14 @@ impl<'a> SelectorParser<'a> {
.tokens .tokens
.next() .next()
.expect("expected ident after `:`") .expect("expected ident after `:`")
.clone()
.kind .kind
{ {
TokenKind::Ident(tok) => Selector::Pseudo(tok), TokenKind::Ident(ref tok) => Selector::Pseudo(tok.clone()),
_ => todo!("there should normally be an ident after `:`"), _ => todo!("there should normally be an ident after `:`"),
} }
} }
TokenKind::Ident(ref tok) => Selector::Element(tok.clone()), TokenKind::Ident(tok) => Selector::Element(tok.clone()),
TokenKind::Selector(ref sel) => sel.clone(), TokenKind::Selector(sel) => sel.clone(),
_ => todo!(), _ => todo!(),
}; };
Some(selector) Some(selector)