diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-11-12 01:40:31 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-12 01:40:31 +0000 |
| commit | 5502160bd23f14b91ac2bd3726a93bdd0b40cc53 (patch) | |
| tree | 81ced0f54f4c02eb7fd3bdd5d3d1248014f356a6 /src/parser.cpp | |
| parent | ae0a219d1f5495acc4d82421fa24d84186c2a40d (diff) | |
| parent | 0c315e7f7613b085a203e9c94d222e846b5b9e46 (diff) | |
| download | zig-5502160bd23f14b91ac2bd3726a93bdd0b40cc53.tar.gz zig-5502160bd23f14b91ac2bd3726a93bdd0b40cc53.zip | |
Merge pull request #3652 from ziglang/anon-container-lit
implement anonymous struct literals and anonymous list literals
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index a1ece3ed10..484e145cfa 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -81,7 +81,7 @@ static AstNode *ast_parse_for_type_expr(ParseContext *pc); static AstNode *ast_parse_while_type_expr(ParseContext *pc); static AstNode *ast_parse_switch_expr(ParseContext *pc); static AstNode *ast_parse_asm_expr(ParseContext *pc); -static AstNode *ast_parse_enum_lit(ParseContext *pc); +static AstNode *ast_parse_anon_lit(ParseContext *pc); static AstNode *ast_parse_asm_output(ParseContext *pc); static AsmOutput *ast_parse_asm_output_item(ParseContext *pc); static AstNode *ast_parse_asm_input(ParseContext *pc); @@ -1600,9 +1600,9 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) { if (container_decl != nullptr) return container_decl; - AstNode *enum_lit = ast_parse_enum_lit(pc); - if (enum_lit != nullptr) - return enum_lit; + AstNode *anon_lit = ast_parse_anon_lit(pc); + if (anon_lit != nullptr) + return anon_lit; AstNode *error_set_decl = ast_parse_error_set_decl(pc); if (error_set_decl != nullptr) @@ -1876,16 +1876,22 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc) { return res; } -static AstNode *ast_parse_enum_lit(ParseContext *pc) { +static AstNode *ast_parse_anon_lit(ParseContext *pc) { Token *period = eat_token_if(pc, TokenIdDot); if (period == nullptr) return nullptr; - Token *identifier = expect_token(pc, TokenIdSymbol); - AstNode *res = ast_create_node(pc, NodeTypeEnumLiteral, period); - res->data.enum_literal.period = period; - res->data.enum_literal.identifier = identifier; - return res; + // anon enum literal + Token *identifier = eat_token_if(pc, TokenIdSymbol); + if (identifier != nullptr) { + AstNode *res = ast_create_node(pc, NodeTypeEnumLiteral, period); + res->data.enum_literal.period = period; + res->data.enum_literal.identifier = identifier; + return res; + } + + // anon container literal + return ast_parse_init_list(pc); } // AsmOutput <- COLON AsmOutputList AsmInput? |
