From af25fbed39fac85d69cca0407ba5172f99d51538 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Thu, 5 Mar 2020 00:57:05 -0600 Subject: [PATCH] Fix syntax error tests --- compiler/src/compile.rs | 29 ----------------------------- compiler/src/error.rs | 4 ++++ compiler/src/output_stream.rs | 5 +++++ compiler/src/peephole.rs | 3 +++ parser/src/lexer.rs | 2 ++ 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/compiler/src/compile.rs b/compiler/src/compile.rs index f4d088c42..29a876f5f 100644 --- a/compiler/src/compile.rs +++ b/compiler/src/compile.rs @@ -562,8 +562,6 @@ impl Compiler { } match value { Some(v) => { -<<<<<<< Updated upstream -======= if self.ctx.func == FunctionContext::AsyncFunction && self.current_output().is_generator() { @@ -572,7 +570,6 @@ impl Compiler { statement.location.clone(), )); } ->>>>>>> Stashed changes self.compile_expression(v)?; } None => { @@ -1658,16 +1655,7 @@ impl Compiler { } Await { value } => { if self.ctx.func != FunctionContext::AsyncFunction { -<<<<<<< Updated upstream - return Err(CompileError { - statement: None, - error: CompileErrorType::InvalidAwait, - location: self.current_source_location.clone(), - source_path: None, - }); -======= return Err(self.error(CompileErrorType::InvalidAwait)); ->>>>>>> Stashed changes } self.compile_expression(value)?; self.emit(Instruction::GetAwaitable); @@ -1679,27 +1667,10 @@ impl Compiler { YieldFrom { value } => { match self.ctx.func { FunctionContext::NoFunction => { -<<<<<<< Updated upstream - return Err(CompileError { - statement: None, - error: CompileErrorType::InvalidYieldFrom, - location: self.current_source_location.clone(), - source_path: None, - }) - } - FunctionContext::AsyncFunction => { - return Err(CompileError { - statement: None, - error: CompileErrorType::AsyncYieldFrom, - location: self.current_source_location.clone(), - source_path: None, - }) -======= return Err(self.error(CompileErrorType::InvalidYieldFrom)) } FunctionContext::AsyncFunction => { return Err(self.error(CompileErrorType::AsyncYieldFrom)) ->>>>>>> Stashed changes } FunctionContext::Function => {} } diff --git a/compiler/src/error.rs b/compiler/src/error.rs index 2c8250136..6f28e3a33 100644 --- a/compiler/src/error.rs +++ b/compiler/src/error.rs @@ -57,6 +57,7 @@ pub enum CompileErrorType { InvalidYieldFrom, InvalidAwait, AsyncYieldFrom, + AsyncReturnValue, } impl CompileError { @@ -102,6 +103,9 @@ impl fmt::Display for CompileError { CompileErrorType::InvalidYieldFrom => "'yield from' outside function".to_owned(), CompileErrorType::InvalidAwait => "'await' outside async function".to_owned(), CompileErrorType::AsyncYieldFrom => "'yield from' inside async function".to_owned(), + CompileErrorType::AsyncReturnValue => { + "'return' with value inside async generator".to_owned() + } }; if let Some(statement) = &self.statement { diff --git a/compiler/src/output_stream.rs b/compiler/src/output_stream.rs index fa358817a..9cc49a944 100644 --- a/compiler/src/output_stream.rs +++ b/compiler/src/output_stream.rs @@ -7,6 +7,8 @@ pub trait OutputStream: From + Into { fn set_label(&mut self, label: Label); /// Mark the inner CodeObject as a generator fn mark_generator(&mut self); + /// Check to see if the inner CodeObject is a generator + fn is_generator(&self) -> bool; } pub struct CodeObjectStream { @@ -36,4 +38,7 @@ impl OutputStream for CodeObjectStream { fn mark_generator(&mut self) { self.code.flags |= CodeFlags::IS_GENERATOR; } + fn is_generator(&self) -> bool { + self.code.flags.contains(CodeFlags::IS_GENERATOR) + } } diff --git a/compiler/src/peephole.rs b/compiler/src/peephole.rs index b85266867..67a4b9efe 100644 --- a/compiler/src/peephole.rs +++ b/compiler/src/peephole.rs @@ -112,6 +112,9 @@ where fn mark_generator(&mut self) { self.inner.mark_generator() } + fn is_generator(&self) -> bool { + self.inner.is_generator() + } } impl OptimizationBuffer for PeepholeOptimizer { diff --git a/parser/src/lexer.rs b/parser/src/lexer.rs index d43dc37bb..b145588d6 100644 --- a/parser/src/lexer.rs +++ b/parser/src/lexer.rs @@ -685,6 +685,8 @@ where tabs = 0; } None => { + spaces = 0; + tabs = 0; break; } _ => {