aboutsummaryrefslogtreecommitdiff
path: root/src/parse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/parse.zig')
-rw-r--r--src/parse.zig21
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, .{