| 1274 | } |
| 1275 | |
| 1276 | Result WastParser::ParseModule(std::unique_ptr<Module>* out_module) { |
| 1277 | WABT_TRACE(ParseModule); |
| 1278 | auto module = std::make_unique<Module>(); |
| 1279 | module->filename = lexer_->Filename(); |
| 1280 | |
| 1281 | if (PeekMatchLpar(TokenType::Module)) { |
| 1282 | // Starts with "(module". Allow text and binary modules, but no quoted |
| 1283 | // modules. |
| 1284 | CommandPtr command; |
| 1285 | CHECK_RESULT(ParseModuleCommand(nullptr, &command)); |
| 1286 | if (isa<ModuleCommand>(command.get())) { |
| 1287 | auto module_command = cast<ModuleCommand>(std::move(command)); |
| 1288 | *module = std::move(module_command->module); |
| 1289 | } else { |
| 1290 | assert(isa<ScriptModuleCommand>(command.get())); |
| 1291 | auto module_command = cast<ScriptModuleCommand>(std::move(command)); |
| 1292 | *module = std::move(module_command->module); |
| 1293 | } |
| 1294 | } else if (IsModuleField(PeekPair()) || PeekIsCustom()) { |
| 1295 | // Parse an inline module (i.e. one with no surrounding (module)). |
| 1296 | CHECK_RESULT(ParseModuleFieldList(module.get())); |
| 1297 | } else if (PeekMatch(TokenType::Eof)) { |
| 1298 | errors_->emplace_back(ErrorLevel::Warning, GetLocation(), |
| 1299 | lexer_->Filename(), "empty module"); |
| 1300 | } else { |
| 1301 | ConsumeIfLpar(); |
| 1302 | ErrorExpected({"a module field", "a module"}); |
| 1303 | } |
| 1304 | |
| 1305 | EXPECT(Eof); |
| 1306 | if (!HasError()) { |
| 1307 | *out_module = std::move(module); |
| 1308 | return Result::Ok; |
| 1309 | } else { |
| 1310 | return Result::Error; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | Result WastParser::ParseScript(std::unique_ptr<Script>* out_script) { |
| 1315 | WABT_TRACE(ParseScript); |
no test coverage detected