mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-10 10:02:38 +03:00
Merge pull request #5339 from GabrielDertoni/fix-repl-panic
fix: repl panic on empty line
This commit is contained in:
commit
d3a40b651b
@ -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(_)
|
||||
|
Loading…
Reference in New Issue
Block a user