summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuinn Stephens <quinn@osmora.org>2024-11-03 09:31:07 -0500
committerQuinn Stephens <quinn@osmora.org>2024-11-03 09:31:07 -0500
commit388025e5a7d2d7997926c6a9af8767ca9ccb12bf (patch)
tree4e99c39d77a620d03700a845596379a8d4a3a142
parent774809f07cbbc8e5efdb30fbb7c06ed87d6c78ba (diff)
[parser] Refactor parse_type()
Switch statement makes more sense here. Signed-off-by: Quinn Stephens <quinn@osmora.org>
-rw-r--r--compiler/parser/type.c19
1 files changed, 11 insertions, 8 deletions
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) {