mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-08 05:35:22 +00:00
Pass ParseError location to CompileError
This commit is contained in:
parent
f4a94903b3
commit
9f068a3146
1 changed files with 5 additions and 8 deletions
13
src/error.rs
13
src/error.rs
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue