diff options
| author | Baitinq <[email protected]> | 2025-02-15 23:09:35 +0100 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-02-15 23:12:27 +0100 |
| commit | adfde11dd5495cbe28e7faba6dd14b48897b8b7b (patch) | |
| tree | 7c818a6892938a840dd35f7e631ba6bbb532075d /src | |
| parent | Codegen: depend on libc for entrypoint (diff) | |
| download | pry-lang-adfde11dd5495cbe28e7faba6dd14b48897b8b7b.tar.gz pry-lang-adfde11dd5495cbe28e7faba6dd14b48897b8b7b.tar.bz2 pry-lang-adfde11dd5495cbe28e7faba6dd14b48897b8b7b.zip | |
Codegen: start supporting types for function params
Diffstat (limited to 'src')
| -rw-r--r-- | src/parser.zig | 8 | ||||
| -rw-r--r-- | src/tokenizer.zig | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/parser.zig b/src/parser.zig index 7d71de3..2486662 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -57,6 +57,7 @@ pub const Node = union(enum) { }, IDENTIFIER: struct { name: []const u8, + type: ?[]const u8, }, }, FUNCTION_DEFINITION: struct { @@ -174,6 +175,7 @@ pub const Parser = struct { .PRIMARY_EXPRESSION = .{ .IDENTIFIER = .{ .name = try self.arena.dupe(u8, identifier.?.type.IDENTIFIER), + .type = null, }, }, }), @@ -370,6 +372,7 @@ pub const Parser = struct { .PRIMARY_EXPRESSION = .{ .IDENTIFIER = .{ .name = try self.arena.dupe(u8, identifier_token), + .type = null, }, }, }), @@ -410,7 +413,7 @@ pub const Parser = struct { } }); } - // FunctionParameters ::= IDENTIFIER ("," IDENTIFIER)* + // FunctionParameters ::= IDENTIFIER ":" IDENTIFIER ("," IDENTIFIER ":" IDENTIFIER)* fn parse_function_parameters(self: *Parser) ParserError![]*Node { errdefer if (!self.try_context) std.debug.print("Error parsing function parameters {any}\n", .{self.peek_token()}); @@ -423,11 +426,14 @@ pub const Parser = struct { } first = false; const ident = self.accept_token(tokenizer.TokenType.IDENTIFIER) orelse return node_list.items; + _ = try self.parse_token(tokenizer.TokenType.COLON); + const type_ident = try self.parse_token(tokenizer.TokenType.IDENTIFIER); try node_list.append(try self.create_node(.{ .PRIMARY_EXPRESSION = .{ .IDENTIFIER = .{ .name = try self.arena.dupe(u8, ident.type.IDENTIFIER), + .type = try self.arena.dupe(u8, type_ident.type.IDENTIFIER), }, }, })); diff --git a/src/tokenizer.zig b/src/tokenizer.zig index a955c65..908c016 100644 --- a/src/tokenizer.zig +++ b/src/tokenizer.zig @@ -30,6 +30,7 @@ pub const TokenType = union(enum) { // Punctuation SEMICOLON: void, COMMA: void, + COLON: void, LPAREN: void, RPAREN: void, LBRACE: void, @@ -72,6 +73,7 @@ pub const Tokenizer = struct { if (self.accept_string("=>")) return self.create_token(.{ .ARROW = void{} }); if (self.accept_string(";")) return self.create_token(.{ .SEMICOLON = void{} }); if (self.accept_string(",")) return self.create_token(.{ .COMMA = void{} }); + if (self.accept_string(":")) return self.create_token(.{ .COLON = void{} }); if (self.accept_string("(")) return self.create_token(.{ .LPAREN = void{} }); if (self.accept_string(")")) return self.create_token(.{ .RPAREN = void{} }); if (self.accept_string("{")) return self.create_token(.{ .LBRACE = void{} }); |