Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60256 - in trunk/boost/spirit/home: karma karma/auto karma/char karma/directive karma/nonterminal karma/string support/nonterminal
From: hartmut.kaiser_at_[hidden]
Date: 2010-03-06 16:58:10


Author: hkaiser
Date: 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
New Revision: 60256
URL: http://svn.boost.org/trac/boost/changeset/60256

Log:
Spirit: implemented new encoding features for Karma
Added:
   trunk/boost/spirit/home/karma/directive/encoding.hpp (contents, props changed)
Text files modified:
   trunk/boost/spirit/home/karma/auto/meta_create.hpp | 40 ++++++++++++++++++++--------------------
   trunk/boost/spirit/home/karma/char/char.hpp | 24 ++++++++++++------------
   trunk/boost/spirit/home/karma/char/char_class.hpp | 8 ++++++++
   trunk/boost/spirit/home/karma/directive.hpp | 2 ++
   trunk/boost/spirit/home/karma/nonterminal/grammar.hpp | 21 ++++++++++++---------
   trunk/boost/spirit/home/karma/nonterminal/rule.hpp | 34 ++++++++++++++++++++++++++--------
   trunk/boost/spirit/home/karma/string/lit.hpp | 8 ++++----
   trunk/boost/spirit/home/support/nonterminal/extract_param.hpp | 1 -
   8 files changed, 84 insertions(+), 54 deletions(-)

Modified: trunk/boost/spirit/home/karma/auto/meta_create.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/auto/meta_create.hpp (original)
+++ trunk/boost/spirit/home/karma/auto/meta_create.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -51,57 +51,57 @@
     template <typename String>
     struct meta_create_string
     {
- typedef spirit::standard::string_type type;
- static type const& call() { return spirit::standard::string; }
+ typedef spirit::default_encoding::string_type type;
+ static type const& call() { return spirit::default_encoding::string; }
     };
 
     template <>
     struct meta_create_string<wchar_t*>
     {
- typedef spirit::standard_wide::string_type type;
- static type const& call() { return spirit::standard_wide::string; }
+ typedef spirit::default_wide_encoding::string_type type;
+ static type const& call() { return spirit::default_wide_encoding::string; }
     };
 
     template <>
     struct meta_create_string<wchar_t const*>
     {
- typedef spirit::standard_wide::string_type type;
- static type const& call() { return spirit::standard_wide::string; }
+ typedef spirit::default_wide_encoding::string_type type;
+ static type const& call() { return spirit::default_wide_encoding::string; }
     };
 
     template <int N>
     struct meta_create_string<wchar_t[N]>
     {
- typedef spirit::standard_wide::string_type type;
- static type const& call() { return spirit::standard_wide::string; }
+ typedef spirit::default_wide_encoding::string_type type;
+ static type const& call() { return spirit::default_wide_encoding::string; }
     };
 
     template <int N>
     struct meta_create_string<wchar_t const[N]>
     {
- typedef spirit::standard_wide::string_type type;
- static type const& call() { return spirit::standard_wide::string; }
+ typedef spirit::default_wide_encoding::string_type type;
+ static type const& call() { return spirit::default_wide_encoding::string; }
     };
 
     template <int N>
     struct meta_create_string<wchar_t(&)[N]>
     {
- typedef spirit::standard_wide::string_type type;
- static type const& call() { return spirit::standard_wide::string; }
+ typedef spirit::default_wide_encoding::string_type type;
+ static type const& call() { return spirit::default_wide_encoding::string; }
     };
 
     template <int N>
     struct meta_create_string<wchar_t const(&)[N]>
     {
- typedef spirit::standard_wide::string_type type;
- static type const& call() { return spirit::standard_wide::string; }
+ typedef spirit::default_wide_encoding::string_type type;
+ static type const& call() { return spirit::default_wide_encoding::string; }
     };
 
     template <typename Traits, typename Allocator>
     struct meta_create_string<std::basic_string<wchar_t, Traits, Allocator> >
     {
- typedef spirit::standard_wide::string_type type;
- static type const& call() { return spirit::standard_wide::string; }
+ typedef spirit::default_wide_encoding::string_type type;
+ static type const& call() { return spirit::default_wide_encoding::string; }
     };
 
     ///////////////////////////////////////////////////////////////////////////
@@ -203,14 +203,14 @@
     template <>
     struct meta_create<char>
     {
- typedef spirit::standard::char_type type;
- static type const& call() { return spirit::standard::char_; }
+ typedef spirit::default_encoding::char_type type;
+ static type const& call() { return spirit::default_encoding::char_; }
     };
     template <>
     struct meta_create<wchar_t>
     {
- typedef spirit::standard_wide::char_type type;
- static type const& call() { return spirit::standard_wide::char_; }
+ typedef spirit::default_wide_encoding::char_type type;
+ static type const& call() { return spirit::default_wide_encoding::char_; }
     };
 
     // boolean generator

Modified: trunk/boost/spirit/home/karma/char/char.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/char/char.hpp (original)
+++ trunk/boost/spirit/home/karma/char/char.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -354,29 +354,29 @@
     // literals: 'x', "x"
     template <typename Modifiers>
     struct make_primitive<char, Modifiers>
- : detail::basic_literal<Modifiers, char_encoding::standard> {};
+ : detail::basic_literal<Modifiers, char_encoding::default_encoding> {};
 
     template <typename Modifiers>
     struct make_primitive<char const(&)[2], Modifiers>
- : detail::basic_literal<Modifiers, char_encoding::standard> {};
+ : detail::basic_literal<Modifiers, char_encoding::default_encoding> {};
 
     // literals: L'x', L"x"
     template <typename Modifiers>
     struct make_primitive<wchar_t, Modifiers>
- : detail::basic_literal<Modifiers, char_encoding::standard_wide> {};
+ : detail::basic_literal<Modifiers, char_encoding::default_wide_encoding> {};
 
     template <typename Modifiers>
     struct make_primitive<wchar_t const(&)[2], Modifiers>
- : detail::basic_literal<Modifiers, char_encoding::standard_wide> {};
+ : detail::basic_literal<Modifiers, char_encoding::default_wide_encoding> {};
 
     // char_
     template <typename CharEncoding, typename Modifiers>
     struct make_primitive<tag::char_code<tag::char_, CharEncoding>, Modifiers>
     {
         static bool const lower =
- has_modifier<Modifiers, tag::char_code<tag::lower, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
         static bool const upper =
- has_modifier<Modifiers, tag::char_code<tag::upper, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
 
         typedef any_char<
             typename spirit::detail::get_encoding_with_case<
@@ -400,9 +400,9 @@
       , Modifiers>
     {
         static bool const lower =
- has_modifier<Modifiers, tag::char_code<tag::lower, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
         static bool const upper =
- has_modifier<Modifiers, tag::char_code<tag::upper, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
 
         typedef typename spirit::detail::get_encoding_with_case<
             Modifiers, CharEncoding, lower || upper>::type encoding;
@@ -432,9 +432,9 @@
       , Modifiers>
     {
         static bool const lower =
- has_modifier<Modifiers, tag::char_code<tag::lower, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
         static bool const upper =
- has_modifier<Modifiers, tag::char_code<tag::upper, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
 
         typedef literal_char<
             typename spirit::detail::get_encoding_with_case<
@@ -460,9 +460,9 @@
       , Modifiers>
     {
         static bool const lower =
- has_modifier<Modifiers, tag::char_code<tag::lower, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
         static bool const upper =
- has_modifier<Modifiers, tag::char_code<tag::upper, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
 
         typedef char_range<
             typename spirit::detail::get_encoding_with_case<

Modified: trunk/boost/spirit/home/karma/char/char_class.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/char/char_class.hpp (original)
+++ trunk/boost/spirit/home/karma/char/char_class.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -42,16 +42,24 @@
 {
     // hoist the char classification namespaces into karma sub-namespaces of
     // the same name
+ namespace default_encoding { using namespace boost::spirit::default_encoding; }
+ namespace default_wide_encoding { using namespace boost::spirit::default_wide_encoding; }
     namespace ascii { using namespace boost::spirit::ascii; }
     namespace iso8859_1 { using namespace boost::spirit::iso8859_1; }
     namespace standard { using namespace boost::spirit::standard; }
     namespace standard_wide { using namespace boost::spirit::standard_wide; }
+#if defined(BOOST_SPIRIT_UNICODE)
+ namespace unicode { using namespace boost::spirit::unicode; }
+#endif
 
     // Import the standard namespace into the karma namespace. This allows
     // for default handling of all character/string related operations if not
     // prefixed with a character set namespace.
     using namespace boost::spirit::standard;
 
+ // Import encoding
+ using spirit::encoding;
+
     ///////////////////////////////////////////////////////////////////////////
     //
     // char_class

Modified: trunk/boost/spirit/home/karma/directive.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/directive.hpp (original)
+++ trunk/boost/spirit/home/karma/directive.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -10,6 +10,8 @@
 #pragma once
 #endif
 
+#include <boost/spirit/home/karma/directive/encoding.hpp>
+
 ///////////////////////////////////////////////////////////////////////////////
 // directives related to alignment
 // left_align[...], right_align[...], center[...]

Added: trunk/boost/spirit/home/karma/directive/encoding.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/karma/directive/encoding.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -0,0 +1,35 @@
+// Copyright (c) 2001-2010 Joel de Guzman
+// Copyright (c) 2001-2010 Hartmut Kaiser
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#if !defined(SPIRIT_KARMA_ENCODING_MARCH_05_2010_0550PM)
+#define SPIRIT_KARMA_ENCODING_MARCH_05_2010_0550PM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/karma/meta_compiler.hpp>
+#include <boost/spirit/home/support/common_terminals.hpp>
+
+namespace boost { namespace spirit
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // Enablers
+ ///////////////////////////////////////////////////////////////////////////
+
+ // enables encoding
+ template <typename CharEncoding>
+ struct use_directive<
+ karma::domain, tag::char_code<tag::encoding, CharEncoding> >
+ : mpl::true_ {};
+
+ template <typename CharEncoding>
+ struct is_modifier_directive<
+ karma::domain, tag::char_code<tag::encoding, CharEncoding> >
+ : mpl::true_ {};
+}}
+
+#endif

Modified: trunk/boost/spirit/home/karma/nonterminal/grammar.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/nonterminal/grammar.hpp (original)
+++ trunk/boost/spirit/home/karma/nonterminal/grammar.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -27,24 +27,26 @@
       , 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<OutputIterator, T1, T2, T3> const>
+ reference<rule<OutputIterator, T1, T2, T3, T4> const>
>::type
- , grammar<OutputIterator, T1, T2, T3>
+ , grammar<OutputIterator, T1, T2, T3, T4>
>
- , generator<grammar<OutputIterator, T1, T2, T3> >
+ , generator<grammar<OutputIterator, T1, T2, T3, T4> >
       , noncopyable
     {
         typedef OutputIterator iterator_type;
- typedef rule<OutputIterator, T1, T2, T3> start_type;
+ typedef rule<OutputIterator, T1, T2, T3, T4> start_type;
         typedef typename start_type::properties properties;
         typedef typename start_type::sig_type sig_type;
         typedef typename start_type::locals_type locals_type;
         typedef typename start_type::delimiter_type delimiter_type;
- typedef grammar<OutputIterator, T1, T2, T3> base_type;
+ typedef typename start_type::encoding_type encoding_type;
+ typedef grammar<OutputIterator, T1, T2, T3, T4> base_type;
         typedef reference<start_type const> reference_;
         typedef typename proto::terminal<reference_>::type terminal;
 
@@ -62,16 +64,17 @@
 
         // 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_>
- grammar(rule<Iterator_, T1_, T2_, T3_> const&
+ template <typename Iterator_, typename T1_, typename T2_, typename T3_,
+ typename T4_>
+ grammar(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
             // 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/karma/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/karma/nonterminal/rule.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -68,24 +68,25 @@
       , 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<OutputIterator, T1, T2, T3> const>
+ reference<rule<OutputIterator, T1, T2, T3, T4> const>
>::type
- , rule<OutputIterator, T1, T2, T3>
+ , rule<OutputIterator, T1, T2, T3, T4>
>
- , generator<rule<OutputIterator, T1, T2, T3> >
+ , generator<rule<OutputIterator, T1, T2, T3, T4> >
     {
         typedef mpl::int_<generator_properties::all_properties> properties;
 
         typedef OutputIterator iterator_type;
- typedef rule<OutputIterator, T1, T2, T3> this_type;
+ typedef rule<OutputIterator, 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;
 
         // the output iterator is always wrapped by karma
         typedef detail::output_iterator<OutputIterator, properties>
@@ -102,10 +103,16 @@
                 karma::domain, template_params>::type
         delimiter_type;
 
+ // The rule's signature
         typedef typename
             spirit::detail::extract_sig<template_params>::type
         sig_type;
 
+ // The rule's encoding 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
@@ -133,6 +140,14 @@
             bool(output_iterator&, context_type&, delimiter_type const&)>
         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_)
@@ -156,7 +171,8 @@
             // the expression (expr) is not a valid spirit karma expression.
             BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
 
- f = detail::bind_generator<mpl::false_>(compile<karma::domain>(expr));
+ f = detail::bind_generator<mpl::false_>(
+ compile<karma::domain>(expr, encoding_modifier_type()));
         }
 
         rule& operator=(rule const& rhs)
@@ -190,7 +206,8 @@
             // the expression (expr) is not a valid spirit karma expression.
             BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
 
- f = detail::bind_generator<mpl::false_>(compile<karma::domain>(expr));
+ f = detail::bind_generator<mpl::false_>(
+ compile<karma::domain>(expr, encoding_modifier_type()));
             return *this;
         }
 
@@ -203,7 +220,8 @@
             // the expression (expr) is not a valid spirit karma expression.
             BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
 
- r.f = detail::bind_generator<mpl::true_>(compile<karma::domain>(expr));
+ r.f = detail::bind_generator<mpl::true_>(
+ compile<karma::domain>(expr, encoding_modifier_type()));
             return r;
         }
 

Modified: trunk/boost/spirit/home/karma/string/lit.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/string/lit.hpp (original)
+++ trunk/boost/spirit/home/karma/string/lit.hpp 2010-03-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -197,9 +197,9 @@
       , Modifiers>
     {
         static bool const lower =
- has_modifier<Modifiers, tag::char_code<tag::lower, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
         static bool const upper =
- has_modifier<Modifiers, tag::char_code<tag::upper, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
 
         typedef any_string<
             typename spirit::detail::get_encoding_with_case<
@@ -248,9 +248,9 @@
       , Modifiers>
     {
         static bool const lower =
- has_modifier<Modifiers, tag::char_code<tag::lower, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
         static bool const upper =
- has_modifier<Modifiers, tag::char_code<tag::upper, CharEncoding> >::value;
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
 
         typedef typename add_const<A0>::type const_string;
         typedef literal_string<

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-06 16:58:09 EST (Sat, 06 Mar 2010)
@@ -109,7 +109,6 @@
         typedef typename fusion::result_of::as_list<params>::type type;
     };
 
-
     ///////////////////////////////////////////////////////////////////////////
     template <typename Types>
     struct extract_encoding


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