remove some panicking

This commit is contained in:
ConnorSkees 2020-05-17 00:08:50 -04:00
parent eb2f3ebe5a
commit 6e7f1cc319
3 changed files with 13 additions and 3 deletions

View File

@ -326,7 +326,10 @@ pub(crate) fn eat_expr<I: Iterator<Item = Token>>(
} }
} }
'@' => { '@' => {
toks.next(); let span = toks.next().unwrap().pos();
if toks.peek().is_none() {
return Err(("Expected identifier.", span).into());
}
let Spanned { node: ident, span } = eat_ident(toks, scope, super_selector)?; let Spanned { node: ident, span } = eat_ident(toks, scope, super_selector)?;
devour_whitespace(toks); devour_whitespace(toks);
let rule = AtRule::from_tokens( let rule = AtRule::from_tokens(

View File

@ -885,8 +885,10 @@ impl Value {
} }
} }
';' | '}' | '{' => return None, ';' | '}' | '{' => return None,
':' | '?' | ')' | '@' => return Some(Err(("expected \";\".", span).into())), ':' | '?' | ')' | '@' | '^' => return Some(Err(("expected \";\".", span).into())),
v if v.is_control() => return Some(Err(("Expected expression.", span).into())), v if v as u32 >= 0x80 || v.is_control() => {
return Some(Err(("Expected expression.", span).into()))
}
v => todo!("unexpected token in value parsing: {:?}", v), v => todo!("unexpected token in value parsing: {:?}", v),
})) }))
} }

View File

@ -57,3 +57,8 @@ error!(
no_value_after_forward_slash, no_value_after_forward_slash,
"a {color: 303/;}", "Error: Expected expression." "a {color: 303/;}", "Error: Expected expression."
); );
error!(xor_in_value, "a {color: a^;}", "Error: expected \";\".");
error!(
nothing_after_at_sign,
"a {color: red; @", "Error: Expected identifier."
);