diff options
Diffstat (limited to 'src/parse.zig')
-rw-r--r-- | src/parse.zig | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/parse.zig b/src/parse.zig index 8347687..e675fbe 100644 --- a/src/parse.zig +++ b/src/parse.zig @@ -45,12 +45,18 @@ pub const Stmt = struct { expr: *const Expr, assign_var: AssignVar, block: Block, + @"while": While, pub const AssignVar = struct { ident: Lexer.Location, is_decl: bool, value: *const Expr, }; + + pub const While = struct { + cond: *const Expr, + do: Block, + }; }; fn format(self: Stmt, writer: anytype, source: []const u8, indent: usize) !void { @@ -63,6 +69,10 @@ pub const Stmt = struct { assign_var.ident.getIdent(source), fmt(assign_var.value, source, indent), }), + .@"while" => |@"while"| try writer.print("while {} {}", .{ + fmt(@"while".cond, source, indent), + fmt(@"while".do, source, indent), + }), }; } }; @@ -165,6 +175,18 @@ pub fn statement(allocator: Allocator, lexer: *Lexer) ParseError!Stmt { .type = .{ .block = b }, }; }, + .@"while" => { + const @"while" = lexer.next(); + const cond = try expression(allocator, lexer); + const do = try block(allocator, lexer); + return .{ + .loc = @"while".loc.combine(do.loc), + .type = .{ .@"while" = .{ + .cond = cond, + .do = do, + } }, + }; + }, else => { const lhs = try expression(allocator, lexer); if (lexer.peek().type == .equal) { |