From 15984567e8187f529fbe649109ef83bba309a2d8 Mon Sep 17 00:00:00 2001 From: Mathias Magnusson Date: Tue, 29 Jul 2025 15:03:26 +0200 Subject: continue continuing procedure calls --- src/parse.zig | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/parse.zig') diff --git a/src/parse.zig b/src/parse.zig index bd0ca46..451b050 100644 --- a/src/parse.zig +++ b/src/parse.zig @@ -32,8 +32,9 @@ pub const File = struct { }; fn format(self: File, writer: anytype, source: []const u8, indent: usize) !void { - for (self.decls) |decl| { - try writer.print("{s} {s} {}", .{ + for (0.., self.decls) |i, decl| { + try writer.print("{s}{s} {s} {}\n", .{ + if (i == 0) "" else "\n", decl.inner.ident.getIdent(source), ":=", fmt(decl.inner.value, source, indent), @@ -182,6 +183,7 @@ const ParseError = error{ UnexpectedToken, InvalidAssignTarget, ExprStatementMustBeCall, + ExpectedCOmmaOrIdentifier, }; pub fn file(allocator: Allocator, lexer: *Lexer) !File { @@ -272,8 +274,19 @@ fn parseProc(allocator: Allocator, lexer: *Lexer) ParseError!*Expr { if (lexer.peek().type != .proc) return parseComparisons(allocator, lexer); const proc = try mustEat(lexer, .proc); _ = try mustEat(lexer, .left_paren); - // TODO: parameters - _ = try mustEat(lexer, .right_paren); + var params: std.ArrayList(Lexer.Location) = .init(allocator); + while (true) { + const tok = lexer.next(); + switch (tok.type) { + .right_paren => break, + .identifier => { + try params.append(tok.loc); + if (lexer.peek().type == .right_paren) continue; + _ = try mustEat(lexer, .comma); + }, + else => return error.ExpectedCOmmaOrIdentifier, + } + } const body = try parseBlock(allocator, lexer); return allocate(Expr, allocator, .{ -- cgit v1.2.3