diff options
| author | gingerBill <bill@gingerbill.org> | 2018-09-11 12:10:32 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2018-09-11 12:10:32 +0100 |
| commit | f1e1814ff91ab0753891536442797ff8544e6b6c (patch) | |
| tree | 52572629c86ee40763f3eb7346a478f5bacad31d /src/parser.cpp | |
| parent | b468cf141bdec09369ff8d2c28097ec7ead3c2f6 (diff) | |
Syntactic sugar for anonymous enum within a bit set
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index a162a4ee3..f029e7159 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2038,22 +2038,32 @@ Ast *parse_operand(AstFile *f, bool lhs) { case Token_bit_set: { Token token = expect_token(f, Token_bit_set); - Token open = expect_token(f, Token_OpenBracket); - Ast *elem = nullptr; - Ast *underlying = nullptr; + if (f->curr_token.kind == Token_OpenBrace) { + Token open = expect_token(f, Token_OpenBrace); - bool prev_allow_range = f->allow_range; - f->allow_range = true; - elem = parse_expr(f, false); - f->allow_range = prev_allow_range; - if (allow_token(f, Token_Semicolon)) { - underlying = parse_type(f); - } + Array<Ast *> values = parse_element_list(f); + Token close = expect_token(f, Token_CloseBrace); + Ast *enum_type = ast_enum_type(f, token, nullptr, values); + + return ast_bit_set_type(f, token, enum_type, nullptr); + } else { + expect_token(f, Token_OpenBracket); - Token close = expect_token(f, Token_CloseBracket); + Ast *elem = nullptr; + Ast *underlying = nullptr; - return ast_bit_set_type(f, token, elem, underlying); + bool prev_allow_range = f->allow_range; + f->allow_range = true; + elem = parse_expr(f, false); + f->allow_range = prev_allow_range; + if (allow_token(f, Token_Semicolon)) { + underlying = parse_type(f); + } + + expect_token(f, Token_CloseBracket); + return ast_bit_set_type(f, token, elem, underlying); + } } default: { |