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

Unified Diff: src/parser.cc

Issue 9422001: Make 'module' a context-sensitive keyword. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added missing CHECK_OK; rebased. Created 8 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/heap.h ('k') | src/scanner.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 3dfab294c8b4610c98c3db3edeac3469c8d767ba..f0556cb35531f2e3feea74bf7a708356ccea6d73 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -1188,14 +1188,28 @@ Statement* Parser::ParseModuleElement(ZoneStringList* labels,
case Token::LET:
case Token::CONST:
return ParseVariableStatement(kModuleElement, ok);
- case Token::MODULE:
- return ParseModuleDeclaration(ok);
case Token::IMPORT:
return ParseImportDeclaration(ok);
case Token::EXPORT:
return ParseExportDeclaration(ok);
- default:
- return ParseStatement(labels, ok);
+ default: {
+ Statement* stmt = ParseStatement(labels, CHECK_OK);
+ // Handle 'module' as a context-sensitive keyword.
+ if (FLAG_harmony_modules &&
+ peek() == Token::IDENTIFIER &&
+ !scanner().HasAnyLineTerminatorBeforeNext() &&
+ stmt != NULL) {
+ ExpressionStatement* estmt = stmt->AsExpressionStatement();
+ if (estmt != NULL &&
+ estmt->expression()->AsVariableProxy() != NULL &&
+ estmt->expression()->AsVariableProxy()->name()->Equals(
+ isolate()->heap()->module_symbol()) &&
+ !scanner().literal_contains_escapes()) {
Michael Starzinger 2012/02/24 12:31:05 As discussed offline ignoring escapes here is cons
+ return ParseModuleDeclaration(ok);
+ }
+ }
+ return stmt;
+ }
}
}
@@ -1206,7 +1220,6 @@ Block* Parser::ParseModuleDeclaration(bool* ok) {
// Create new block with one expected declaration.
Block* block = factory()->NewBlock(NULL, 1, true);
- Expect(Token::MODULE, CHECK_OK);
Handle<String> name = ParseIdentifier(CHECK_OK);
// top_scope_->AddDeclaration(
// factory()->NewModuleDeclaration(proxy, module, top_scope_));
@@ -2172,8 +2185,17 @@ Statement* Parser::ParseExpressionOrLabelledStatement(ZoneStringList* labels,
return ParseNativeDeclaration(ok);
}
- // Parsed expression statement.
- ExpectSemicolon(CHECK_OK);
+ // Parsed expression statement, or the context-sensitive 'module' keyword.
+ // Only expect semicolon in the former case.
+ if (!FLAG_harmony_modules ||
+ peek() != Token::IDENTIFIER ||
+ scanner().HasAnyLineTerminatorBeforeNext() ||
+ expr->AsVariableProxy() == NULL ||
+ !expr->AsVariableProxy()->name()->Equals(
+ isolate()->heap()->module_symbol()) ||
+ scanner().literal_contains_escapes()) {
Michael Starzinger 2012/02/24 12:19:16 A seven line condition. That's an achievement unlo
+ ExpectSemicolon(CHECK_OK);
+ }
return factory()->NewExpressionStatement(expr);
}
« no previous file with comments | « src/heap.h ('k') | src/scanner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698