resolve hang on malformed input involving and and or

This commit is contained in:
ConnorSkees 2020-06-22 14:18:14 -04:00
parent eb6f0f3451
commit c700845174
3 changed files with 26 additions and 9 deletions

View File

@ -546,10 +546,12 @@ impl<'a> Parser<'a> {
}
';' | '}' | '{' => return None,
':' | '?' | ')' | '@' | '^' | ']' | '|' => {
return Some(Err(("expected \";\".", span).into()))
self.toks.next();
return Some(Err(("expected \";\".", span).into()));
}
'\u{0}'..='\u{8}' | '\u{b}'..='\u{1f}' | '\u{7f}'..=std::char::MAX | '`' | '~' => {
return Some(Err(("Expected expression.", span).into()))
self.toks.next();
return Some(Err(("Expected expression.", span).into()));
}
' ' | '\n' | '\t' => unreachable!("whitespace is checked prior to this match"),
'A'..='Z' | 'a'..='z' | '_' | '\\' => {
@ -1194,14 +1196,20 @@ impl<'a, 'b: 'a> IntermediateValueIterator<'a, 'b> {
if left.node.is_true(left.span)? {
// we explicitly ignore errors here as a workaround for short circuiting
while let Some(value) = self.peek() {
if let Ok(Spanned {
node: IntermediateValue::Comma,
..
}) = value
{
break;
match value {
Ok(Spanned {
node: IntermediateValue::Comma,
..
}) => break,
Ok(..) => {
self.next();
}
Err(..) => {
if let Some(v) = self.next() {
v?;
}
}
}
self.next();
}
space_separated.push(left);
} else {

View File

@ -56,3 +56,8 @@ test!(
"a {\n color: false and comparable(\"a\", \"b\");\n}\n",
"a {\n color: false;\n}\n"
);
error!(
#[ignore = "blocked on a rewrite of value eval"]
properly_bubbles_error_when_invalid_char_after_and,
"a {\n color: false and? foo;\n}\n", "Error: expected \";\"."
);

View File

@ -73,3 +73,7 @@ test!(
"a {\n color: true or red % foo, red;\n}\n",
"a {\n color: true, red;\n}\n"
);
error!(
properly_bubbles_error_when_invalid_char_after_or,
"a {\n color: true or? foo;\n}\n", "Error: expected \";\"."
);