MCPcopy Create free account
hub / github.com/WebAssembly/wabt / ParseScript

Method ParseScript

src/wast-parser.cc:1314–1345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1312}
1313
1314Result WastParser::ParseScript(std::unique_ptr<Script>* out_script) {
1315 WABT_TRACE(ParseScript);
1316 auto script = std::make_unique<Script>();
1317 script->filename = lexer_->Filename();
1318
1319 // Don't consume the Lpar yet, even though it is required. This way the
1320 // sub-parser functions (e.g. ParseFuncModuleField) can consume it and keep
1321 // the parsing structure more regular.
1322 if (IsModuleField(PeekPair()) || PeekIsCustom()) {
1323 // Parse an inline module (i.e. one with no surrounding (module)).
1324 auto command = std::make_unique<ModuleCommand>();
1325 command->module.loc = GetLocation();
1326 CHECK_RESULT(ParseModuleFieldList(&command->module));
1327 script->commands.emplace_back(std::move(command));
1328 } else if (IsCommand(PeekPair())) {
1329 CHECK_RESULT(ParseCommandList(script.get(), &script->commands));
1330 } else if (PeekMatch(TokenType::Eof)) {
1331 errors_->emplace_back(ErrorLevel::Warning, GetLocation(),
1332 lexer_->Filename(), "empty script");
1333 } else {
1334 ConsumeIfLpar();
1335 ErrorExpected({"a module field", "a command"});
1336 }
1337
1338 EXPECT(Eof);
1339 if (!HasError()) {
1340 *out_script = std::move(script);
1341 return Result::Ok;
1342 } else {
1343 return Result::Error;
1344 }
1345}
1346
1347Result WastParser::ParseCustomSectionAnnotation(Module* module) {
1348 WABT_TRACE(ParseCustomSectionAnnotation);

Callers 1

ParseWastScriptFunction · 0.45

Calls 5

IsModuleFieldFunction · 0.85
IsCommandFunction · 0.85
FilenameMethod · 0.80
emplace_backMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected