|
Boost-Commit : |
From: eric_at_[hidden]
Date: 2007-11-28 20:11:41
Author: eric_niebler
Date: 2007-11-28 20:11:41 EST (Wed, 28 Nov 2007)
New Revision: 41450
URL: http://svn.boost.org/trac/boost/changeset/41450
Log:
handle list sets like (set= 'a','b','c')
Text files modified:
branches/proto/v3/boost/xpressive/detail/core/matcher/set_matcher.hpp | 8 +-
branches/proto/v3/boost/xpressive/detail/detail_fwd.hpp | 2
branches/proto/v3/boost/xpressive/detail/dynamic/parser.hpp | 3
branches/proto/v3/boost/xpressive/detail/static/grammar2.hpp | 126 +++++++++++++++++++++++++++++++++++----
branches/proto/v3/boost/xpressive/detail/static/transmogrify.hpp | 2
branches/proto/v3/boost/xpressive/xpressive_typeof.hpp | 2
6 files changed, 122 insertions(+), 21 deletions(-)
Modified: branches/proto/v3/boost/xpressive/detail/core/matcher/set_matcher.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/core/matcher/set_matcher.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/core/matcher/set_matcher.hpp 2007-11-28 20:11:41 EST (Wed, 28 Nov 2007)
@@ -30,12 +30,12 @@
///////////////////////////////////////////////////////////////////////////////
// set_matcher
//
-template<typename Traits, int Size>
+template<typename Traits, typename Size>
struct set_matcher
: quant_style_fixed_width<1>
{
typedef typename Traits::char_type char_type;
- char_type set_[ Size ];
+ char_type set_[ Size::value ];
bool not_;
bool icase_;
@@ -55,7 +55,7 @@
{
this->icase_ = true;
- for(int i = 0; i < Size; ++i)
+ for(int i = 0; i < Size::value; ++i)
{
this->set_[i] = traits.translate_nocase(this->set_[i]);
}
@@ -63,7 +63,7 @@
bool in_set(Traits const &traits, char_type ch) const
{
- char_type const *begin = &this->set_[0], *end = begin + Size;
+ char_type const *begin = &this->set_[0], *end = begin + Size::value;
ch = this->icase_ ? traits.translate_nocase(ch) : traits.translate(ch);
return end != std::find(begin, end, ch);
}
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-28 20:11:41 EST (Wed, 28 Nov 2007)
@@ -117,7 +117,7 @@
template<typename Traits, bool ICase>
struct range_matcher;
- template<typename Traits, int Size>
+ template<typename Traits, typename Size>
struct set_matcher;
template<typename Xpr, typename Greedy>
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-28 20:11:41 EST (Wed, 28 Nov 2007)
@@ -18,6 +18,7 @@
#endif
#include <boost/assert.hpp>
+#include <boost/mpl/integral_c.hpp>
#include <boost/xpressive/regex_constants.hpp>
#include <boost/xpressive/detail/detail_fwd.hpp>
#include <boost/xpressive/detail/core/matchers.hpp>
@@ -79,7 +80,7 @@
{
using namespace regex_constants;
typedef typename iterator_value<BidiIter>::type char_type;
- typedef set_matcher<Traits, 2> set_matcher;
+ typedef set_matcher<Traits, mpl::integral_c<int, 2> > set_matcher;
typedef literal_matcher<Traits, false, true> literal_matcher;
char_type const newline = traits.widen('\n');
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-28 20:11:41 EST (Wed, 28 Nov 2007)
@@ -18,6 +18,7 @@
#include <boost/mpl/assert.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/apply_wrap.hpp>
+#include <boost/mpl/next_prior.hpp>
#include <boost/fusion/include/cons.hpp>
#include <boost/xpressive/proto3/proto.hpp>
#include <boost/xpressive/proto3/transform.hpp>
@@ -200,6 +201,25 @@
}
};
+ struct traits : function_transform
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Visitor>
+ struct result<This(Visitor)>
+ {
+ typedef typename Visitor::traits_type type;
+ };
+
+ template<typename Visitor>
+ typename Visitor::traits_type const &
+ operator()(Visitor &visitor)
+ {
+ return visitor.traits();
+ }
+ };
+
// BUGBUG make_expr uses as_expr, not as_arg. Is that right?
typedef functional::make_expr<tag::shift_right> _make_shift_right;
typedef functional::make_expr<tag::terminal> _make_terminal;
@@ -207,15 +227,6 @@
typedef functional::make_expr<tag::logical_not> _make_logical_not;
typedef functional::make_expr<tag::negate> _make_negate;
- template<typename Visitor>
- struct traits_type
- {
- typedef typename Visitor::traits_type type;
- };
-
- struct greedy : mpl::true_ {};
- struct non_greedy : mpl::false_ {};
-
// Place a head and a tail in sequence, if it's not
// already in sequence.
struct in_sequence : function_transform
@@ -251,6 +262,76 @@
};
///////////////////////////////////////////////////////////////////////////
+ // CharLiteral
+ template<typename Char>
+ struct CharLiteral
+ : proto::or_<
+ proto::terminal<char>
+ , proto::terminal<Char>
+ >
+ {};
+
+ template<>
+ struct CharLiteral<char>
+ : proto::terminal<char>
+ {};
+
+ struct _one : mpl::int_<1> {};
+
+ ///////////////////////////////////////////////////////////////////////////
+ // ListSet
+ // matches expressions like (set= 'a','b','c')
+ // calculates the size of the set
+ // populates an array of characters
+ template<typename Char>
+ struct ListSet
+ : or_<
+ when<
+ comma<ListSet<Char>, CharLiteral<Char> >
+ , mpl::next<ListSet<Char>(_left)>()
+ >
+ , when<
+ assign<terminal<set_initializer>, CharLiteral<Char> >
+ , _one()
+ >
+ >
+ {};
+
+ struct fill_list_set : function_transform
+ {
+ template<typename Sig>
+ struct result;
+
+ template<typename This, typename Set, typename Expr, typename Visitor>
+ struct result<This(Set, Expr, Visitor)>
+ {
+ typedef Set type;
+ };
+
+ template<typename Set, typename Expr, typename Visitor>
+ Set operator()(Set set, Expr const &expr, Visitor &visitor) const
+ {
+ typename Set::char_type *buffer = set.set_;
+ this->fill(buffer, expr, visitor.traits());
+ return set;
+ }
+
+ private:
+ template<typename Char, typename Expr, typename Traits>
+ void fill(Char *&buffer, Expr const &expr, Traits const &traits) const
+ {
+ this->fill(buffer, proto::left(expr), traits);
+ *buffer++ = traits.translate(
+ char_cast<Char>(proto::arg(proto::right(expr)), traits)
+ );
+ }
+
+ template<typename Char, typename Traits>
+ void fill(Char *&, set_initializer_type, Traits const &) const
+ {}
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
// Cases
template<typename Char, typename Gram>
struct Cases
@@ -382,6 +463,17 @@
, optional_matcher<as_alternate, Greedy>(as_alternate)
>
{};
+
+ struct as_list_set
+ : apply_<
+ _
+ , fill_list_set(
+ set_matcher<traits(_visitor), ListSet<Char>(_) >()
+ , _
+ , _visitor
+ )
+ >
+ {};
// Here are the cases, which use the transforms defined above.
template<typename Tag, typename Dummy = void>
@@ -391,14 +483,14 @@
template<typename Dummy>
struct case_<tag::terminal, Dummy>
- : when< terminal<_>, as_matcher(_arg, _visitor) >
+ : when<_, as_matcher(_arg, _visitor)>
{};
template<typename Dummy>
struct case_<tag::shift_right, Dummy>
: when<
shift_right<Gram, Gram>
- , reverse_fold_tree<_, _state, in_sequence(Gram, _state) >
+ , reverse_fold_tree<_, _state, in_sequence(Gram, _state)>
>
{};
@@ -406,7 +498,7 @@
struct case_<tag::bitwise_or, Dummy>
: when<
bitwise_or<Gram, Gram>
- , alternate_matcher<as_alternates_list, traits_type<_visitor> >(as_alternates_list)
+ , alternate_matcher<as_alternates_list, traits(_visitor)>(as_alternates_list)
>
{};
@@ -442,7 +534,15 @@
template<typename Dummy>
struct case_<tag::assign, Dummy>
- : when<assign<terminal<mark_placeholder>, Gram>, Gram(as_marker)>
+ : or_<
+ when<assign<terminal<mark_placeholder>, Gram>, Gram(as_marker)>
+ , when<ListSet<Char>, as_list_set>
+ >
+ {};
+
+ template<typename Dummy>
+ struct case_<tag::comma, Dummy>
+ : when<ListSet<Char>, as_list_set>
{};
};
Modified: branches/proto/v3/boost/xpressive/detail/static/transmogrify.hpp
==============================================================================
--- branches/proto/v3/boost/xpressive/detail/static/transmogrify.hpp (original)
+++ branches/proto/v3/boost/xpressive/detail/static/transmogrify.hpp 2007-11-28 20:11:41 EST (Wed, 28 Nov 2007)
@@ -162,7 +162,7 @@
}
};
- template<typename BidiIter, typename Traits, int Size>
+ template<typename BidiIter, typename Traits, typename Size>
struct transmogrify<BidiIter, mpl::true_, Traits, set_matcher<Traits, Size> >
{
typedef set_matcher<Traits, Size> type;
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-28 20:11:41 EST (Wed, 28 Nov 2007)
@@ -98,7 +98,7 @@
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::keeper_matcher, (typename))
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::lookahead_matcher, (typename))
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::lookbehind_matcher, (typename))
-BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::set_matcher, (typename)(int))
+BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::set_matcher, (typename)(typename))
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::predicate_matcher, (typename))
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::action_matcher, (typename))
BOOST_TYPEOF_REGISTER_TEMPLATE(boost::xpressive::detail::attr_matcher, (typename)(typename)(bool))
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