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

Method parse

test/expected/catch.hpp:9532–9576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9530 using ParserBase::parse;
9531
9532 auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override {
9533
9534 struct ParserInfo {
9535 ParserBase const* parser = nullptr;
9536 size_t count = 0;
9537 };
9538 const size_t totalParsers = m_options.size() + m_args.size();
9539 assert( totalParsers < 512 );
9540 // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do
9541 ParserInfo parseInfos[512];
9542
9543 {
9544 size_t i = 0;
9545 for (auto const &opt : m_options) parseInfos[i++].parser = &opt;
9546 for (auto const &arg : m_args) parseInfos[i++].parser = &arg;
9547 }
9548
9549 m_exeName.set( exeName );
9550
9551 auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
9552 while( result.value().remainingTokens() ) {
9553 bool tokenParsed = false;
9554
9555 for( size_t i = 0; i < totalParsers; ++i ) {
9556 auto& parseInfo = parseInfos[i];
9557 if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) {
9558 result = parseInfo.parser->parse(exeName, result.value().remainingTokens());
9559 if (!result)
9560 return result;
9561 if (result.value().type() != ParseResultType::NoMatch) {
9562 tokenParsed = true;
9563 ++parseInfo.count;
9564 break;
9565 }
9566 }
9567 }
9568
9569 if( result.value().type() == ParseResultType::ShortCircuitAll )
9570 return result;
9571 if( !tokenParsed )
9572 return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token );
9573 }
9574 // !TBD Check missing required options
9575 return result;
9576 }
9577 };
9578
9579 template<typename DerivedT>

Callers

nothing calls this directly

Calls 8

ParseStateClass · 0.85
remainingTokensMethod · 0.80
sizeMethod · 0.45
setMethod · 0.45
valueMethod · 0.45
cardinalityMethod · 0.45
parseMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected