Improved error handling for declarations inside functions
This commit is contained in:
parent
7194e937fb
commit
3b08932403
|
@ -735,8 +735,8 @@ proc forStmt(self: Parser): ASTNode =
|
||||||
self.expect(RightParen, "unterminated for loop condition")
|
self.expect(RightParen, "unterminated for loop condition")
|
||||||
var body = self.statement()
|
var body = self.statement()
|
||||||
if increment != nil:
|
if increment != nil:
|
||||||
# The increment runs at each iteration, so we
|
# The increment runs after each iteration, so we
|
||||||
# inject it into the block as the first statement
|
# inject it into the block as the last statement
|
||||||
body = newBlockStmt(@[body, increment], tok)
|
body = newBlockStmt(@[body, increment], tok)
|
||||||
if condition == nil:
|
if condition == nil:
|
||||||
## An empty condition is functionally
|
## An empty condition is functionally
|
||||||
|
@ -778,6 +778,10 @@ proc varDecl(self: Parser, isStatic: bool = true, isPrivate: bool = true): ASTNo
|
||||||
keyword = "constant"
|
keyword = "constant"
|
||||||
else:
|
else:
|
||||||
keyword = "variable"
|
keyword = "variable"
|
||||||
|
if not isStatic and self.currentFunction != nil:
|
||||||
|
self.error("dynamic declarations are illegal inside functions")
|
||||||
|
if not isPrivate and self.currentFunction != nil:
|
||||||
|
self.error("public declarations are illegal inside functions")
|
||||||
self.expect(Identifier, &"expecting {keyword} name after '{varKind.lexeme}'")
|
self.expect(Identifier, &"expecting {keyword} name after '{varKind.lexeme}'")
|
||||||
var name = newIdentExpr(self.peek(-1))
|
var name = newIdentExpr(self.peek(-1))
|
||||||
if self.match(Equal):
|
if self.match(Equal):
|
||||||
|
|
Loading…
Reference in New Issue