aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-09-05 21:55:07 -0400
committerAndrew Kelley <andrew@ziglang.org>2019-09-05 21:55:32 -0400
commit0a3c6dbda92931eba055c2c6447b7a4412408f17 (patch)
tree86d98cd519e628c28efe2fe9e2ff3ec86f55246d /src/parser.cpp
parentca70ca7e26aaae3425dad3a2b179f544bacf45e3 (diff)
downloadzig-0a3c6dbda92931eba055c2c6447b7a4412408f17.tar.gz
zig-0a3c6dbda92931eba055c2c6447b7a4412408f17.zip
implement `noasync` function calls
See #3157
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index ba8757e4ae..96071daa07 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -113,7 +113,7 @@ static AstNode *ast_parse_multiply_op(ParseContext *pc);
static AstNode *ast_parse_prefix_op(ParseContext *pc);
static AstNode *ast_parse_prefix_type_op(ParseContext *pc);
static AstNode *ast_parse_suffix_op(ParseContext *pc);
-static AstNode *ast_parse_fn_call_argumnets(ParseContext *pc);
+static AstNode *ast_parse_fn_call_arguments(ParseContext *pc);
static AstNode *ast_parse_array_type_start(ParseContext *pc);
static AstNode *ast_parse_ptr_type_start(ParseContext *pc);
static AstNode *ast_parse_container_decl_auto(ParseContext *pc);
@@ -1403,12 +1403,14 @@ static AstNode *ast_parse_error_union_expr(ParseContext *pc) {
}
// SuffixExpr
-// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
+// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
+// / KEYWORD_noasync PrimaryTypeExpr SuffixOp* FnCallArguments
// / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
- Token *async_token = eat_token_if(pc, TokenIdKeywordAsync);
- if (async_token != nullptr) {
- if (eat_token_if(pc, TokenIdKeywordFn) != nullptr) {
+ Token *async_token = eat_token(pc);
+ bool is_async = async_token->id == TokenIdKeywordAsync;
+ if (is_async || async_token->id == TokenIdKeywordNoAsync) {
+ if (is_async && eat_token_if(pc, TokenIdKeywordFn) != nullptr) {
// HACK: If we see the keyword `fn`, then we assume that
// we are parsing an async fn proto, and not a call.
// We therefore put back all tokens consumed by the async
@@ -1447,24 +1449,24 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
child = suffix;
}
- // TODO: Both *_async_prefix and *_fn_call_argumnets returns an
+ // TODO: Both *_async_prefix and *_fn_call_arguments returns an
// AstNode *. All we really want here is the arguments of
// the call we parse. We therefor "leak" the node for now.
// Wait till we get async rework to fix this.
- AstNode *args = ast_parse_fn_call_argumnets(pc);
+ AstNode *args = ast_parse_fn_call_arguments(pc);
if (args == nullptr)
ast_invalid_token_error(pc, peek_token(pc));
assert(args->type == NodeTypeFnCallExpr);
AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async_token);
- res->data.fn_call_expr.is_async = true;
+ res->data.fn_call_expr.modifier = is_async ? CallModifierAsync : CallModifierNoAsync;
res->data.fn_call_expr.seen = false;
res->data.fn_call_expr.fn_ref_expr = child;
res->data.fn_call_expr.params = args->data.fn_call_expr.params;
- res->data.fn_call_expr.is_builtin = false;
return res;
}
+ put_back_token(pc);
AstNode *res = ast_parse_primary_type_expr(pc);
if (res == nullptr)
@@ -1496,7 +1498,7 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
continue;
}
- AstNode * call = ast_parse_fn_call_argumnets(pc);
+ AstNode * call = ast_parse_fn_call_arguments(pc);
if (call != nullptr) {
assert(call->type == NodeTypeFnCallExpr);
call->data.fn_call_expr.fn_ref_expr = res;
@@ -1552,7 +1554,7 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
name = buf_create_from_str("export");
}
- AstNode *res = ast_expect(pc, ast_parse_fn_call_argumnets);
+ AstNode *res = ast_expect(pc, ast_parse_fn_call_arguments);
AstNode *name_sym = ast_create_node(pc, NodeTypeSymbol, token);
name_sym->data.symbol_expr.symbol = name;
@@ -1560,7 +1562,7 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
res->line = at_sign->start_line;
res->column = at_sign->start_column;
res->data.fn_call_expr.fn_ref_expr = name_sym;
- res->data.fn_call_expr.is_builtin = true;
+ res->data.fn_call_expr.modifier = CallModifierBuiltin;
return res;
}
@@ -2672,7 +2674,7 @@ static AstNode *ast_parse_suffix_op(ParseContext *pc) {
}
// FnCallArguments <- LPAREN ExprList RPAREN
-static AstNode *ast_parse_fn_call_argumnets(ParseContext *pc) {
+static AstNode *ast_parse_fn_call_arguments(ParseContext *pc) {
Token *paren = eat_token_if(pc, TokenIdLParen);
if (paren == nullptr)
return nullptr;