diff options
author | Mathias Magnusson <mathias@magnusson.space> | 2025-07-29 15:03:26 +0200 |
---|---|---|
committer | Mathias Magnusson <mathias@magnusson.space> | 2025-07-29 15:03:26 +0200 |
commit | 15984567e8187f529fbe649109ef83bba309a2d8 (patch) | |
tree | 9b7882f873eaf0a8c968fc34c925002cb2182964 /src/parse.zig | |
parent | 0fa2f445eb7140214471074fc544adfd0f8a524f (diff) | |
download | huginn-15984567e8187f529fbe649109ef83bba309a2d8.tar.gz |
continue continuing procedure calls
Diffstat (limited to 'src/parse.zig')
-rw-r--r-- | src/parse.zig | 21 |
1 files changed, 17 insertions, 4 deletions
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, .{ |