OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 1170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1181 // ModuleDeclaration | 1181 // ModuleDeclaration |
1182 // ImportDeclaration | 1182 // ImportDeclaration |
1183 // ExportDeclaration | 1183 // ExportDeclaration |
1184 | 1184 |
1185 switch (peek()) { | 1185 switch (peek()) { |
1186 case Token::FUNCTION: | 1186 case Token::FUNCTION: |
1187 return ParseFunctionDeclaration(ok); | 1187 return ParseFunctionDeclaration(ok); |
1188 case Token::LET: | 1188 case Token::LET: |
1189 case Token::CONST: | 1189 case Token::CONST: |
1190 return ParseVariableStatement(kModuleElement, ok); | 1190 return ParseVariableStatement(kModuleElement, ok); |
1191 case Token::MODULE: | |
1192 return ParseModuleDeclaration(ok); | |
1193 case Token::IMPORT: | 1191 case Token::IMPORT: |
1194 return ParseImportDeclaration(ok); | 1192 return ParseImportDeclaration(ok); |
1195 case Token::EXPORT: | 1193 case Token::EXPORT: |
1196 return ParseExportDeclaration(ok); | 1194 return ParseExportDeclaration(ok); |
1197 default: | 1195 default: { |
1198 return ParseStatement(labels, ok); | 1196 Statement* stmt = ParseStatement(labels, CHECK_OK); |
1197 // Handle 'module' as a context-sensitive keyword. | |
1198 if (FLAG_harmony_modules && | |
1199 peek() == Token::IDENTIFIER && | |
1200 !scanner().HasAnyLineTerminatorBeforeNext() && | |
1201 stmt != NULL) { | |
1202 ExpressionStatement* estmt = stmt->AsExpressionStatement(); | |
1203 if (estmt != NULL && | |
1204 estmt->expression()->AsVariableProxy() != NULL && | |
1205 estmt->expression()->AsVariableProxy()->name()->Equals( | |
1206 isolate()->heap()->module_symbol()) && | |
1207 !scanner().literal_contains_escapes()) { | |
Michael Starzinger
2012/02/24 12:31:05
As discussed offline ignoring escapes here is cons
| |
1208 return ParseModuleDeclaration(ok); | |
1209 } | |
1210 } | |
1211 return stmt; | |
1212 } | |
1199 } | 1213 } |
1200 } | 1214 } |
1201 | 1215 |
1202 | 1216 |
1203 Block* Parser::ParseModuleDeclaration(bool* ok) { | 1217 Block* Parser::ParseModuleDeclaration(bool* ok) { |
1204 // ModuleDeclaration: | 1218 // ModuleDeclaration: |
1205 // 'module' Identifier Module | 1219 // 'module' Identifier Module |
1206 | 1220 |
1207 // Create new block with one expected declaration. | 1221 // Create new block with one expected declaration. |
1208 Block* block = factory()->NewBlock(NULL, 1, true); | 1222 Block* block = factory()->NewBlock(NULL, 1, true); |
1209 Expect(Token::MODULE, CHECK_OK); | |
1210 Handle<String> name = ParseIdentifier(CHECK_OK); | 1223 Handle<String> name = ParseIdentifier(CHECK_OK); |
1211 // top_scope_->AddDeclaration( | 1224 // top_scope_->AddDeclaration( |
1212 // factory()->NewModuleDeclaration(proxy, module, top_scope_)); | 1225 // factory()->NewModuleDeclaration(proxy, module, top_scope_)); |
1213 VariableProxy* proxy = Declare(name, LET, NULL, true, CHECK_OK); | 1226 VariableProxy* proxy = Declare(name, LET, NULL, true, CHECK_OK); |
1214 Module* module = ParseModule(ok); | 1227 Module* module = ParseModule(ok); |
1215 // TODO(rossberg): Add initialization statement to block. | 1228 // TODO(rossberg): Add initialization statement to block. |
1216 USE(proxy); | 1229 USE(proxy); |
1217 USE(module); | 1230 USE(module); |
1218 return block; | 1231 return block; |
1219 } | 1232 } |
(...skipping 945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2165 peek() == Token::FUNCTION && | 2178 peek() == Token::FUNCTION && |
2166 !scanner().HasAnyLineTerminatorBeforeNext() && | 2179 !scanner().HasAnyLineTerminatorBeforeNext() && |
2167 expr != NULL && | 2180 expr != NULL && |
2168 expr->AsVariableProxy() != NULL && | 2181 expr->AsVariableProxy() != NULL && |
2169 expr->AsVariableProxy()->name()->Equals( | 2182 expr->AsVariableProxy()->name()->Equals( |
2170 isolate()->heap()->native_symbol()) && | 2183 isolate()->heap()->native_symbol()) && |
2171 !scanner().literal_contains_escapes()) { | 2184 !scanner().literal_contains_escapes()) { |
2172 return ParseNativeDeclaration(ok); | 2185 return ParseNativeDeclaration(ok); |
2173 } | 2186 } |
2174 | 2187 |
2175 // Parsed expression statement. | 2188 // Parsed expression statement, or the context-sensitive 'module' keyword. |
2176 ExpectSemicolon(CHECK_OK); | 2189 // Only expect semicolon in the former case. |
2190 if (!FLAG_harmony_modules || | |
2191 peek() != Token::IDENTIFIER || | |
2192 scanner().HasAnyLineTerminatorBeforeNext() || | |
2193 expr->AsVariableProxy() == NULL || | |
2194 !expr->AsVariableProxy()->name()->Equals( | |
2195 isolate()->heap()->module_symbol()) || | |
2196 scanner().literal_contains_escapes()) { | |
Michael Starzinger
2012/02/24 12:19:16
A seven line condition. That's an achievement unlo
| |
2197 ExpectSemicolon(CHECK_OK); | |
2198 } | |
2177 return factory()->NewExpressionStatement(expr); | 2199 return factory()->NewExpressionStatement(expr); |
2178 } | 2200 } |
2179 | 2201 |
2180 | 2202 |
2181 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { | 2203 IfStatement* Parser::ParseIfStatement(ZoneStringList* labels, bool* ok) { |
2182 // IfStatement :: | 2204 // IfStatement :: |
2183 // 'if' '(' Expression ')' Statement ('else' Statement)? | 2205 // 'if' '(' Expression ')' Statement ('else' Statement)? |
2184 | 2206 |
2185 Expect(Token::IF, CHECK_OK); | 2207 Expect(Token::IF, CHECK_OK); |
2186 Expect(Token::LPAREN, CHECK_OK); | 2208 Expect(Token::LPAREN, CHECK_OK); |
(...skipping 3593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5780 ASSERT(info->isolate()->has_pending_exception()); | 5802 ASSERT(info->isolate()->has_pending_exception()); |
5781 } else { | 5803 } else { |
5782 result = parser.ParseProgram(info); | 5804 result = parser.ParseProgram(info); |
5783 } | 5805 } |
5784 } | 5806 } |
5785 info->SetFunction(result); | 5807 info->SetFunction(result); |
5786 return (result != NULL); | 5808 return (result != NULL); |
5787 } | 5809 } |
5788 | 5810 |
5789 } } // namespace v8::internal | 5811 } } // namespace v8::internal |
OLD | NEW |