mirror of
https://github.com/RustPython/Parser.git
synced 2025-08-31 23:57:57 +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 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()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue