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

Method parse

unittests/catch.hpp:6199–6233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6197 using ParserBase::parse;
6198
6199 auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override {
6200 auto validationResult = validate();
6201 if( !validationResult )
6202 return InternalParseResult( validationResult );
6203
6204 auto remainingTokens = tokens;
6205 if( remainingTokens && remainingTokens->type == TokenType::Option ) {
6206 auto const &token = *remainingTokens;
6207 if( isMatch(token.token ) ) {
6208 if( m_ref->isFlag() ) {
6209 auto flagRef = static_cast<detail::BoundFlagRefBase*>( m_ref.get() );
6210 auto result = flagRef->setFlag( true );
6211 if( !result )
6212 return InternalParseResult( result );
6213 if( result.value() == ParseResultType::ShortCircuitAll )
6214 return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) );
6215 } else {
6216 auto valueRef = static_cast<detail::BoundValueRefBase*>( m_ref.get() );
6217 ++remainingTokens;
6218 if( !remainingTokens )
6219 return InternalParseResult::runtimeError( "Expected argument following " + token.token );
6220 auto const &argToken = *remainingTokens;
6221 if( argToken.type != TokenType::Argument )
6222 return InternalParseResult::runtimeError( "Expected argument following " + token.token );
6223 auto result = valueRef->setValue( argToken.token );
6224 if( !result )
6225 return InternalParseResult( result );
6226 if( result.value() == ParseResultType::ShortCircuitAll )
6227 return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) );
6228 }
6229 return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) );
6230 }
6231 }
6232 return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) );
6233 }
6234
6235 auto validate() const -> Result override {
6236 if( m_optNames.empty() )

Callers

nothing calls this directly

Calls 6

ParseStateClass · 0.85
isFlagMethod · 0.45
getMethod · 0.45
setFlagMethod · 0.45
valueMethod · 0.45
setValueMethod · 0.45

Tested by

no test coverage detected