mirror of
https://github.com/RustPython/Parser.git
synced 2025-07-19 19:15:43 +00:00
CompilerError always contains source_path
This commit is contained in:
parent
fae42a0533
commit
1125a529e7
3 changed files with 35 additions and 47 deletions
27
src/error.rs
27
src/error.rs
|
@ -10,29 +10,22 @@ pub struct CompileError {
|
|||
pub statement: Option<String>,
|
||||
pub error: CompileErrorType,
|
||||
pub location: Location,
|
||||
pub source_path: Option<String>,
|
||||
pub source_path: String,
|
||||
}
|
||||
|
||||
impl CompileError {
|
||||
pub fn from_parse_error(parse_error: ParseError, source_path: String) -> Self {
|
||||
Self {
|
||||
statement: None,
|
||||
error: CompileErrorType::Parse(parse_error.error),
|
||||
location: parse_error.location,
|
||||
source_path,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_statement_info(&mut self, statement: String) {
|
||||
self.statement = Some(statement);
|
||||
}
|
||||
|
||||
pub fn update_source_path(&mut self, source_path: &str) {
|
||||
debug_assert!(self.source_path.is_none());
|
||||
self.source_path = Some(source_path.to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ParseError> for CompileError {
|
||||
fn from(error: ParseError) -> Self {
|
||||
CompileError {
|
||||
statement: None,
|
||||
error: CompileErrorType::Parse(error.error),
|
||||
location: error.location,
|
||||
source_path: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue