From 388025e5a7d2d7997926c6a9af8767ca9ccb12bf Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Sun, 3 Nov 2024 09:31:07 -0500 Subject: [parser] Refactor parse_type() Switch statement makes more sense here. Signed-off-by: Quinn Stephens --- compiler/parser/type.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'compiler') diff --git a/compiler/parser/type.c b/compiler/parser/type.c index 4b961f0..b86ba9c 100644 --- a/compiler/parser/type.c +++ b/compiler/parser/type.c @@ -261,17 +261,20 @@ parse_type(struct parser *ctx) return; } - next_token(ctx); - if (ctx->tok.kind == TK_IDENTIFIER) { + switch (next_token(ctx)->kind) { + case TK_IDENTIFIER: success = parse_alias(ctx, typ); - } else if (ctx->tok.kind == TK_ENUM) { + break; + case TK_ENUM: success = parse_enum(ctx, typ); - } else if (ctx->tok.kind == TK_STRUCT) { + break; + case TK_STRUCT: success = parse_struct(ctx, typ); - } else { - tok_error(&ctx->tok, "expected type name or \"enum\" after \":\"\n"); - free(typ); - return; + break; + default: + tok_error(&ctx->tok, "expected identifier, \"enum\", or \"struct\" after \":\"\n"); + success = false; + break; } if (!success) { -- cgit v1.2.3