diff options
Diffstat (limited to 'src/parse.c')
-rw-r--r-- | src/parse.c | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/parse.c b/src/parse.c index fda8dfd..87588e1 100644 --- a/src/parse.c +++ b/src/parse.c @@ -896,12 +896,24 @@ static bool parse_union(struct lexer *lexer, struct type *out) if (!match(lexer, T_UNION)) { return false; } + + out->desc.un.tag_type = NULL; + if (match(lexer, T_LPAREN)) { + out->desc.un.tag_type = must_malloc(sizeof(struct type)); + if (!parse_type(lexer, out->desc.un.tag_type)) { + error(lex_loc(lexer), "syntax error: expected type"); + } + + if (!match(lexer, T_RPAREN)) { + error(lex_loc(lexer), "syntax error: expected ')'"); + } + } + if (!match(lexer, T_LBRACE)) { error(lex_loc(lexer), "syntax error: expected '{'"); } out->kind = TYP_UNION; - out->desc.un.tag_type = NULL; out->desc.un.alts = must_calloc(1, sizeof(struct type)); out->desc.un.altsz = 1; out->desc.un.altlen = 0; |