MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / parse

Method parse

extern/Catch2/catch.hpp:9598–9642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9596 using ParserBase::parse;
9597
9598 auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override {
9599
9600 struct ParserInfo {
9601 ParserBase const* parser = nullptr;
9602 size_t count = 0;
9603 };
9604 const size_t totalParsers = m_options.size() + m_args.size();
9605 assert( totalParsers < 512 );
9606 // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do
9607 ParserInfo parseInfos[512];
9608
9609 {
9610 size_t i = 0;
9611 for (auto const &opt : m_options) parseInfos[i++].parser = &opt;
9612 for (auto const &arg : m_args) parseInfos[i++].parser = &arg;
9613 }
9614
9615 m_exeName.set( exeName );
9616
9617 auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
9618 while( result.value().remainingTokens() ) {
9619 bool tokenParsed = false;
9620
9621 for( size_t i = 0; i < totalParsers; ++i ) {
9622 auto& parseInfo = parseInfos[i];
9623 if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) {
9624 result = parseInfo.parser->parse(exeName, result.value().remainingTokens());
9625 if (!result)
9626 return result;
9627 if (result.value().type() != ParseResultType::NoMatch) {
9628 tokenParsed = true;
9629 ++parseInfo.count;
9630 break;
9631 }
9632 }
9633 }
9634
9635 if( result.value().type() == ParseResultType::ShortCircuitAll )
9636 return result;
9637 if( !tokenParsed )
9638 return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token );
9639 }
9640 // !TBD Check missing required options
9641 return result;
9642 }
9643 };
9644
9645 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