MCPcopy Create free account
hub / github.com/WasmEdge/WasmEdge / parse

Method parse

lib/validator/component_name.cpp:337–626  ·  view source on GitHub ↗

exportname ::= | importname ::= | | |

Source from the content-addressed store, hash-verified

335// exportname ::= <plainname> | <interfacename>
336// importname ::= <exportname> | <depname> | <urlname> | <hashname>
337Expect<ComponentName> ComponentName::parse(std::string_view Name) {
338 ComponentName Result(Name);
339 auto Next = Name;
340
341 // plainname ::= <label>
342 // | '[constructor]' <label>
343 // | '[method]' <label> '.' <label>
344 // | '[static]' <label> '.' <label>
345
346 if (tryRead("[constructor]"sv, Next)) {
347 if (!isKebabString(Next)) {
348 return reportError("invalid label after [constructor]"sv);
349 }
350 Result.Detail.emplace<ConstructorDetail>(ConstructorDetail{Next});
351 Result.NoTagName = Next;
352 Result.Kind = ComponentNameKind::Constructor;
353 return Result;
354 }
355
356 auto tryReadResourceWithLabel = [&](std::string_view Tag,
357 std::string_view &Resource,
358 std::string_view &Label) -> bool {
359 auto Saved = Next;
360 if (!tryRead(Tag, Next)) {
361 return false;
362 }
363 auto TmpNoTagName = Next;
364 if (!readUntil(Next, '.', Resource)) {
365 Next = Saved;
366 return false;
367 }
368 if (!isKebabString(Resource) || !isKebabString(Next)) {
369 Next = Saved;
370 return false;
371 }
372 Result.NoTagName = TmpNoTagName;
373 Label = Next;
374 return true;
375 };
376
377 {
378 std::string_view Resource, Label;
379 if (tryReadResourceWithLabel("[method]"sv, Resource, Label)) {
380 Result.Detail.emplace<MethodDetail>(MethodDetail{Resource, Label});
381 Result.Kind = ComponentNameKind::Method;
382 return Result;
383 }
384 }
385
386 {
387 std::string_view Resource, Label;
388 if (tryReadResourceWithLabel("[static]"sv, Resource, Label)) {
389 Result.Detail.emplace<StaticDetail>(StaticDetail{Resource, Label});
390 Result.Kind = ComponentNameKind::Static;
391 return Result;
392 }
393 }
394

Callers

nothing calls this directly

Calls 15

tryReadFunction · 0.85
isKebabStringFunction · 0.85
reportErrorFunction · 0.85
readUntilFunction · 0.85
isValidSemverFunction · 0.85
isEOFFunction · 0.85
tryParseIntegritySuffixFunction · 0.85
isIntegrityMetadataFunction · 0.85
isLowercaseKebabStringFunction · 0.85
tryReadKebabFunction · 0.85
isVersionFunction · 0.85
substrMethod · 0.80

Tested by

no test coverage detected