⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parser.cpp

📁 robocup rcssbase-11.1.0(1).zip
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				}				else				{					m_builder.includeFailed( full_name.native_file_string(),											 "cannot include a directory",											 m_stack.front().m_name,											 m_stack.front().m_lineno );					return false;				}			}			else			{				m_builder.includeFailed( full_name.native_file_string(),										 "file not found",										 m_stack.front().m_name,										 m_stack.front().m_lineno );				return false;			}		}        		void		Parser::load( const char* begin, const char* end )		{			lib::Loader loader;			std::string libname = cleanString( begin, end );			boost::filesystem::path path;			try			{				path = boost::filesystem::path( libname,												&boost::filesystem::native );			}			catch(...)			{				try				{					path = boost::filesystem::path( libname );				}				catch( const std::exception& e )				{					m_builder.loadFailed( libname, 										  e.what(), 										  lib::Loader::listAvailableModules(),										  m_stack.front().m_name, 										  m_stack.front().m_lineno );				}			}			if( !loader.open( path ) )			{				m_builder.loadFailed( libname, 									  loader.errorStr(), 									  lib::Loader::listAvailableModules(), 									  m_stack.front().m_name, 									  m_stack.front().m_lineno );			}			else			{				m_builder.manageModule( loader );				Builder::Creator c;				if( Builder::factory().getCreator( c, 												   loader.strippedName().c_str() ) )					m_builder.manageChild( c( &m_builder ) );			}		}				bool		Parser::setParamName( const char* begin, const char* end )		{			m_curr_param = cleanString( begin, end );			m_curr_module.clear();			return true;		}		void		Parser::appendParamName( const char* begin, const char* end )		{			if( m_curr_module.empty() )				m_curr_module = m_curr_param;			else				m_curr_module += "::" + m_curr_param;			m_curr_param = cleanString( begin, end );		}				bool		Parser::buildBool( bool value )		{			m_builder.buildParam( m_curr_module, m_curr_param, value, 								  m_stack.front().m_name,								  m_stack.front().m_lineno );			return true;		}				bool		Parser::buildInt( int value )		{			m_builder.buildParam( m_curr_module, m_curr_param, value, 								  m_stack.front().m_name, m_stack.front().m_lineno );			return true;		}				bool		Parser::buildReal( double value )		{			m_builder.buildParam( m_curr_module, m_curr_param, value, 								  m_stack.front().m_name, m_stack.front().m_lineno );			return true;		}				bool		Parser::buildString( const char* begin, const char* end )		{			m_builder.buildParam( m_curr_module, m_curr_param, 								  cleanString( begin, end ), 								  m_stack.front().m_name, m_stack.front().m_lineno );			return true;		}		void		Parser::requestGenericHelp()		{			m_builder.requestGenericHelp();		}				void		Parser::requestDetailedHelp()		{			if( m_curr_module.empty() )				m_curr_module = m_curr_param;			else				m_curr_module += "::" + m_curr_param;			m_builder.requestDetailedHelp( m_curr_module );		}		void		Parser::parseError( size_t pos,							const std::string& buffer )		{			std::string what;			if( pos + 10 > buffer.size() )				what = std::string( buffer.begin() + pos, buffer.end() );			else				what = std::string( buffer.begin() + pos,									buffer.begin() + pos + 10 );			std::string::iterator newline = std::find( what.begin(),													   what.end(), 													   '\n' );			if( newline != what.end() )				what = std::string( what.begin(), newline );			m_builder.parseError( what,								  "unknown parse error",								  m_stack.front().m_name,								  m_stack.front().m_lineno );		}		bool		Parser::boostParse()		{			using namespace rcss::conf;			boost::spirit::assertion<Errors> expect_assign(ASSIGN_EXPECTED);			boost::spirit::assertion<Errors> expect_delim(DELIM_EXPECTED);			boost::spirit::assertion<Errors> expect_value(VALUE_EXPECTED);			boost::spirit::assertion<Errors> expect_string(STRING_EXPECTED);			boost::spirit::guard<Errors> conf_guard;			std::istream& in = *m_stack.front().m_strm;			typedef std::istreambuf_iterator<char> iter_t;			std::string buffer;			std::copy( iter_t( in ), iter_t(), std::back_inserter( buffer ) );						boost::spirit::rule<> ws_p = +boost::spirit::chset_p( " \t\0" );			boost::spirit::rule<> newline_p = boost::spirit::eol_p;			boost::spirit::rule<> comment_p = ( 				boost::spirit::comment_p( "/*", "*/" )				| boost::spirit::comment_p( "//" )				| boost::spirit::comment_p( "#" ) );						boost::spirit::rule<> junk_p = ( 				ws_p 				| comment_p				[ 					boost::bind( &Parser::countNewLines, this, _1, _2 ) 					] 				| newline_p				[ 					boost::bind( &Parser::countNewLines, this, _1, _2 ) 					] 				);			boost::spirit::rule<> ignore_p = *junk_p;						boost::spirit::rule<> minus_p = boost::spirit::ch_p('-');						boost::spirit::rule<> assign_p = boost::spirit::ch_p( '=' );			boost::spirit::rule<> simple_str_p = ( 				+(~boost::spirit::chset_p( ":\"'= \t\n-" ) )				>> *(~boost::spirit::chset_p( ":\"'= \t\n" ) ) 				);			boost::spirit::rule<> pqsb_p = ~boost::spirit::ch_p( '"' );			boost::spirit::rule<> qsb_p = (				boost::spirit::str_p( "\\\"" ) 				| pqsb_p				);			boost::spirit::rule<> qstr_p = '"' >> *qsb_p >> '"';						boost::spirit::rule<> pqsb2_p = ~boost::spirit::ch_p( '\'' );			boost::spirit::rule<> qsb2_p = (				boost::spirit::str_p( "\\'" ) 				| pqsb2_p				);			boost::spirit::rule<> qstr2_p = '\'' >> (*qsb2_p) >> '\'';			boost::spirit::rule<> string_p = ( simple_str_p											   | qstr_p											   | qstr2_p );				boost::spirit::rule<> flag_p = ( 				boost::spirit::as_lower_d[ "help" ]				| boost::spirit::as_lower_d[ "include" ]				| boost::spirit::as_lower_d[ "load" ]				| boost::spirit::as_lower_d[ "setpath" ]				| boost::spirit::as_lower_d[ "addpath" ] 				);						boost::spirit::rule<> includerule_p = ( 				boost::spirit::as_lower_d[ "include" ] 				>> ignore_p 				>> expect_assign( assign_p ) 				>> ignore_p 				>> expect_string( 					string_p[						boost::bind( &Parser::include, this, _1, _2 ) 					])				);			boost::spirit::rule<> loadrule_p = ( 				boost::spirit::as_lower_d[ "load" ] 				>> ignore_p				>> expect_assign( assign_p )				>> ignore_p				>> expect_string( 					string_p[						boost::bind( &Parser::load, this, _1, _2 ) 					])				);			boost::spirit::rule<> pathrule_p = ( 				( boost::spirit::as_lower_d[ "setpath" ]				  >> ignore_p				  >> expect_assign( assign_p )				  >> ignore_p				  >> expect_string( 					  string_p[						  &setPath					  ])				  )				| ( boost::spirit::as_lower_d[ "addpath" ]					>> ignore_p					>> expect_assign( assign_p )					>> ignore_p					>> expect_string( 						string_p[							&addPath						])					)				);						boost::spirit::rule<> delim_p = boost::spirit::str_p( "::" );						boost::spirit::rule<> param_name_p = (				(simple_str_p - flag_p)[					boost::bind( &Parser::setParamName,								 this,								 _1, _2 )  				 ]				>> ( expect_delim( delim_p ) 					 >> ( simple_str_p - boost::spirit::as_lower_d[ "help" ])[						 boost::bind( &Parser::appendParamName,									  this,									  _1, _2 )						   ]					 )				>> *( delim_p  					 >> ( simple_str_p - boost::spirit::as_lower_d[ "help" ])[							 boost::bind( &Parser::appendParamName,										  this,										  _1, _2 )						   ]					 )				);			boost::spirit::rule<> module_name_p = (				(simple_str_p - flag_p)[					boost::bind( &Parser::setParamName,								 this,								 _1, _2 )  				 ]				>> *(delim_p 					 >> ( simple_str_p - boost::spirit::as_lower_d[ "help" ])[							 boost::bind( &Parser::appendParamName,										  this,										  _1, _2 )						   ]					 )				);			boost::spirit::rule<> true_p = ( 				boost::spirit::as_lower_d[ "on" ]				| boost::spirit::as_lower_d[ "true" ] 				);						boost::spirit::rule<> false_p = ( 				boost::spirit::as_lower_d[ "off" ]				| boost::spirit::as_lower_d[ "false" ] 				);						boost::spirit::rule<> param_p = ( 				param_name_p				>> ignore_p				>> expect_assign( assign_p )				>> ignore_p				>> expect_value( true_p[									 boost::bind( &Parser::buildBool,												  this,												  true )								 ]								 | false_p[									 boost::bind( &Parser::buildBool,												  this,												  false )								 ]								 | boost::spirit::strict_real_p[									 boost::bind( &Parser::buildReal,												  this,												  _1 )								 ]								 |								 boost::spirit::int_p[									 boost::bind( &Parser::buildInt,												  this,												  _1 )								 ]								 | string_p[									 boost::bind( &Parser::buildString,												  this,												  _1, _2 )								 ]) 				);						boost::spirit::rule<> data_p = ( 			    boost::spirit::as_lower_d[ "help" ][					boost::bind( &Parser::requestGenericHelp,								 this )				]				| ( module_name_p					>> delim_p 					>> boost::spirit::as_lower_d[ "help" ] )[						boost::bind( &Parser::requestDetailedHelp,									 this )	 					] 				| param_p				| pathrule_p				| includerule_p				| loadrule_p				);						boost::spirit::rule<> item_p = ( 				junk_p 				| ( !minus_p					>> !minus_p					>> data_p )				);			boost::spirit::rule<> input_p = conf_guard( *item_p )[				boost::bind( &ParseErrorHandler::parseError,							 this, _1, _2 )			];			// 			BOOST_SPIRIT_DEBUG_RULE(ws_p);// 			BOOST_SPIRIT_DEBUG_RULE(newline_p);// 			BOOST_SPIRIT_DEBUG_RULE(comment_p);// 			BOOST_SPIRIT_DEBUG_RULE(string_p);// 			BOOST_SPIRIT_DEBUG_RULE(input_p);// 			BOOST_SPIRIT_DEBUG_RULE(item_p);// 			BOOST_SPIRIT_DEBUG_RULE(param_p);// 			BOOST_SPIRIT_DEBUG_RULE(data_p);// 			BOOST_SPIRIT_DEBUG_RULE(junk_p);// 			BOOST_SPIRIT_DEBUG_RULE(ignore_p);// 			BOOST_SPIRIT_DEBUG_RULE(includerule_p);// 			BOOST_SPIRIT_DEBUG_RULE(loadrule_p);// 			BOOST_SPIRIT_DEBUG_RULE(pathrule_p);// 			BOOST_SPIRIT_DEBUG_RULE(param_name_p);// 			BOOST_SPIRIT_DEBUG_RULE(module_name_p);// 			BOOST_SPIRIT_DEBUG_RULE(true_p);// 			BOOST_SPIRIT_DEBUG_RULE(false_p);// 			BOOST_SPIRIT_DEBUG_RULE(flag_p);// 			BOOST_SPIRIT_DEBUG_RULE(boost::spirit::as_lower_d[ "help" ]);// 			BOOST_SPIRIT_DEBUG_RULE(delim_p);// 			BOOST_SPIRIT_DEBUG_RULE(minus_p);// 			BOOST_SPIRIT_DEBUG_RULE(assign_p);// 			BOOST_SPIRIT_DEBUG_RULE(simple_str_p);// 			BOOST_SPIRIT_DEBUG_RULE(qstr_p);// 			BOOST_SPIRIT_DEBUG_RULE(qstr2_p);// 			BOOST_SPIRIT_DEBUG_RULE(string_p);// 			BOOST_SPIRIT_DEBUG_RULE(boost::spirit::int_p);// 			BOOST_SPIRIT_DEBUG_RULE(includerule_p);// 			BOOST_SPIRIT_DEBUG_RULE(loadrule_p);// 			BOOST_SPIRIT_DEBUG_RULE(pathrule_p);			boost::spirit::parse_info<> info = boost::spirit::parse( buffer.c_str(), 																	 input_p );			if( !info.full )			{ 				parseError( info.length, buffer );			}			return info.full;		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -