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

Method parse

extlibs/catch/include/catch/catch.hpp:9281–9325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9279 using ParserBase::parse;
9280
9281 auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override {
9282
9283 struct ParserInfo {
9284 ParserBase const* parser = nullptr;
9285 size_t count = 0;
9286 };
9287 const size_t totalParsers = m_options.size() + m_args.size();
9288 assert( totalParsers < 512 );
9289 // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do
9290 ParserInfo parseInfos[512];
9291
9292 {
9293 size_t i = 0;
9294 for (auto const &opt : m_options) parseInfos[i++].parser = &opt;
9295 for (auto const &arg : m_args) parseInfos[i++].parser = &arg;
9296 }
9297
9298 m_exeName.set( exeName );
9299
9300 auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
9301 while( result.value().remainingTokens() ) {
9302 bool tokenParsed = false;
9303
9304 for( size_t i = 0; i < totalParsers; ++i ) {
9305 auto& parseInfo = parseInfos[i];
9306 if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) {
9307 result = parseInfo.parser->parse(exeName, result.value().remainingTokens());
9308 if (!result)
9309 return result;
9310 if (result.value().type() != ParseResultType::NoMatch) {
9311 tokenParsed = true;
9312 ++parseInfo.count;
9313 break;
9314 }
9315 }
9316 }
9317
9318 if( result.value().type() == ParseResultType::ShortCircuitAll )
9319 return result;
9320 if( !tokenParsed )
9321 return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token );
9322 }
9323 // !TBD Check missing required options
9324 return result;
9325 }
9326 };
9327
9328 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