Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60191 - in trunk/boost/spirit/home: qi/nonterminal support support/nonterminal
From: joel_at_[hidden]
Date: 2010-03-05 10:40:27


Author: djowel
Date: 2010-03-05 10:40:27 EST (Fri, 05 Mar 2010)
New Revision: 60191
URL: http://svn.boost.org/trac/boost/changeset/60191

Log:
rules with parameters for char encoding
Text files modified:
   trunk/boost/spirit/home/qi/nonterminal/grammar.hpp | 29 ++++++++++++++++-------------
   trunk/boost/spirit/home/qi/nonterminal/rule.hpp | 32 ++++++++++++++++++++++++--------
   trunk/boost/spirit/home/support/common_terminals.hpp | 20 ++++++++++++++++++++
   trunk/boost/spirit/home/support/nonterminal/extract_param.hpp | 12 ++++++++++++
   4 files changed, 72 insertions(+), 21 deletions(-)

Modified: trunk/boost/spirit/home/qi/nonterminal/grammar.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/grammar.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/grammar.hpp 2010-03-05 10:40:27 EST (Fri, 05 Mar 2010)
@@ -27,23 +27,25 @@
       , typename T1 = unused_type
       , typename T2 = unused_type
       , typename T3 = unused_type
+ , typename T4 = unused_type
>
     struct grammar
       : proto::extends<
             typename proto::terminal<
- reference<rule<Iterator, T1, T2, T3> const>
+ reference<rule<Iterator, T1, T2, T3, T4> const>
>::type
- , grammar<Iterator, T1, T2, T3>
+ , grammar<Iterator, T1, T2, T3, T4>
>
- , parser<grammar<Iterator, T1, T2, T3> >
+ , parser<grammar<Iterator, T1, T2, T3, T4> >
       , noncopyable
     {
         typedef Iterator iterator_type;
- typedef rule<Iterator, T1, T2, T3> start_type;
+ typedef rule<Iterator, T1, T2, T3, T4> start_type;
         typedef typename start_type::sig_type sig_type;
         typedef typename start_type::locals_type locals_type;
         typedef typename start_type::skipper_type skipper_type;
- typedef grammar<Iterator, T1, T2, T3> base_type;
+ typedef typename start_type::encoding_type encoding_type;
+ typedef grammar<Iterator, T1, T2, T3, T4> base_type;
         typedef reference<start_type const> reference_;
         typedef typename proto::terminal<reference_>::type terminal;
 
@@ -56,19 +58,20 @@
         , name_(name_)
         {}
 
- // This constructor is used to catch if the start rule is not
- // compatible with the grammar.
- template <typename Iterator_, typename T1_, typename T2_, typename T3_>
+ // This constructor is used to catch if the start rule is not
+ // compatible with the grammar.
+ template <typename Iterator_,
+ typename T1_, typename T2_, typename T3_, typename T4_>
         grammar(
- rule<Iterator_, T1_, T2_, T3_> const&
+ rule<Iterator_, T1_, T2_, T3_, T4_> const&
           , std::string const& = "unnamed-grammar")
         {
- // If you see the assertion below failing then the start rule
- // passed to the constructor of the grammar is not compatible with
+ // If you see the assertion below failing then the start rule
+ // passed to the constructor of the grammar is not compatible with
             // the grammar (i.e. it uses different template parameters).
             BOOST_SPIRIT_ASSERT_MSG(
- (is_same<start_type, rule<Iterator_, T1_, T2_, T3_> >::value)
- , incompatible_start_rule, (rule<Iterator_, T1_, T2_, T3_>));
+ (is_same<start_type, rule<Iterator_, T1_, T2_, T3_, T4_> >::value)
+ , incompatible_start_rule, (rule<Iterator_, T1_, T2_, T3_, T4_>));
         }
 
         std::string name() const

Modified: trunk/boost/spirit/home/qi/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/rule.hpp 2010-03-05 10:40:27 EST (Fri, 05 Mar 2010)
@@ -67,22 +67,23 @@
       , typename T1 = unused_type
       , typename T2 = unused_type
       , typename T3 = unused_type
+ , typename T4 = unused_type
>
     struct rule
       : proto::extends<
             typename proto::terminal<
- reference<rule<Iterator, T1, T2, T3> const>
+ reference<rule<Iterator, T1, T2, T3, T4> const>
>::type
- , rule<Iterator, T1, T2, T3>
+ , rule<Iterator, T1, T2, T3, T4>
>
- , parser<rule<Iterator, T1, T2, T3> >
+ , parser<rule<Iterator, T1, T2, T3, T4> >
     {
         typedef Iterator iterator_type;
- typedef rule<Iterator, T1, T2, T3> this_type;
+ typedef rule<Iterator, T1, T2, T3, T4> this_type;
         typedef reference<this_type const> reference_;
         typedef typename proto::terminal<reference_>::type terminal;
         typedef proto::extends<terminal, this_type> base_type;
- typedef mpl::vector<T1, T2, T3> template_params;
+ typedef mpl::vector<T1, T2, T3, T4> template_params;
 
         // locals_type is a sequence of types to be used as local variables
         typedef typename
@@ -99,6 +100,10 @@
             spirit::detail::extract_sig<template_params>::type
         sig_type;
 
+ typedef typename
+ spirit::detail::extract_encoding<template_params>::type
+ encoding_type;
+
         // This is the rule's attribute type
         typedef typename
             spirit::detail::attr_from_sig<sig_type>::type
@@ -125,6 +130,14 @@
             )>
         function_type;
 
+ typedef typename
+ mpl::if_<
+ is_same<encoding_type, unused_type>
+ , unused_type
+ , tag::char_code<tag::encoding, encoding_type>
+ >::type
+ encoding_modifier_type;
+
         explicit rule(std::string const& name_ = "unnamed-rule")
           : base_type(terminal::make(reference_(*this)))
           , name_(name_)
@@ -148,7 +161,8 @@
             // then the expression (expr) is not a valid spirit qi expression.
             BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
 
- f = detail::bind_parser<mpl::false_>(compile<qi::domain>(expr));
+ f = detail::bind_parser<mpl::false_>(
+ compile<qi::domain>(expr, encoding_modifier_type()));
         }
 
         rule& operator=(rule const& rhs)
@@ -182,7 +196,8 @@
             // then the expression (expr) is not a valid spirit qi expression.
             BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
 
- f = detail::bind_parser<mpl::false_>(compile<qi::domain>(expr));
+ f = detail::bind_parser<mpl::false_>(
+ compile<qi::domain>(expr, encoding_modifier_type()));
             return *this;
         }
 
@@ -195,7 +210,8 @@
             // then the expression (expr) is not a valid spirit qi expression.
             BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
 
- r.f = detail::bind_parser<mpl::true_>(compile<qi::domain>(expr));
+ r.f = detail::bind_parser<mpl::true_>(
+ compile<qi::domain>(expr, encoding_modifier_type()));
             return r;
         }
 

Modified: trunk/boost/spirit/home/support/common_terminals.hpp
==============================================================================
--- trunk/boost/spirit/home/support/common_terminals.hpp (original)
+++ trunk/boost/spirit/home/support/common_terminals.hpp 2010-03-05 10:40:27 EST (Fri, 05 Mar 2010)
@@ -39,6 +39,26 @@
>
     char_encodings;
 
+ template <typename T>
+ struct is_char_encoding : mpl::false_ {};
+
+ template <>
+ struct is_char_encoding<spirit::char_encoding::ascii> : mpl::true_ {};
+
+ template <>
+ struct is_char_encoding<spirit::char_encoding::iso8859_1> : mpl::true_ {};
+
+ template <>
+ struct is_char_encoding<spirit::char_encoding::standard> : mpl::true_ {};
+
+ template <>
+ struct is_char_encoding<spirit::char_encoding::standard_wide> : mpl::true_ {};
+
+#if defined(BOOST_SPIRIT_UNICODE)
+ template <>
+ struct is_char_encoding<spirit::char_encoding::unicode> : mpl::true_ {};
+#endif
+
     // Our basic terminals
     BOOST_SPIRIT_DEFINE_TERMINALS(
         ( verbatim )

Modified: trunk/boost/spirit/home/support/nonterminal/extract_param.hpp
==============================================================================
--- trunk/boost/spirit/home/support/nonterminal/extract_param.hpp (original)
+++ trunk/boost/spirit/home/support/nonterminal/extract_param.hpp 2010-03-05 10:40:27 EST (Fri, 05 Mar 2010)
@@ -16,6 +16,7 @@
 #include <boost/spirit/home/support/meta_compiler.hpp>
 #include <boost/spirit/home/support/nonterminal/locals.hpp>
 #include <boost/spirit/home/support/unused.hpp>
+#include <boost/spirit/home/support/common_terminals.hpp>
 
 #include <boost/function_types/is_function.hpp>
 #include <boost/function_types/parameter_types.hpp>
@@ -107,6 +108,17 @@
 
         typedef typename fusion::result_of::as_list<params>::type type;
     };
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Types>
+ struct extract_encoding
+ : extract_param<
+ Types
+ , is_char_encoding<mpl::_>
+ , unused_type
+ >
+ {};
 }}}
 
 #endif


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