Minor changes to how await/yield expressions are parsed

This commit is contained in:
Nocturn9x 2022-04-06 15:57:47 +02:00
parent ce82517f14
commit 6500dd632e
1 changed files with 3 additions and 2 deletions

View File

@ -275,7 +275,8 @@ proc primary(self: Parser): ASTNode =
let tok = self.step()
if self.currentFunction == nil:
self.error("'yield' cannot be used outside functions")
elif self.currentFunction.kind == lambdaExpr or not FunDecl(self.currentFunction).isGenerator:
elif self.currentFunction.token.kind != Generator:
# It's easier than doing conversions for lambda/funDecl
self.error("'yield' cannot be used outside generators")
if not self.check([RightBrace, RightBracket, RightParen, Comma, Semicolon]):
# Expression delimiters
@ -287,7 +288,7 @@ proc primary(self: Parser): ASTNode =
let tok = self.step()
if self.currentFunction == nil:
self.error("'await' cannot be used outside functions")
if self.currentFunction.kind == lambdaExpr or not FunDecl(self.currentFunction).isAsync:
if self.currentFunction.token.kind != Coroutine:
self.error("'await' can only be used inside coroutines")
result = newAwaitExpr(self.expression(), tok)
of RightParen, RightBracket, RightBrace: