summaryrefslogtreecommitdiff
path: root/src/parser/parser.c
diff options
context:
space:
mode:
authorQuinn Stephens <quinn@osmora.org>2025-06-09 22:11:41 -0400
committerQuinn Stephens <quinn@osmora.org>2025-06-09 22:11:41 -0400
commit24522c8496c2661ba90b560bed0da482a85c3c8d (patch)
tree17b6896149d533a98be3f7bc37de15ef9d8b9fa3 /src/parser/parser.c
parentf25568b5830beb9a12709644f26d4fc12a8cad79 (diff)
parser: Parse pointer levels (e.g. void **)
Signed-off-by: Quinn Stephens <quinn@osmora.org>
Diffstat (limited to 'src/parser/parser.c')
-rw-r--r--src/parser/parser.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/parser/parser.c b/src/parser/parser.c
index ccdc037..b947ea2 100644
--- a/src/parser/parser.c
+++ b/src/parser/parser.c
@@ -96,6 +96,7 @@ static bool
parse_decl(struct parser *ctx)
{
struct type *type;
+ int ptr_levels;
struct ast_node *node;
/*
@@ -112,6 +113,12 @@ parse_decl(struct parser *ctx)
}
parser_advance(ctx);
+ ptr_levels = 0;
+ while (ctx->tok.kind == TOK_ASTERISK) {
+ ptr_levels++;
+ parser_advance(ctx);
+ }
+
if (ctx->tok.kind != TOK_IDENTIFIER) {
tok_error(&ctx->tok, "expected identifier after type\n");
return false;
@@ -127,7 +134,7 @@ parse_decl(struct parser *ctx)
node->name = ctx->tok.pos;
node->name_len = ctx->tok.len;
node->type = type;
- node->ptr_levels = 0;
+ node->ptr_levels = ptr_levels;
parser_advance(ctx);
if (ctx->tok.kind == TOK_LPAREN) {