remove unwrap and todo! from attribute parsing
@@ -23,29 +23,22 @@ impl Attribute {
super_selector: &Selector,
) -> SassResult<SelectorKind> {
devour_whitespace(toks);
- let attr = if let Some(t) = toks.next() {
- match t.kind {
+ let attr = match toks.next().ok_or("Expected identifier.")?.kind {
v @ 'a'..='z' | v @ 'A'..='Z' | v @ '-' | v @ '_' => {
format!("{}{}", v, eat_ident(toks, scope, super_selector)?)
}
- '#' if toks.next().unwrap().kind == '{' => {
+ '#' if toks.next().ok_or("Expected expression.")?.kind == '{' => {
parse_interpolation(toks, scope, super_selector)?.to_string()
}
- q @ '"' | q @ '\'' => {
- parse_quoted_string(toks, scope, q, super_selector)?.to_string()
- }
+ q @ '"' | q @ '\'' => parse_quoted_string(toks, scope, q, super_selector)?.to_string(),
_ => return Err("Expected identifier.".into()),
- }
- } else {
- todo!()
};
devour_whitespace(toks);
- let kind = if let Some(t) = toks.next() {
- match t.kind {
+ let kind = match toks.next().ok_or("expected \"{\".")?.kind {
v @ 'a'..='z' | v @ 'A'..='Z' => {
- match toks.next().unwrap().kind {
+ match toks.next().ok_or("expected \"]\".")?.kind {
']' => {}
_ => return Err("expected \"]\".".into()),
}
@@ -71,13 +64,10 @@ impl Attribute {
'$' => AttributeKind::Suffix,
'*' => AttributeKind::Contains,
_ => return Err("Expected \"]\".".into()),
- }
- } else {
- todo!()
};
if kind != AttributeKind::Equals {
- match toks.next().unwrap().kind {
+ match toks.next().ok_or("expected \"=\".")?.kind {
'=' => {}
_ => return Err("expected \"=\".".into()),
}
@@ -85,24 +75,17 @@ impl Attribute {
devour_whitespace(toks);
- let value = if let Some(t) = toks.next() {
- match t.kind {
+ let value = match toks.next().ok_or("Expected identifier.")?.kind {
v @ 'a'..='z' | v @ 'A'..='Z' | v @ '-' | v @ '_' => {
format!("{}{}", v, eat_ident(toks, scope, super_selector)?)
}
- q @ '"' | q @ '\'' => {
- parse_quoted_string(toks, scope, q, super_selector)?.to_string()
- }
+ q @ '"' | q @ '\'' => parse_quoted_string(toks, scope, q, super_selector)?.to_string(),
_ => return Err("Expected identifier.".into()),
- }
- } else {
- todo!()
};
devour_whitespace(toks);
- let modifier = if let Some(t) = toks.next() {
- match t.kind {
+ let modifier = match toks.next().ok_or("expected \"]\".")?.kind {
']' => {
return Ok(SelectorKind::Attribute(Attribute {
kind,
@@ -112,16 +95,13 @@ impl Attribute {
}))
}
v @ 'a'..='z' | v @ 'A'..='Z' => {
- match toks.next().unwrap().kind {
+ match toks.next().ok_or("expected \"]\".")?.kind {
']' => {}
_ => return Err("expected \"]\".".into()),
}
Some(v)
}
_ => return Err("Expected \"]\".".into()),
- }
- } else {
- return Err("expected \"]\".".into());
};
Ok(SelectorKind::Attribute(Attribute {
