diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2020-04-25 17:49:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-25 17:49:06 +0100 |
| commit | a10d180d81b2d2c9cf7459c2f245642a124bb12f (patch) | |
| tree | 87e8168aabd3456f2f84b8eab7bbb557bcb2e2ed | |
| parent | f63b9806d24d347ab4c351f87797bd23e2834b5d (diff) | |
| parent | c704de844282b5899818518ed0fc0f96a4cfb5b8 (diff) | |
Merge pull request #627 from zhibog/master
Added #maybe to the builtin parser and ast for Unions
| -rw-r--r-- | core/odin/ast/ast.odin | 1 | ||||
| -rw-r--r-- | core/odin/parser/parser.odin | 5 |
2 files changed, 6 insertions, 0 deletions
diff --git a/core/odin/ast/ast.odin b/core/odin/ast/ast.odin index 80974b0a9..6d7d4f5c2 100644 --- a/core/odin/ast/ast.odin +++ b/core/odin/ast/ast.odin @@ -609,6 +609,7 @@ Union_Type :: struct { variants: []^Expr, where_token: tokenizer.Token, where_clauses: []^Expr, + is_maybe: bool, } Enum_Type :: struct { diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 93ecddbda..474a86672 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -2224,6 +2224,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr { tok := expect_token(p, .Union); poly_params: ^ast.Field_List; align: ^ast.Expr; + is_maybe: bool; if allow_token(p, .Open_Paren) { param_count: int; @@ -2244,6 +2245,9 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr { case "align": if align != nil do error(p, tag.pos, "duplicate union tag '#%s'", tag.text); align = parse_expr(p, true); + case "maybe": + if is_maybe do error(p, tag.pos, "duplicate union tag '#%s'", tag.text); + is_maybe = true; case: error(p, tag.pos, "invalid union tag '#%s", tag.text); } @@ -2282,6 +2286,7 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr { ut.align = align; ut.where_token = where_token; ut.where_clauses = where_clauses; + ut.is_maybe = is_maybe; return ut; |