Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2007-11-30 01:39:51


Author: eric_niebler
Date: 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
New Revision: 41486
URL: http://svn.boost.org/trac/boost/changeset/41486

Log:
handle compound sets like set['a' | alpha]
Text files modified:
   branches/proto/v3/boost/xpressive/detail/core/matcher/charset_matcher.hpp | 4
   branches/proto/v3/boost/xpressive/detail/core/peeker.hpp | 4
   branches/proto/v3/boost/xpressive/detail/detail_fwd.hpp | 2
   branches/proto/v3/boost/xpressive/detail/dynamic/parser.hpp | 8 +-
   branches/proto/v3/boost/xpressive/detail/static/grammar2.hpp | 88 +++++++++++++++++++++++++++++++++++++++
   branches/proto/v3/boost/xpressive/proto3/transform/fold_tree.hpp | 12 +++++
   branches/proto/v3/boost/xpressive/xpressive_typeof.hpp | 2
   7 files changed, 109 insertions(+), 11 deletions(-)

Modified: branches/proto/v3/boost/xpressive/detail/core/matcher/charset_matcher.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/core/matcher/charset_matcher.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/core/matcher/charset_matcher.hpp 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
@@ -23,13 +23,13 @@
     ///////////////////////////////////////////////////////////////////////////////
     // charset_matcher
     //
- template<typename Traits, bool ICase, typename CharSet>
+ template<typename Traits, typename ICase, typename CharSet>
     struct charset_matcher
       : quant_style_fixed_width<1>
     {
         typedef typename Traits::char_type char_type;
         typedef Traits traits_type;
- typedef mpl::bool_<ICase> icase_type;
+ typedef ICase icase_type;
 
         charset_matcher(CharSet const &charset = CharSet())
           : charset_(charset)

Modified: branches/proto/v3/boost/xpressive/detail/core/peeker.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/core/peeker.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/core/peeker.hpp 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
@@ -209,12 +209,12 @@
         return mpl::false_();
     }
 
- template<bool ICase, typename Traits>
+ template<typename ICase, typename Traits>
     typename enable_if<is_narrow_char<typename Traits::char_type>, mpl::false_>::type
     accept(charset_matcher<Traits, ICase, basic_chset<Char> > const &xpr)
     {
         BOOST_ASSERT(0 != xpr.charset_.base().count());
- this->bset_.set_charset(xpr.charset_, ICase);
+ this->bset_.set_charset(xpr.charset_, ICase::value);
         return mpl::false_();
     }
 

Modified: branches/proto/v3/boost/xpressive/detail/detail_fwd.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/detail_fwd.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/detail_fwd.hpp 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
@@ -111,7 +111,7 @@
     template<typename Traits>
     struct compound_charset;
 
- template<typename Traits, bool ICase, typename CharSet = compound_charset<Traits> >
+ template<typename Traits, typename ICase, typename CharSet = compound_charset<Traits> >
     struct charset_matcher;
 
     template<typename Traits, typename ICase>

Modified: branches/proto/v3/boost/xpressive/detail/dynamic/parser.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/dynamic/parser.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/dynamic/parser.hpp 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
@@ -227,13 +227,13 @@
         charset_type charset(chset.base());
         if(icase)
         {
- charset_matcher<Traits, true, charset_type> matcher(charset);
+ charset_matcher<Traits, true_, charset_type> matcher(charset);
             merge_charset(matcher.charset_, chset, traits);
             return make_dynamic<BidiIter>(matcher);
         }
         else
         {
- charset_matcher<Traits, false, charset_type> matcher(charset);
+ charset_matcher<Traits, false_, charset_type> matcher(charset);
             merge_charset(matcher.charset_, chset, traits);
             return make_dynamic<BidiIter>(matcher);
         }
@@ -252,12 +252,12 @@
     {
         if(icase)
         {
- charset_matcher<Traits, true> matcher(chset);
+ charset_matcher<Traits, true_> matcher(chset);
             return make_dynamic<BidiIter>(matcher);
         }
         else
         {
- charset_matcher<Traits, false> matcher(chset);
+ charset_matcher<Traits, false_> matcher(chset);
             return make_dynamic<BidiIter>(matcher);
         }
     }

Modified: branches/proto/v3/boost/xpressive/detail/static/grammar2.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/static/grammar2.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/static/grammar2.hpp 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
@@ -371,7 +371,63 @@
             void fill(Char *&, set_initializer_type, Traits const &) const
             {}
         };
-
+
+ template<typename T>
+ T &uncv(T const volatile &t)
+ {
+ return const_cast<T &>(t);
+ }
+
+ struct merge_charset : function_transform
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename CharSet, typename Xpr, typename Visitor>
+ struct result<This(CharSet, Xpr, Visitor)>
+ {
+ typedef CharSet type;
+ };
+
+ template<typename CharSet, typename Traits, typename ICase, typename Not, typename Visitor>
+ CharSet const &
+ operator()(CharSet const &charset, literal_matcher<Traits, ICase, Not> const &ch, Visitor &visitor) const
+ {
+ BOOST_MPL_ASSERT_NOT((Not)); // TODO fixme!
+ set_char(uncv(charset.charset_), ch.ch_, visitor.traits(), ICase());
+ return charset;
+ }
+
+ template<typename CharSet, typename Traits, typename ICase, typename Visitor>
+ CharSet const &
+ operator()(CharSet const &charset, range_matcher<Traits, ICase> const &rg, Visitor &visitor) const
+ {
+ BOOST_ASSERT(!rg.not_); // TODO fixme!
+ set_range(uncv(charset.charset_), rg.ch_min_, rg.ch_max_, visitor.traits(), ICase());
+ return charset;
+ }
+
+ template<typename CharSet, typename Traits, typename Size, typename Visitor>
+ CharSet const &
+ operator()(CharSet const &charset, set_matcher<Traits, Size> const &set_, Visitor &visitor) const
+ {
+ BOOST_ASSERT(!set_.not_); // TODO fixme!
+ for(int i=0; i < Size::value; ++i)
+ {
+ set_char(uncv(charset.charset_), set_.set_[i], visitor.traits(), Visitor::icase_type::value);
+ }
+ return charset;
+ }
+
+ template<typename CharSet, typename Traits, typename Visitor>
+ CharSet const &
+ operator()(CharSet const &charset, posix_charset_matcher<Traits> const &posix, Visitor &visitor) const
+ {
+ set_class(uncv(charset.charset_), posix.mask_, posix.not_, visitor.traits());
+ return charset;
+ }
+ };
+
         ///////////////////////////////////////////////////////////////////////////
         // Cases
         template<typename Char, typename Gram>
@@ -516,6 +572,22 @@
>
             {};
 
+ struct as_set
+ : fold_tree<
+ _
+ , charset_matcher<
+ traits(_visitor)
+ , icase<_visitor>
+ , if_<
+ is_narrow_char<Char>()
+ , basic_chset<Char>()
+ , compound_charset<traits(_visitor)>()
+ >
+ >()
+ , merge_charset(_state, Gram(_make_shift_right(_, end_matcher()), no_next()), _visitor)
+ >
+ {};
+
             // Here are the cases, which use the transforms defined above.
             template<typename Tag, typename Dummy = void>
             struct case_
@@ -661,6 +733,20 @@
>
>
             {};
+
+ template<typename Dummy>
+ struct case_<tag::subscript, Dummy>
+ : or_<
+ when<
+ subscript<terminal<set_initializer>, bitwise_or<Gram, Gram> >
+ , as_set(_right)
+ >
+ , when<
+ subscript<terminal<set_initializer>, terminal<_> >
+ , as_matcher(_arg(_right), _visitor)
+ >
+ >
+ {};
         };
 
     } // namespace detail

Modified: branches/proto/v3/boost/xpressive/proto3/transform/fold_tree.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/proto3/transform/fold_tree.hpp (original)
+++ branches/proto/v3/boost/xpressive/proto3/transform/fold_tree.hpp 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
@@ -103,12 +103,24 @@
         typedef raw_transform type;
     };
 
+ template<typename Grammar, typename Fun>
+ struct transform_category<transform::detail::fold_tree_<Grammar, Fun> >
+ {
+ typedef raw_transform type;
+ };
+
     template<typename Sequence, typename State0, typename Fun>
     struct transform_category<transform::reverse_fold_tree<Sequence, State0, Fun> >
     {
         typedef raw_transform type;
     };
 
+ template<typename Grammar, typename Fun>
+ struct transform_category<transform::detail::reverse_fold_tree_<Grammar, Fun> >
+ {
+ typedef raw_transform type;
+ };
+
 }}
 
 #endif

Modified: branches/proto/v3/boost/xpressive/xpressive_typeof.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/xpressive_typeof.hpp (original)
+++ branches/proto/v3/boost/xpressive/xpressive_typeof.hpp 2007-11-30 01:39:49 EST (Fri, 30 Nov 2007)
@@ -82,7 +82,7 @@
 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::assert_eol_matcher, (typename))
 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::literal_matcher, (typename)(typename)(typename))
 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::string_matcher, (typename)(bool))
-BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::charset_matcher, (typename)(bool)(typename))
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::charset_matcher, (typename)(typename)(typename))
 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::logical_newline_matcher, (typename))
 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::mark_matcher, (typename)(bool))
 BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::repeat_end_matcher, (typename))


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