Skip to content

Commit cdd9813

Browse files
committed
EOF after \\ raise EOF Error
Return EOF Error to get the next line after` \\ `in the shell. Closes RustPython#1928
1 parent 7c51a91 commit cdd9813

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

parser/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub enum LexicalErrorType {
2828
UnrecognizedToken { tok: char },
2929
FStringError(FStringErrorType),
3030
LineContinuationError,
31+
EOF,
3132
OtherError(String),
3233
}
3334

@@ -59,6 +60,7 @@ impl fmt::Display for LexicalErrorType {
5960
LexicalErrorType::LineContinuationError => {
6061
write!(f, "unexpected character after line continuation character")
6162
}
63+
LexicalErrorType::EOF => write!(f, "unexpected EOF while parsing"),
6264
LexicalErrorType::OtherError(msg) => write!(f, "{}", msg),
6365
}
6466
}

parser/src/lexer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,13 @@ where
11911191
location: self.get_pos(),
11921192
});
11931193
}
1194+
1195+
if self.chr0.is_none() {
1196+
return Err(LexicalError {
1197+
error: LexicalErrorType::EOF,
1198+
location: self.get_pos(),
1199+
});
1200+
}
11941201
}
11951202

11961203
_ => {

src/shell.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod helper;
22

33
use rustpython_compiler::{compile, error::CompileError, error::CompileErrorType};
4-
use rustpython_parser::error::ParseErrorType;
4+
use rustpython_parser::error::{LexicalErrorType, ParseErrorType};
55
use rustpython_vm::readline::{Readline, ReadlineResult};
66
use rustpython_vm::{
77
exceptions::{print_exception, PyBaseExceptionRef},
@@ -23,6 +23,10 @@ fn shell_exec(vm: &VirtualMachine, source: &str, scope: Scope) -> ShellExecResul
2323
Ok(_val) => ShellExecResult::Ok,
2424
Err(err) => ShellExecResult::PyErr(err),
2525
},
26+
Err(CompileError {
27+
error: CompileErrorType::Parse(ParseErrorType::Lexical(LexicalErrorType::EOF)),
28+
..
29+
}) => ShellExecResult::Continue,
2630
Err(CompileError {
2731
error: CompileErrorType::Parse(ParseErrorType::EOF),
2832
..

0 commit comments

Comments
 (0)