| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file spirit_actors.h | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  |  * @brief Additional utilities and actors for the wrap parser | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * @date Dec 8, 2011 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  |  * @author Frank Dellaert | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/spirit/include/classic_core.hpp>
 | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  | #include <boost/spirit/include/classic_push_back_actor.hpp>
 | 
					
						
							|  |  |  | #include <boost/spirit/include/classic_clear_actor.hpp>
 | 
					
						
							|  |  |  | #include <boost/spirit/include/classic_assign_actor.hpp>
 | 
					
						
							|  |  |  | #include <boost/spirit/include/classic_confix.hpp>
 | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace boost { | 
					
						
							|  |  |  | namespace spirit { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //  Summary:
 | 
					
						
							|  |  |  | //  A semantic action policy that calls pop_back method.
 | 
					
						
							|  |  |  | //  (This doc uses convention available in actors.hpp)
 | 
					
						
							|  |  |  | //  Note that this action performs a "safe" pop, that checks the size
 | 
					
						
							|  |  |  | //  before popping to avoid segfaults
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Actions (what it does):
 | 
					
						
							|  |  |  | //      ref.pop_back();
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Policy name:
 | 
					
						
							|  |  |  | //      pop_action
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Policy holder, corresponding helper method:
 | 
					
						
							|  |  |  | //      ref_actor, clear_a( ref );
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  () operators: both.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  See also ref_actor for more details.
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | struct pop_action | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |   template< typename T> | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   void act(T& ref_) const | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     if (!ref_.empty()) | 
					
						
							|  |  |  |     ref_.pop_back(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // helper method that creates a and_assign_actor.
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | template<typename T> | 
					
						
							|  |  |  | inline ref_actor<T,pop_action> pop_a(T& ref_) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   return ref_actor<T,pop_action>(ref_); | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | //  Summary:
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  A semantic action policy that appends a set of values to the back of a
 | 
					
						
							|  |  |  | //  container.
 | 
					
						
							|  |  |  | //  (This doc uses convention available in actors.hpp)
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Actions (what it does and what ref, value_ref must support):
 | 
					
						
							|  |  |  | //      ref.push_back( values );
 | 
					
						
							|  |  |  | //      ref.push_back( T::value_type(first,last) );
 | 
					
						
							|  |  |  | //      ref.push_back( value_ref );
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Policy name:
 | 
					
						
							|  |  |  | //      append_action
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  Policy holder, corresponding helper method:
 | 
					
						
							|  |  |  | //      ref_value_actor, append_a( ref );
 | 
					
						
							|  |  |  | //      ref_const_ref_actor, append_a( ref, value_ref );
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  () operators: both
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | //  See also ref_value_actor and ref_const_ref_actor for more details.
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct append_action | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |   template< typename T, typename ValueT > | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   void act(T& ref_, ValueT const& value_) const | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     ref_.insert(ref_.begin(), value_.begin(), value_.end()); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   template<typename T,typename IteratorT> | 
					
						
							|  |  |  |   void act( | 
					
						
							|  |  |  |       T& ref_, | 
					
						
							|  |  |  |       IteratorT const& first_, | 
					
						
							|  |  |  |       IteratorT const& last_ | 
					
						
							|  |  |  |   ) const | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     ref_.insert(ref_.end(), first_, last_); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename T> | 
					
						
							|  |  |  | inline ref_value_actor<T,append_action> | 
					
						
							|  |  |  | append_a(T& ref_) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   return ref_value_actor<T,append_action>(ref_); | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<typename T,typename ValueT> | 
					
						
							|  |  |  | inline ref_const_ref_actor<T,ValueT,append_action> | 
					
						
							|  |  |  | append_a( | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     T& ref_, | 
					
						
							|  |  |  |     ValueT const& value_ | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   return ref_const_ref_actor<T,ValueT,append_action>(ref_,value_); | 
					
						
							| 
									
										
										
										
											2011-12-16 03:39:11 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BOOST_SPIRIT_CLASSIC_NAMESPACE_END | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  | namespace classic = BOOST_SPIRIT_CLASSIC_NS; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Some basic rules used by all parsers
 | 
					
						
							|  |  |  | template<typename ScannerT> | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  | struct BasicRules { | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |   classic::rule<ScannerT> comments_p, basisType_p, eigenType_p, keywords_p, | 
					
						
							|  |  |  |       stlType_p, name_p, className_p, namespace_p; | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  |   BasicRules() { | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 03:29:11 +08:00
										 |  |  |     using classic::comment_p; | 
					
						
							|  |  |  |     using classic::eol_p; | 
					
						
							|  |  |  |     using classic::str_p; | 
					
						
							|  |  |  |     using classic::alpha_p; | 
					
						
							|  |  |  |     using classic::lexeme_d; | 
					
						
							|  |  |  |     using classic::upper_p; | 
					
						
							|  |  |  |     using classic::lower_p; | 
					
						
							|  |  |  |     using classic::alnum_p; | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     comments_p = comment_p("/*", "*/") | comment_p("//", eol_p); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     basisType_p = (str_p("string") | "bool" | "size_t" | "int" | "double" | 
					
						
							|  |  |  |         | "char" | "unsigned char"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     eigenType_p = (str_p("Vector") | "Matrix"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     keywords_p = | 
					
						
							|  |  |  |         (str_p("const") | "static" | "namespace" | "void" | basisType_p); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     stlType_p = (str_p("vector") | "list"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     name_p = lexeme_d[alpha_p >> *(alnum_p | '_')]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     className_p = (lexeme_d[upper_p >> *(alnum_p | '_')] - eigenType_p | 
					
						
							|  |  |  |         - keywords_p) | stlType_p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     namespace_p = lexeme_d[lower_p >> *(alnum_p | '_')] - keywords_p; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-12-02 03:03:26 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-12-01 18:43:19 +08:00
										 |  |  | 
 |