mirror of
https://github.com/RustPython/Parser.git
synced 2025-09-12 21:36:17 +00:00
reorganize compiler crates
This commit is contained in:
parent
3351b4408b
commit
060d153bb3
82 changed files with 12368 additions and 164 deletions
101
src/error.rs
101
src/error.rs
|
@ -1,101 +0,0 @@
|
|||
use rustpython_ast::Location;
|
||||
|
||||
use std::{error::Error, fmt};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CompileError {
|
||||
pub error: CompileErrorType,
|
||||
pub location: Location,
|
||||
pub source_path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum CompileErrorType {
|
||||
/// Invalid assignment, cannot store value in target.
|
||||
Assign(&'static str),
|
||||
/// Invalid delete
|
||||
Delete(&'static str),
|
||||
SyntaxError(String),
|
||||
/// Multiple `*` detected
|
||||
MultipleStarArgs,
|
||||
/// Misplaced `*` expression
|
||||
InvalidStarExpr,
|
||||
/// Break statement outside of loop.
|
||||
InvalidBreak,
|
||||
/// Continue statement outside of loop.
|
||||
InvalidContinue,
|
||||
InvalidReturn,
|
||||
InvalidYield,
|
||||
InvalidYieldFrom,
|
||||
InvalidAwait,
|
||||
AsyncYieldFrom,
|
||||
AsyncReturnValue,
|
||||
InvalidFuturePlacement,
|
||||
InvalidFutureFeature(String),
|
||||
FunctionImportStar,
|
||||
TooManyStarUnpack,
|
||||
EmptyWithItems,
|
||||
EmptyWithBody,
|
||||
NotImplementedYet, // RustPython marker for unimplemented features
|
||||
}
|
||||
|
||||
impl fmt::Display for CompileErrorType {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
CompileErrorType::Assign(target) => write!(f, "cannot assign to {}", target),
|
||||
CompileErrorType::Delete(target) => write!(f, "cannot delete {}", target),
|
||||
CompileErrorType::SyntaxError(err) => write!(f, "{}", err.as_str()),
|
||||
CompileErrorType::MultipleStarArgs => {
|
||||
write!(f, "two starred expressions in assignment")
|
||||
}
|
||||
CompileErrorType::InvalidStarExpr => write!(f, "cannot use starred expression here"),
|
||||
CompileErrorType::InvalidBreak => write!(f, "'break' outside loop"),
|
||||
CompileErrorType::InvalidContinue => write!(f, "'continue' outside loop"),
|
||||
CompileErrorType::InvalidReturn => write!(f, "'return' outside function"),
|
||||
CompileErrorType::InvalidYield => write!(f, "'yield' outside function"),
|
||||
CompileErrorType::InvalidYieldFrom => write!(f, "'yield from' outside function"),
|
||||
CompileErrorType::InvalidAwait => write!(f, "'await' outside async function"),
|
||||
CompileErrorType::AsyncYieldFrom => write!(f, "'yield from' inside async function"),
|
||||
CompileErrorType::AsyncReturnValue => {
|
||||
write!(f, "'return' with value inside async generator")
|
||||
}
|
||||
CompileErrorType::InvalidFuturePlacement => write!(
|
||||
f,
|
||||
"from __future__ imports must occur at the beginning of the file"
|
||||
),
|
||||
CompileErrorType::InvalidFutureFeature(feat) => {
|
||||
write!(f, "future feature {} is not defined", feat)
|
||||
}
|
||||
CompileErrorType::FunctionImportStar => {
|
||||
write!(f, "import * only allowed at module level")
|
||||
}
|
||||
CompileErrorType::TooManyStarUnpack => {
|
||||
write!(f, "too many expressions in star-unpacking assignment")
|
||||
}
|
||||
CompileErrorType::EmptyWithItems => {
|
||||
write!(f, "empty items on With")
|
||||
}
|
||||
CompileErrorType::EmptyWithBody => {
|
||||
write!(f, "empty body on With")
|
||||
}
|
||||
CompileErrorType::NotImplementedYet => {
|
||||
write!(f, "RustPython does not implement this feature yet")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for CompileErrorType {}
|
||||
|
||||
impl fmt::Display for CompileError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{} at {}", self.error, self.location)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for CompileError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue