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

Method parse

unittests/catch.hpp:6376–6420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6374 using ParserBase::parse;
6375
6376 auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override {
6377
6378 struct ParserInfo {
6379 ParserBase const* parser = nullptr;
6380 size_t count = 0;
6381 };
6382 const size_t totalParsers = m_options.size() + m_args.size();
6383 assert( totalParsers < 512 );
6384 // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do
6385 ParserInfo parseInfos[512];
6386
6387 {
6388 size_t i = 0;
6389 for (auto const &opt : m_options) parseInfos[i++].parser = &opt;
6390 for (auto const &arg : m_args) parseInfos[i++].parser = &arg;
6391 }
6392
6393 m_exeName.set( exeName );
6394
6395 auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) );
6396 while( result.value().remainingTokens() ) {
6397 bool tokenParsed = false;
6398
6399 for( size_t i = 0; i < totalParsers; ++i ) {
6400 auto& parseInfo = parseInfos[i];
6401 if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) {
6402 result = parseInfo.parser->parse(exeName, result.value().remainingTokens());
6403 if (!result)
6404 return result;
6405 if (result.value().type() != ParseResultType::NoMatch) {
6406 tokenParsed = true;
6407 ++parseInfo.count;
6408 break;
6409 }
6410 }
6411 }
6412
6413 if( result.value().type() == ParseResultType::ShortCircuitAll )
6414 return result;
6415 if( !tokenParsed )
6416 return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token );
6417 }
6418 // !TBD Check missing required options
6419 return result;
6420 }
6421 };
6422
6423 template<typename DerivedT>

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected