Make from __future__ imports a syntactic construct in the compiler

This commit is contained in:
Noah 2020-02-07 21:31:58 +00:00
parent 330fdce246
commit a499fb775a
2 changed files with 52 additions and 0 deletions

View file

@ -58,6 +58,8 @@ pub enum CompileErrorType {
InvalidAwait,
AsyncYieldFrom,
AsyncReturnValue,
InvalidFuturePlacement,
InvalidFutureFeature(String),
}
impl CompileError {
@ -106,6 +108,12 @@ impl fmt::Display for CompileError {
CompileErrorType::AsyncReturnValue => {
"'return' with value inside async generator".to_owned()
}
CompileErrorType::InvalidFuturePlacement => {
"from __future__ imports must occur at the beginning of the file".to_owned()
}
CompileErrorType::InvalidFutureFeature(feat) => {
format!("future feature {} is not defined", feat)
}
};
if let Some(statement) = &self.statement {