forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.rs
More file actions
36 lines (32 loc) · 1020 Bytes
/
error.rs
File metadata and controls
36 lines (32 loc) · 1020 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use rustpython_parser::error::ParseError;
use std::error::Error;
use std::fmt;
#[derive(Debug)]
pub enum CompileError {
// Invalid assignment, cannot store value in target.
Assign(String),
// Invalid delete
Delete,
// Expected an expression got a statement
ExpectExpr,
// Parser error
Parse(ParseError),
// Multiple `*` detected
StarArgs,
}
impl fmt::Display for CompileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
CompileError::Assign(expr) => write!(f, "Invalid assignment: {}", expr),
CompileError::Delete => write!(f, "Invalid delete statement"),
CompileError::ExpectExpr => write!(f, "Expecting expression, got statement"),
CompileError::Parse(err) => err.fmt(f),
CompileError::StarArgs => write!(f, "Two starred expressions in assignment"),
}
}
}
impl Error for CompileError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
None
}
}