diff --git a/src/frontend/parser.nim b/src/frontend/parser.nim index 5ebac51..5b52fd5 100644 --- a/src/frontend/parser.nim +++ b/src/frontend/parser.nim @@ -641,16 +641,14 @@ proc raiseStmt(self: Parser): Statement = proc forEachStmt(self: Parser): Statement = ## Parses C#-like foreach loops let tok = self.peek(-1) - var enclosingLoop = self.currentLoop + let enclosingLoop = self.currentLoop self.currentLoop = Loop - self.expect(LeftParen, "expecting '(' after 'foreach'") self.expect(Identifier) - var identifier = newIdentExpr(self.peek(-1), self.scopeDepth) + let identifier = newIdentExpr(self.peek(-1), self.scopeDepth) self.expect(":") - var expression = self.expression() - self.expect(RightParen) - var body = self.statement() - result = newForEachStmt(identifier, expression, body, tok) + let expression = self.expression() + self.expect(LeftBrace) + result = newForEachStmt(identifier, expression, self.blockStmt(), tok) self.currentLoop = enclosingLoop @@ -700,16 +698,15 @@ proc whileStmt(self: Parser): Statement = ## Parses a C-style while loop statement let tok = self.peek(-1) self.beginScope() - var enclosingLoop = self.currentLoop + let enclosingLoop = self.currentLoop + let condition = self.expression() + self.expect(LeftBrace) self.currentLoop = Loop - self.expect(LeftParen, "expecting '(' before while loop condition") - var condition = self.expression() - self.expect(RightParen, "unterminated while loop condition") - result = newWhileStmt(condition, self.statement(), tok) + result = newWhileStmt(condition, self.blockStmt(), tok) self.currentLoop = enclosingLoop self.endScope() - +#[ proc forStmt(self: Parser): Statement = ## Parses a C-style for loop self.beginScope() @@ -766,18 +763,18 @@ proc forStmt(self: Parser): Statement = result = body self.currentLoop = enclosingLoop self.endScope() +]# proc ifStmt(self: Parser): Statement = ## Parses if statements let tok = self.peek(-1) - self.expect(LeftParen, "expecting '(' before if condition") - var condition = self.expression() - self.expect(RightParen, "expecting ')' after if condition") - var thenBranch = self.statement() + let condition = self.expression() + self.expect(LeftBrace) + let thenBranch = self.blockStmt() var elseBranch: Statement if self.match(Else): - elseBranch = self.statement() + elseBranch = self.blockStmt() result = newIfStmt(condition, thenBranch, elseBranch, tok) @@ -1088,9 +1085,11 @@ proc statement(self: Parser): Statement = of While: discard self.step() result = self.whileStmt() + #[ of For: discard self.step() result = self.forStmt() + ]# of Foreach: discard self.step() result = self.forEachStmt() diff --git a/src/main.nim b/src/main.nim index b843905..df85b72 100644 --- a/src/main.nim +++ b/src/main.nim @@ -194,7 +194,7 @@ proc runFile(f: string, interactive: bool = false, fromString: bool = false) = tokenizer = newLexer() parser = newParser() compiler = newCompiler() - debugger = newDebugger() + debugger {.used.} = newDebugger() serializer = newSerializer() vm = newPeonVM() input: string