Pass ParseError location to CompileError

This commit is contained in:
Aviv Palivoda 2019-07-06 10:23:32 +03:00
parent f4a94903b3
commit 9f068a3146

View file

@ -1,4 +1,4 @@
use rustpython_parser::error::ParseError;
use rustpython_parser::error::{ParseError, ParseErrorType};
use rustpython_parser::lexer::Location;
use std::error::Error;
@ -13,8 +13,8 @@ pub struct CompileError {
impl From<ParseError> for CompileError {
fn from(error: ParseError) -> Self {
CompileError {
error: CompileErrorType::Parse(error),
location: Default::default(), // TODO: extract location from parse error!
error: CompileErrorType::Parse(error.error),
location: error.location,
}
}
}
@ -28,7 +28,7 @@ pub enum CompileErrorType {
/// Expected an expression got a statement
ExpectExpr,
/// Parser error
Parse(ParseError),
Parse(ParseErrorType),
SyntaxError(String),
/// Multiple `*` detected
StarArgs,
@ -56,10 +56,7 @@ impl fmt::Display for CompileError {
}?;
// Print line number:
match &self.error {
CompileErrorType::Parse(..) => Ok(()),
_ => write!(f, " at line {:?}", self.location.row()),
}
write!(f, " at {}", self.location)
}
}