Merge pull request #5339 from GabrielDertoni/fix-repl-panic

fix: repl panic on empty line
This commit is contained in:
Ayaz 2023-05-01 12:50:54 -05:00 committed by GitHub
commit d3a40b651b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,25 +96,7 @@ impl ReplState {
let arena = Bump::new();
match parse_src(&arena, line) {
ParseOutcome::Empty => {
if line.is_empty() {
Ok(TIPS.to_string())
} else if line.ends_with('\n') {
// After two blank lines in a row, give up and try parsing it
// even though it's going to fail. This way you don't get stuck
// in a perpetual Incomplete state due to a syntax error.
Ok(self.eval_and_format(line, dimensions))
} else {
// The previous line wasn't blank, but the line isn't empty either.
// This could mean that, for example, you're writing a multiline `when`
// and want to add a blank line. No problem! Print a blank line and
// continue waiting for input.
//
// If the user presses enter again, next time prev_line_blank() will be true
// and we'll try parsing the source as-is.
Ok("\n".to_string())
}
}
ParseOutcome::Empty => Ok(TIPS.to_string()),
ParseOutcome::Expr(_)
| ParseOutcome::ValueDef(_)
| ParseOutcome::TypeDef(_)