diff options
| author | gingerBill <bill@gingerbill.org> | 2019-07-09 10:28:13 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-07-09 10:28:13 +0100 |
| commit | 4ab9edeb53559f6ab6ef39a5ad9b45564d22aa8e (patch) | |
| tree | 02ece312f83cfb4e5b3873d88b64950369c883e0 /src/parser.cpp | |
| parent | c5b3d7a73640b3d3cbf3309cc2e61790a4901da6 (diff) | |
union #no_nil
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index ff6a03fb6..e262b3196 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -911,12 +911,13 @@ Ast *ast_struct_type(AstFile *f, Token token, Array<Ast *> fields, isize field_c } -Ast *ast_union_type(AstFile *f, Token token, Array<Ast *> variants, Ast *polymorphic_params, Ast *align) { +Ast *ast_union_type(AstFile *f, Token token, Array<Ast *> variants, Ast *polymorphic_params, Ast *align, bool no_nil) { Ast *result = alloc_ast_node(f, Ast_UnionType); result->UnionType.token = token; result->UnionType.variants = variants; result->UnionType.polymorphic_params = polymorphic_params; result->UnionType.align = align; + result->UnionType.no_nil = no_nil; return result; } @@ -1971,6 +1972,7 @@ Ast *parse_operand(AstFile *f, bool lhs) { auto variants = array_make<Ast *>(heap_allocator()); Ast *polymorphic_params = nullptr; Ast *align = nullptr; + bool no_nil = false; CommentGroup *docs = f->lead_comment; Token start_token = f->curr_token; @@ -1993,6 +1995,11 @@ Ast *parse_operand(AstFile *f, bool lhs) { syntax_error(tag, "Duplicate union tag '#%.*s'", LIT(tag.string)); } align = parse_expr(f, true); + } else if (tag.string == "no_nil") { + if (no_nil) { + syntax_error(tag, "Duplicate union tag '#%.*s'", LIT(tag.string)); + } + no_nil = true; } else { syntax_error(tag, "Invalid union tag '#%.*s'", LIT(tag.string)); } @@ -2013,7 +2020,7 @@ Ast *parse_operand(AstFile *f, bool lhs) { Token close = expect_token(f, Token_CloseBrace); - return ast_union_type(f, token, variants, polymorphic_params, align); + return ast_union_type(f, token, variants, polymorphic_params, align, no_nil); } break; case Token_enum: { |