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