Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67226 - in sandbox/configurator/boost/configurator: . detail
From: for.dshevchenko_at_[hidden]
Date: 2010-12-14 00:59:06


Author: dshevchenko
Date: 2010-12-14 00:58:51 EST (Tue, 14 Dec 2010)
New Revision: 67226
URL: http://svn.boost.org/trac/boost/changeset/67226

Log:
Spirit grammars for obtained options.

Text files modified:
   sandbox/configurator/boost/configurator/configurator.hpp | 2
   sandbox/configurator/boost/configurator/configurator_settings.hpp | 8 +
   sandbox/configurator/boost/configurator/detail/grammars.hpp | 133 +++++++++++++++++++++++----------------
   sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp | 54 ++++++---------
   4 files changed, 105 insertions(+), 92 deletions(-)

Modified: sandbox/configurator/boost/configurator/configurator.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/configurator.hpp (original)
+++ sandbox/configurator/boost/configurator/configurator.hpp 2010-12-14 00:58:51 EST (Tue, 14 Dec 2010)
@@ -45,7 +45,7 @@
     configurator() :
             sections_separator( "::" )
             , settings_of_configurator()
- , options_obtainer( settings_of_configurator.option_name_value_separator_str
+ , options_obtainer( settings_of_configurator.option_name_value_separator
                                 , sections_separator
                                 , registered_options
                                 , settings_of_configurator.case_sensitivity )

Modified: sandbox/configurator/boost/configurator/configurator_settings.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/configurator_settings.hpp (original)
+++ sandbox/configurator/boost/configurator/configurator_settings.hpp 2010-12-14 00:58:51 EST (Tue, 14 Dec 2010)
@@ -13,6 +13,7 @@
 #include <boost/configurator/detail/misc.hpp>
 
 #include <string>
+#include <ostream>
 
 namespace boost {
 
@@ -24,14 +25,12 @@
 struct configurator_settings {
     configurator_settings() :
             option_name_value_separator( '=' )
- , option_name_value_separator_str( "=" )
             , one_line_comment_sign( "//" )
             , case_sensitivity( false ) {}
 public:
     char option_name_value_separator;
     std::string one_line_comment_sign;
     bool case_sensitivity;
- std::string option_name_value_separator_str;
     //
 public:
     configurator_settings& set_case_sensitivity_for_names() {
@@ -56,7 +55,10 @@
         } else {}
     }
 public:
- //
+ configurator_settings& send_warnings_to( std::ostream& os ) {
+ //
+ return *this;
+ }
 };
 
 } // namespace cf

Modified: sandbox/configurator/boost/configurator/detail/grammars.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/grammars.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/grammars.hpp 2010-12-14 00:58:51 EST (Tue, 14 Dec 2010)
@@ -9,6 +9,7 @@
 #ifndef BOOST_CONFIGURATOR_GRAMMARS_HPP
 #define BOOST_CONFIGURATOR_GRAMMARS_HPP
 
+#include <boost/configurator/detail/types.hpp>
 #include <boost/spirit/include/qi.hpp>
 #include <boost/spirit/include/phoenix_core.hpp>
 #include <boost/spirit/include/phoenix_operator.hpp>
@@ -53,11 +54,26 @@
 namespace detail {
 
 template< typename Iterator >
-struct obtained_option_parser_space : boost::spirit::qi::grammar< Iterator
- , obtained_option()
- , boost::spirit::ascii::space_type > {
- obtained_option_parser_space() :
- obtained_option_parser_space::base_type( start ) {
+struct option_parser_space : boost::spirit::qi::grammar< Iterator
+ , obtained_option()
+ , boost::spirit::ascii::space_type > {
+ typedef typename boost::spirit::qi::rule
+ <
+ Iterator
+ , std::string()
+ , boost::spirit::ascii::space_type
+ >
+ string_rule;
+ typedef typename boost::spirit::qi::rule
+ <
+ Iterator
+ , obtained_option()
+ , boost::spirit::ascii::space_type
+ >
+ base_rule;
+public:
+ option_parser_space() :
+ option_parser_space::base_type( start ) {
         using boost::spirit::qi::lexeme;
         using boost::spirit::qi::char_;
          
@@ -66,68 +82,73 @@
         start %= name_extractor >> value_extractor;
     }
 public:
- boost::spirit::qi::rule
- <
- Iterator
- , std::string()
- , boost::spirit::ascii::space_type
- >
- name_extractor;
- boost::spirit::qi::rule
- <
- Iterator
- , std::string()
- , boost::spirit::ascii::space_type
- >
- value_extractor;
- boost::spirit::qi::rule
- <
- Iterator
- , obtained_option()
- , boost::spirit::ascii::space_type
- >
- start;
+ string_rule name_extractor;
+ string_rule value_extractor;
+ base_rule start;
 };
 
 template< typename Iterator >
-struct obtained_option_parser : boost::spirit::qi::grammar< Iterator
- , obtained_option()
- , boost::spirit::ascii::space_type > {
- obtained_option_parser( char separator ) :
- obtained_option_parser::base_type( start ) {
+struct option_parser : boost::spirit::qi::grammar< Iterator
+ , obtained_option()
+ , boost::spirit::ascii::space_type > {
+ typedef typename boost::spirit::qi::rule
+ <
+ Iterator
+ , std::string()
+ , boost::spirit::ascii::space_type
+ >
+ string_rule;
+ typedef typename boost::spirit::qi::rule
+ <
+ Iterator
+ , obtained_option()
+ , boost::spirit::ascii::space_type
+ >
+ base_rule;
+public:
+ option_parser( char separator ) :
+ option_parser::base_type( start ) {
         using boost::spirit::qi::lexeme;
         using boost::spirit::qi::char_;
- using boost::spirit::qi::skip;
- using boost::spirit::ascii::space;
          
- name_extractor %= skip( space )[ +( char_ - separator ) ];
- value_extractor %= skip( space )[ +( char_ - separator ) ];
+ name_extractor %= lexeme[ +( char_ - separator ) ];
+ value_extractor %= lexeme[ +( char_ - separator ) ];
         start %= name_extractor >> separator >> value_extractor;
     }
 public:
- boost::spirit::qi::rule
- <
- Iterator
- , std::string()
- , boost::spirit::ascii::space_type
- >
- name_extractor;
- boost::spirit::qi::rule
- <
- Iterator
- , std::string()
- , boost::spirit::ascii::space_type
- >
- value_extractor;
- boost::spirit::qi::rule
- <
- Iterator
- , obtained_option()
- , boost::spirit::ascii::space_type
- >
- start;
+ string_rule name_extractor;
+ string_rule value_extractor;
+ base_rule start;
 };
 
+typedef option_parser< string_it > pure_option_parser;
+typedef option_parser< string_const_it > pure_option_parser_const;
+
+typedef option_parser_space< string_it > pure_option_parser_space;
+typedef option_parser_space< string_const_it > pure_option_parser_space_const;
+
+inline bool parse_option( std::string& s, char separator, obtained_option& result ) {
+ pure_option_parser parser( separator );
+ string_it first = s.begin();
+ string_it last = s.end();
+ bool parse_success = boost::spirit::qi::phrase_parse( first, last
+ , parser
+ , boost::spirit::ascii::space
+ , result );
+ return parse_success && first == last;
+}
+
+inline bool parse_option_space( std::string& s, obtained_option& result ) {
+ pure_option_parser_space parser;
+ string_it first = s.begin();
+ string_it last = s.end();
+ bool parse_success = boost::spirit::qi::phrase_parse( first, last
+ , parser
+ , boost::spirit::ascii::space
+ , result );
+ return parse_success && first == last;
+}
+
 } // namespace detail
 } // namespace cf
 } // namespace boost

Modified: sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp
==============================================================================
--- sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp (original)
+++ sandbox/configurator/boost/configurator/detail/pure_options_obtainer.hpp 2010-12-14 00:58:51 EST (Tue, 14 Dec 2010)
@@ -18,6 +18,10 @@
 #include <boost/function.hpp>
 #include <boost/assign.hpp>
 #include <boost/foreach.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_stl.hpp>
 
 #include <string>
 #include <vector>
@@ -42,7 +46,7 @@
     typedef boost::spirit::qi::rule< string_it >
             simple_rule;
 public:
- pure_options_obtainer( std::string& _option_name_value_separator
+ pure_options_obtainer( const char& _option_name_value_separator
                            , const std::string& _sections_separator
                            , const options& _registered_options
                            , const bool& _case_sensitivity_for_names ) :
@@ -62,7 +66,7 @@
                     ;
     }
 private:
- std::string& option_name_value_separator;
+ const char& option_name_value_separator;
     const std::string& sections_separator;
     const options& registered_options;
     const bool& case_sensitivity_for_names;
@@ -94,11 +98,10 @@
     }
 private:
     bool handle_section_opening( std::string& s, pure_options& /* factual_obtained_options */ ) {
-
-
- /*
         using boost::spirit::qi::_1;
         using boost::phoenix::push_back;
+ using boost::spirit::qi::string;
+ using boost::spirit::qi::char_;
 
         std::string name_of_opening_section;
 
@@ -115,7 +118,6 @@
             final_handle_section_opening( name_of_opening_section );
         } else {}
         return parsing_success;
- */
     }
     
     void final_handle_section_opening( std::string& name_of_opening_section ) {
@@ -149,10 +151,10 @@
     }
 private:
     bool handle_section_closing( std::string& s, pure_options& /* factual_obtained_options */ ) {
-
- /*
         using boost::spirit::qi::_1;
         using boost::phoenix::push_back;
+ using boost::spirit::qi::string;
+ using boost::spirit::qi::char_;
 
         std::string name_of_closing_section;
 
@@ -168,7 +170,6 @@
             final_handle_section_closing( name_of_closing_section );
         } else {}
         return parsing_success;
- */
     }
     
     void final_handle_section_closing( std::string& name_of_closing_section ) {
@@ -198,33 +199,22 @@
     }
 private:
     bool handle_option( std::string& s, pure_options& factual_obtained_options ) {
+ bool parsing_success = false;
 
- /*
- using boost::spirit::qi::_1;
- using boost::phoenix::push_back;
-
- std::string option_name;
- std::string option_value;
-
- simple_rule name_extractor = +( char_[ push_back( boost::phoenix::ref(option_name), _1 ) ]
- - string( option_name_value_separator ) );
-
- simple_rule separator = string( option_name_value_separator );
- if ( ' ' == *option_name_value_separator.begin() ) {
- separator = +( string( option_name_value_separator ) );
- } else {}
-
- simple_rule value_extractor = +( char_[ push_back( boost::phoenix::ref(option_value), _1 ) ] );
- simple_rule full = name_extractor >> separator >> value_extractor;
+ obtained_option result;
+ if ( ' ' == option_name_value_separator ) {
+ parsing_success = parse_option_space( s, result );
+ } else {
+ parsing_success = parse_option( s, option_name_value_separator, result );
+ }
 
- bool parsing_success = parse( s.begin(), s.end(), full );
         if ( parsing_success ) {
- boost::trim( option_name );
- boost::trim( option_value );
- final_handle_option( option_name, option_value, factual_obtained_options );
+ boost::trim( result.name );
+ boost::trim( result.value );
+ final_handle_option( result.name, result.value, factual_obtained_options );
         } else {}
- return parsing_success;
- */
+
+ return parsing_success;
     }
 
     void final_handle_option( const std::string& option_name


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk