Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: runtime/vm/parser.cc

Issue 232213003: Allow function literals in string interpolation (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/function_literals2_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/bootstrap.h" 9 #include "vm/bootstrap.h"
10 #include "vm/class_finalizer.h" 10 #include "vm/class_finalizer.h"
(...skipping 10305 matching lines...) Expand 10 before | Expand all | Expand 10 after
10316 } 10316 }
10317 has_interpolation = true; 10317 has_interpolation = true;
10318 AstNode* expr = NULL; 10318 AstNode* expr = NULL;
10319 const intptr_t expr_pos = TokenPos(); 10319 const intptr_t expr_pos = TokenPos();
10320 if (CurrentToken() == Token::kINTERPOL_VAR) { 10320 if (CurrentToken() == Token::kINTERPOL_VAR) {
10321 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true); 10321 expr = ResolveIdent(TokenPos(), *CurrentLiteral(), true);
10322 ConsumeToken(); 10322 ConsumeToken();
10323 } else { 10323 } else {
10324 ASSERT(CurrentToken() == Token::kINTERPOL_START); 10324 ASSERT(CurrentToken() == Token::kINTERPOL_START);
10325 ConsumeToken(); 10325 ConsumeToken();
10326 const bool saved_mode = SetAllowFunctionLiterals(true);
10326 expr = ParseExpr(kAllowConst, kConsumeCascades); 10327 expr = ParseExpr(kAllowConst, kConsumeCascades);
10328 SetAllowFunctionLiterals(saved_mode);
10327 ExpectToken(Token::kINTERPOL_END); 10329 ExpectToken(Token::kINTERPOL_END);
10328 } 10330 }
10329 // Check if this interpolated string is still considered a compile time 10331 // Check if this interpolated string is still considered a compile time
10330 // constant. If it is we need to evaluate if the current string part is 10332 // constant. If it is we need to evaluate if the current string part is
10331 // a constant or not. Only strings, numbers, booleans and null values 10333 // a constant or not. Only strings, numbers, booleans and null values
10332 // are allowed in compile time const interpolations. 10334 // are allowed in compile time const interpolations.
10333 if (is_compiletime_const) { 10335 if (is_compiletime_const) {
10334 const Object* const_expr = expr->EvalConstExpr(); 10336 const Object* const_expr = expr->EvalConstExpr();
10335 if ((const_expr != NULL) && 10337 if ((const_expr != NULL) &&
10336 (const_expr->IsNumber() || 10338 (const_expr->IsNumber() ||
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
10734 10736
10735 void Parser::SkipStringLiteral() { 10737 void Parser::SkipStringLiteral() {
10736 ASSERT(CurrentToken() == Token::kSTRING); 10738 ASSERT(CurrentToken() == Token::kSTRING);
10737 while (CurrentToken() == Token::kSTRING) { 10739 while (CurrentToken() == Token::kSTRING) {
10738 ConsumeToken(); 10740 ConsumeToken();
10739 while (true) { 10741 while (true) {
10740 if (CurrentToken() == Token::kINTERPOL_VAR) { 10742 if (CurrentToken() == Token::kINTERPOL_VAR) {
10741 ConsumeToken(); 10743 ConsumeToken();
10742 } else if (CurrentToken() == Token::kINTERPOL_START) { 10744 } else if (CurrentToken() == Token::kINTERPOL_START) {
10743 ConsumeToken(); 10745 ConsumeToken();
10746 const bool saved_mode = SetAllowFunctionLiterals(true);
10744 SkipExpr(); 10747 SkipExpr();
10748 SetAllowFunctionLiterals(saved_mode);
10745 ExpectToken(Token::kINTERPOL_END); 10749 ExpectToken(Token::kINTERPOL_END);
10746 } else { 10750 } else {
10747 break; 10751 break;
10748 } 10752 }
10749 } 10753 }
10750 } 10754 }
10751 } 10755 }
10752 10756
10753 10757
10754 void Parser::SkipPrimary() { 10758 void Parser::SkipPrimary() {
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
10915 void Parser::SkipQualIdent() { 10919 void Parser::SkipQualIdent() {
10916 ASSERT(IsIdentifier()); 10920 ASSERT(IsIdentifier());
10917 ConsumeToken(); 10921 ConsumeToken();
10918 if (CurrentToken() == Token::kPERIOD) { 10922 if (CurrentToken() == Token::kPERIOD) {
10919 ConsumeToken(); // Consume the kPERIOD token. 10923 ConsumeToken(); // Consume the kPERIOD token.
10920 ExpectIdentifier("identifier expected after '.'"); 10924 ExpectIdentifier("identifier expected after '.'");
10921 } 10925 }
10922 } 10926 }
10923 10927
10924 } // namespace dart 10928 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | tests/language/function_literals2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698