Chromium Code Reviews| Index: runtime/vm/parser.cc |
| diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc |
| index f7db62fa973ae6feac63732acdd0e390194e6428..aceee41c555af9d6887674a31a7fefbd32196ecb 100644 |
| --- a/runtime/vm/parser.cc |
| +++ b/runtime/vm/parser.cc |
| @@ -286,6 +286,7 @@ Parser::Parser(const Script& script, const Library& library, intptr_t token_pos) |
| token_kind_(Token::kILLEGAL), |
| current_block_(NULL), |
| is_top_level_(false), |
| + await_is_keyword_(false), |
| current_member_(NULL), |
| allow_function_literals_(true), |
| parsed_function_(NULL), |
| @@ -312,6 +313,7 @@ Parser::Parser(const Script& script, |
| token_kind_(Token::kILLEGAL), |
| current_block_(NULL), |
| is_top_level_(false), |
| + await_is_keyword_(false), |
| current_member_(NULL), |
| allow_function_literals_(true), |
| parsed_function_(parsed_function), |
| @@ -2957,6 +2959,11 @@ SequenceNode* Parser::ParseFunc(const Function& func, |
| OpenAsyncClosure(); |
| } |
| + // For async functions and their inner closures parse "await" as a keyword. |
| + if (func.IsAsyncFunction() || func.is_async_closure()) { |
| + await_is_keyword_ = true; |
| + } |
| + |
| intptr_t end_token_pos = 0; |
| if (CurrentToken() == Token::kLBRACE) { |
| ConsumeToken(); |
| @@ -3025,6 +3032,7 @@ SequenceNode* Parser::ParseFunc(const Function& func, |
| current_block_->statements->Add(body); |
| innermost_function_ = saved_innermost_function.raw(); |
| last_used_try_index_ = saved_try_index; |
| + await_is_keyword_ = false; |
|
hausner
2014/08/26 22:48:06
Interesting. Why are you setting this flag to fals
Michael Lippautz (Google)
2014/08/26 23:01:44
As discussed offline: Need for parsing nested func
|
| return CloseBlock(); |
| } |
| @@ -6255,9 +6263,14 @@ bool Parser::IsSimpleLiteral(const AbstractType& type, Instance* value) { |
| } |
| -// Returns true if the current token is kIDENT or a pseudo-keyword. |
| +// Returns true if the current token is |
| +// * kIDENT, |
| +// * or a pseudo-keyword, |
| +// * or is not the literal "await" in an async function. |
| bool Parser::IsIdentifier() { |
| - return Token::IsIdentifier(CurrentToken()); |
| + return Token::IsIdentifier(CurrentToken()) && |
| + (!await_is_keyword_ || |
| + (CurrentLiteral()->raw() != Symbols::Await().raw())); |
| } |
| @@ -8454,11 +8467,12 @@ AstNode* Parser::ParseAwaitableExpr(bool require_compiletime_const, |
| // function. |
| return expr; |
| } |
| - SequenceNode* intermediates_block = new(I) SequenceNode( |
| - Scanner::kNoSourcePos, current_block_->scope); |
| - AwaitTransformer at(intermediates_block, library_, parsed_function()); |
| + OpenBlock(); |
| + AwaitTransformer at(current_block_->statements, |
| + library_, |
| + parsed_function()); |
| AstNode* result = at.Transform(expr); |
| - current_block_->statements->Add(intermediates_block); |
| + current_block_->statements->Add(CloseBlock()); |
| parsed_function()->reset_have_seen_await(); |
| return result; |
| } |
| @@ -10843,7 +10857,7 @@ AstNode* Parser::ParsePrimary() { |
| OpenBlock(); |
| primary = ParseFunctionStatement(true); |
| CloseBlock(); |
| - } else if (IsLiteral("await") && |
| + } else if ((CurrentLiteral()->raw() == Symbols::Await().raw()) && |
| (parsed_function()->function().IsAsyncFunction() || |
| parsed_function()->function().is_async_closure())) { |
| // The body of an async function is parsed multiple times. The first time |