diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-04-18 22:21:54 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-04-18 22:21:54 -0400 |
| commit | 06909ceaab8ecb33d1f41049870797a3ae721610 (patch) | |
| tree | 921bdc2b695512725e60e028521cef2d386c93da /src/parser.cpp | |
| parent | ca4341f7ba845e7af3c6f2be52cd60c51ec6d68f (diff) | |
| download | zig-06909ceaab8ecb33d1f41049870797a3ae721610.tar.gz zig-06909ceaab8ecb33d1f41049870797a3ae721610.zip | |
support break in suspend blocks
* you can label suspend blocks
* labeled break supports suspend blocks
See #803
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 2bd94033cc..4b70e904b8 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -648,12 +648,30 @@ static AstNode *ast_parse_asm_expr(ParseContext *pc, size_t *token_index, bool m } /* -SuspendExpression(body) = "suspend" "|" Symbol "|" body +SuspendExpression(body) = option(Symbol ":") "suspend" option(("|" Symbol "|" body)) */ static AstNode *ast_parse_suspend_block(ParseContext *pc, size_t *token_index, bool mandatory) { size_t orig_token_index = *token_index; - Token *suspend_token = &pc->tokens->at(*token_index); + Token *name_token = nullptr; + Token *token = &pc->tokens->at(*token_index); + if (token->id == TokenIdSymbol) { + *token_index += 1; + Token *colon_token = &pc->tokens->at(*token_index); + if (colon_token->id == TokenIdColon) { + *token_index += 1; + name_token = token; + token = &pc->tokens->at(*token_index); + } else if (mandatory) { + ast_expect_token(pc, colon_token, TokenIdColon); + zig_unreachable(); + } else { + *token_index = orig_token_index; + return nullptr; + } + } + + Token *suspend_token = token; if (suspend_token->id == TokenIdKeywordSuspend) { *token_index += 1; } else if (mandatory) { @@ -675,6 +693,9 @@ static AstNode *ast_parse_suspend_block(ParseContext *pc, size_t *token_index, b } AstNode *node = ast_create_node(pc, NodeTypeSuspend, suspend_token); + if (name_token != nullptr) { + node->data.suspend.name = token_buf(name_token); + } node->data.suspend.promise_symbol = ast_parse_symbol(pc, token_index); ast_eat_token(pc, token_index, TokenIdBinOr); node->data.suspend.block = ast_parse_block(pc, token_index, true); |
