Files
RustPython/vm/src/error.rs
holygits 4453c3e561 Create error types for parser and compiler
Pass through locations and tokens in ParseError
2019-02-14 10:21:21 +13:00

37 lines
1020 B
Rust

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
}
}