stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// compile.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
#include <boost/xpressive/regex_traits.hpp>
|
||||
#include <boost/xpressive/detail/core/regex_impl.hpp>
|
||||
#include <boost/xpressive/detail/core/linker.hpp>
|
||||
#include <boost/xpressive/detail/core/optimize.hpp>
|
||||
#include <boost/xpressive/detail/core/adaptor.hpp>
|
||||
#include <boost/xpressive/detail/core/matcher/end_matcher.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/xpressive/detail/static/visitor.hpp>
|
||||
#include <boost/xpressive/detail/static/grammar.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// static_compile_impl2
|
||||
template<typename Xpr, typename BidiIter, typename Traits>
|
||||
void static_compile_impl2(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl, Traits const &tr)
|
||||
{
|
||||
typedef typename iterator_value<BidiIter>::type char_type;
|
||||
impl->tracking_clear();
|
||||
impl->traits_ = new traits_holder<Traits>(tr);
|
||||
|
||||
// "compile" the regex and wrap it in an xpression_adaptor.
|
||||
typedef xpression_visitor<BidiIter, mpl::false_, Traits> visitor_type;
|
||||
visitor_type visitor(tr, impl);
|
||||
intrusive_ptr<matchable_ex<BidiIter> const> adxpr = make_adaptor<matchable_ex<BidiIter> >(
|
||||
typename Grammar<char_type>::template impl<Xpr const &, end_xpression, visitor_type &>()(
|
||||
xpr
|
||||
, end_xpression()
|
||||
, visitor
|
||||
)
|
||||
);
|
||||
|
||||
// Link and optimize the regex
|
||||
common_compile(adxpr, *impl, visitor.traits());
|
||||
|
||||
// References changed, update dependencies.
|
||||
impl->tracking_update();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// pattern for imbued regexes.
|
||||
struct XpressiveLocaleModifier
|
||||
: proto::binary_expr<
|
||||
modifier_tag
|
||||
, proto::terminal<locale_modifier<proto::_> >
|
||||
, proto::_
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// static_compile_impl1
|
||||
template<typename Xpr, typename BidiIter>
|
||||
typename disable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type
|
||||
static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
|
||||
{
|
||||
// use default traits
|
||||
typedef typename iterator_value<BidiIter>::type char_type;
|
||||
typedef typename default_regex_traits<char_type>::type traits_type;
|
||||
traits_type tr;
|
||||
static_compile_impl2(xpr, impl, tr);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// static_compile_impl1
|
||||
template<typename Xpr, typename BidiIter>
|
||||
typename enable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type
|
||||
static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
|
||||
{
|
||||
// use specified traits
|
||||
typedef typename proto::result_of::value<typename proto::result_of::left<Xpr>::type>::type::locale_type locale_type;
|
||||
typedef typename regex_traits_type<locale_type, BidiIter>::type traits_type;
|
||||
static_compile_impl2(proto::right(xpr), impl, traits_type(proto::value(proto::left(xpr)).getloc()));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// static_compile
|
||||
template<typename Xpr, typename BidiIter>
|
||||
void static_compile(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
|
||||
{
|
||||
static_compile_impl1(xpr, impl);
|
||||
}
|
||||
|
||||
}}} // namespace boost::xpressive::detail
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,365 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// grammar.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_GRAMMAR_HPP_EAN_11_12_2006
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_GRAMMAR_HPP_EAN_11_12_2006
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
#include <boost/xpressive/detail/static/is_pure.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_matcher.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_alternate.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_sequence.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_quantifier.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_marker.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_set.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_independent.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_modifier.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_inverse.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_action.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
|
||||
#define BOOST_XPRESSIVE_CHECK_REGEX(Expr, Char)\
|
||||
BOOST_MPL_ASSERT\
|
||||
((\
|
||||
typename boost::mpl::if_c<\
|
||||
boost::xpressive::is_valid_regex<Expr, Char>::value\
|
||||
, boost::mpl::true_\
|
||||
, boost::xpressive::INVALID_REGULAR_EXPRESSION\
|
||||
>::type\
|
||||
));
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//**********************************************************************//
|
||||
//* << NOTE! >> *//
|
||||
//* *//
|
||||
//* Whenever you change this grammar, you MUST also make corresponding *//
|
||||
//* changes to width_of.hpp and is_pure.hpp. *//
|
||||
//* *//
|
||||
//**********************************************************************//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
namespace boost { namespace xpressive
|
||||
{
|
||||
template<typename Char>
|
||||
struct Grammar;
|
||||
|
||||
template<typename Char>
|
||||
struct ActionableGrammar;
|
||||
|
||||
namespace grammar_detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// CharLiteral
|
||||
template<typename Char>
|
||||
struct CharLiteral;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ListSet
|
||||
template<typename Char>
|
||||
struct ListSet;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// as_repeat
|
||||
template<typename Char, typename Gram, typename Greedy>
|
||||
struct as_repeat
|
||||
: if_<
|
||||
make<detail::use_simple_repeat<_child, Char> >
|
||||
, as_simple_quantifier<Gram, Greedy>
|
||||
, as_default_quantifier<Greedy>
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// NonGreedyRepeatCases
|
||||
template<typename Gram>
|
||||
struct NonGreedyRepeatCases
|
||||
{
|
||||
template<typename Tag, typename Dummy = void>
|
||||
struct case_
|
||||
: not_<_>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::dereference, Dummy>
|
||||
: dereference<Gram>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::unary_plus, Dummy>
|
||||
: unary_plus<Gram>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::logical_not, Dummy>
|
||||
: logical_not<Gram>
|
||||
{};
|
||||
|
||||
template<uint_t Min, uint_t Max, typename Dummy>
|
||||
struct case_<detail::generic_quant_tag<Min, Max>, Dummy>
|
||||
: unary_expr<detail::generic_quant_tag<Min, Max>, Gram>
|
||||
{};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// InvertibleCases
|
||||
template<typename Char, typename Gram>
|
||||
struct InvertibleCases
|
||||
{
|
||||
template<typename Tag, typename Dummy = void>
|
||||
struct case_
|
||||
: not_<_>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::comma, Dummy>
|
||||
: when<ListSet<Char>, as_list_set_matcher<Char> >
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::assign, Dummy>
|
||||
: when<ListSet<Char>, as_list_set_matcher<Char> >
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::subscript, Dummy>
|
||||
: when<subscript<detail::set_initializer_type, Gram>, call<as_set_matcher<Gram>(_right)> >
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<detail::lookahead_tag, Dummy>
|
||||
: when<
|
||||
unary_expr<detail::lookahead_tag, Gram>
|
||||
, as_lookahead<Gram>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<detail::lookbehind_tag, Dummy>
|
||||
: when<
|
||||
unary_expr<detail::lookbehind_tag, Gram>
|
||||
, as_lookbehind<Gram>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::terminal, Dummy>
|
||||
: when<
|
||||
or_<
|
||||
CharLiteral<Char>
|
||||
, terminal<detail::posix_charset_placeholder>
|
||||
, terminal<detail::range_placeholder<_> >
|
||||
, terminal<detail::logical_newline_placeholder>
|
||||
, terminal<detail::assert_word_placeholder<detail::word_boundary<mpl::true_> > >
|
||||
>
|
||||
, as_matcher
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Cases
|
||||
template<typename Char, typename Gram>
|
||||
struct Cases
|
||||
{
|
||||
template<typename Tag, typename Dummy = void>
|
||||
struct case_
|
||||
: not_<_>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::terminal, Dummy>
|
||||
: when<
|
||||
_
|
||||
, in_sequence<as_matcher>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::shift_right, Dummy>
|
||||
: when<
|
||||
shift_right<Gram, Gram>
|
||||
, reverse_fold<_, _state, Gram>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::bitwise_or, Dummy>
|
||||
: when<
|
||||
bitwise_or<Gram, Gram>
|
||||
, in_sequence<
|
||||
as_alternate_matcher<
|
||||
reverse_fold_tree<_, make<fusion::nil>, in_alternate_list<Gram> >
|
||||
>
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy, typename Greedy>
|
||||
struct case_<optional_tag<Greedy> , Dummy>
|
||||
: when<
|
||||
unary_expr<optional_tag<Greedy>, Gram>
|
||||
, in_sequence<call<as_optional<Gram, Greedy>(_child)> >
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::dereference, Dummy>
|
||||
: when<
|
||||
dereference<Gram>
|
||||
, call<Gram(as_repeat<Char, Gram, mpl::true_>)>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::unary_plus, Dummy>
|
||||
: when<
|
||||
unary_plus<Gram>
|
||||
, call<Gram(as_repeat<Char, Gram, mpl::true_>)>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::logical_not, Dummy>
|
||||
: when<
|
||||
logical_not<Gram>
|
||||
, call<Gram(as_repeat<Char, Gram, mpl::true_>)>
|
||||
>
|
||||
{};
|
||||
|
||||
template<uint_t Min, uint_t Max, typename Dummy>
|
||||
struct case_<detail::generic_quant_tag<Min, Max>, Dummy>
|
||||
: when<
|
||||
unary_expr<detail::generic_quant_tag<Min, Max>, Gram>
|
||||
, call<Gram(as_repeat<Char, Gram, mpl::true_>)>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::negate, Dummy>
|
||||
: when<
|
||||
negate<switch_<NonGreedyRepeatCases<Gram> > >
|
||||
, call<Gram(call<as_repeat<Char, Gram, mpl::false_>(_child)>)>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::complement, Dummy>
|
||||
: when<
|
||||
complement<switch_<InvertibleCases<Char, Gram> > >
|
||||
, in_sequence<call<as_inverse(call<switch_<InvertibleCases<Char, Gram> >(_child)>)> >
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<detail::modifier_tag, Dummy>
|
||||
: when<binary_expr<detail::modifier_tag, _, Gram>, as_modifier<Gram> >
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<detail::lookahead_tag, Dummy>
|
||||
: when<
|
||||
unary_expr<detail::lookahead_tag, Gram>
|
||||
, in_sequence<as_lookahead<Gram> >
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<detail::lookbehind_tag, Dummy>
|
||||
: when<
|
||||
unary_expr<detail::lookbehind_tag, Gram>
|
||||
, in_sequence<as_lookbehind<Gram> >
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<detail::keeper_tag, Dummy>
|
||||
: when<
|
||||
unary_expr<detail::keeper_tag, Gram>
|
||||
, in_sequence<as_keeper<Gram> >
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::comma, Dummy>
|
||||
: when<ListSet<Char>, in_sequence<as_list_set_matcher<Char> > >
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::assign, Dummy>
|
||||
: or_<
|
||||
when<assign<detail::basic_mark_tag, Gram>, call<Gram(as_marker)> >
|
||||
, when<ListSet<Char>, in_sequence<as_list_set_matcher<Char> > >
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Dummy>
|
||||
struct case_<tag::subscript, Dummy>
|
||||
: or_<
|
||||
when<subscript<detail::set_initializer_type, Gram>, in_sequence<call<as_set_matcher<Gram>(_right)> > >
|
||||
, when<subscript<ActionableGrammar<Char>, _>, call<ActionableGrammar<Char>(as_action)> >
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ActionableCases
|
||||
template<typename Char, typename Gram>
|
||||
struct ActionableCases
|
||||
{
|
||||
template<typename Tag, typename Dummy = void>
|
||||
struct case_
|
||||
: Cases<Char, Gram>::template case_<Tag>
|
||||
{};
|
||||
|
||||
// Only in sub-expressions with actions attached do we allow attribute assignements
|
||||
template<typename Dummy>
|
||||
struct case_<proto::tag::assign, Dummy>
|
||||
: or_<
|
||||
typename Cases<Char, Gram>::template case_<proto::tag::assign>
|
||||
, when<proto::assign<terminal<detail::attribute_placeholder<_> >, _>, in_sequence<as_attr_matcher> >
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Grammar
|
||||
template<typename Char>
|
||||
struct Grammar
|
||||
: proto::switch_<grammar_detail::Cases<Char, Grammar<Char> > >
|
||||
{};
|
||||
|
||||
template<typename Char>
|
||||
struct ActionableGrammar
|
||||
: proto::switch_<grammar_detail::ActionableCases<Char, ActionableGrammar<Char> > >
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// INVALID_REGULAR_EXPRESSION
|
||||
struct INVALID_REGULAR_EXPRESSION
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// is_valid_regex
|
||||
template<typename Expr, typename Char>
|
||||
struct is_valid_regex
|
||||
: proto::matches<Expr, Grammar<Char> >
|
||||
{};
|
||||
|
||||
}} // namespace boost::xpressive
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,216 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// is_pure.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_IS_PURE_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_IS_PURE_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/not_equal_to.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/width_of.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// use_simple_repeat_terminal
|
||||
//
|
||||
template<typename Expr, typename Char, bool IsXpr = is_xpr<Expr>::value>
|
||||
struct use_simple_repeat_terminal
|
||||
: mpl::bool_<
|
||||
Expr::quant == quant_fixed_width
|
||||
|| (Expr::width != unknown_width::value && Expr::pure)
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_terminal<Expr, Char, false>
|
||||
: mpl::true_ // char literals, string literals, etc.
|
||||
{};
|
||||
|
||||
template<typename BidiIter, typename Char>
|
||||
struct use_simple_repeat_terminal<tracking_ptr<regex_impl<BidiIter> >, Char, false>
|
||||
: mpl::false_ // basic_regex
|
||||
{};
|
||||
|
||||
template<typename BidiIter, typename Char>
|
||||
struct use_simple_repeat_terminal<reference_wrapper<basic_regex<BidiIter> >, Char, false>
|
||||
: mpl::false_ // basic_regex
|
||||
{};
|
||||
|
||||
template<typename BidiIter, typename Char>
|
||||
struct use_simple_repeat_terminal<reference_wrapper<basic_regex<BidiIter> const>, Char, false>
|
||||
: mpl::false_ // basic_regex
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// use_simple_repeat_
|
||||
//
|
||||
template<typename Expr, typename Char, typename Tag = typename Expr::proto_tag>
|
||||
struct use_simple_repeat_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::terminal>
|
||||
: use_simple_repeat_terminal<typename proto::result_of::value<Expr>::type, Char>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::shift_right>
|
||||
: mpl::and_<
|
||||
use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
, use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::bitwise_or>
|
||||
: mpl::and_<
|
||||
mpl::not_equal_to<unknown_width, width_of<Expr, Char> >
|
||||
, use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
, use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Left>
|
||||
struct use_simple_repeat_assign
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct use_simple_repeat_assign<mark_placeholder>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct use_simple_repeat_assign<set_initializer>
|
||||
: mpl::true_
|
||||
{};
|
||||
|
||||
template<typename Nbr>
|
||||
struct use_simple_repeat_assign<attribute_placeholder<Nbr> >
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
// either (s1 = ...) or (a1 = ...) or (set = ...)
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::assign>
|
||||
: use_simple_repeat_assign<
|
||||
typename proto::result_of::value<
|
||||
typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, modifier_tag>
|
||||
: use_simple_repeat_<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, lookahead_tag>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, lookbehind_tag>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, keeper_tag>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
// when complementing a set or an assertion, the purity is that of the set (true) or the assertion
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::complement>
|
||||
: use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
// The comma is used in list-initialized sets, which are pure
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::comma>
|
||||
: mpl::true_
|
||||
{};
|
||||
|
||||
// The subscript operator[] is used for sets, as in set['a' | range('b','h')]
|
||||
// It is also used for actions, which by definition have side-effects and thus are impure
|
||||
template<typename Expr, typename Char, typename Left>
|
||||
struct use_simple_repeat_subscript
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_subscript<Expr, Char, set_initializer_type>
|
||||
: mpl::true_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::subscript>
|
||||
: use_simple_repeat_subscript<Expr, Char, typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr>
|
||||
{};
|
||||
|
||||
// Quantified expressions are variable-width and cannot use the simple quantifier
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::unary_plus>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::dereference>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::logical_not>
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char, uint_t Min, uint_t Max>
|
||||
struct use_simple_repeat_<Expr, Char, generic_quant_tag<Min, Max> >
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char, uint_t Count>
|
||||
struct use_simple_repeat_<Expr, Char, generic_quant_tag<Count, Count> >
|
||||
: use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat_<Expr, Char, proto::tag::negate>
|
||||
: use_simple_repeat_<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// use_simple_repeat
|
||||
//
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat
|
||||
: use_simple_repeat_<Expr, Char>
|
||||
{
|
||||
// should never try to repeat something of 0-width
|
||||
BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
|
||||
};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct use_simple_repeat<Expr &, Char>
|
||||
: use_simple_repeat_<Expr, Char>
|
||||
{
|
||||
// should never try to repeat something of 0-width
|
||||
BOOST_MPL_ASSERT_RELATION(0, !=, (width_of<Expr, Char>::value));
|
||||
};
|
||||
|
||||
}}} // namespace boost::xpressive::detail
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,66 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// modifier.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_MODIFIER_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_MODIFIER_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable : 4510) // default constructor could not be generated
|
||||
# pragma warning(disable : 4610) // user defined constructor required
|
||||
#endif
|
||||
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/proto/traits.hpp>
|
||||
#include <boost/xpressive/regex_constants.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// modifier
|
||||
template<typename Modifier>
|
||||
struct modifier_op
|
||||
{
|
||||
typedef regex_constants::syntax_option_type opt_type;
|
||||
|
||||
template<typename Expr>
|
||||
struct apply
|
||||
{
|
||||
typedef typename proto::binary_expr<
|
||||
modifier_tag
|
||||
, typename proto::terminal<Modifier>::type
|
||||
, typename proto::result_of::as_child<Expr const>::type
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template<typename Expr>
|
||||
typename apply<Expr>::type const
|
||||
operator ()(Expr const &expr) const
|
||||
{
|
||||
typename apply<Expr>::type that = {{this->mod_}, proto::as_child(expr)};
|
||||
return that;
|
||||
}
|
||||
|
||||
operator opt_type() const
|
||||
{
|
||||
return this->opt_;
|
||||
}
|
||||
|
||||
Modifier mod_;
|
||||
opt_type opt_;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,120 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// placeholders.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_PLACEHOLDERS_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_PLACEHOLDERS_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
# pragma warning(push)
|
||||
# pragma warning(disable:4510) // default constructor could not be generated
|
||||
# pragma warning(disable:4610) // can never be instantiated - user defined constructor required
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/xpressive/detail/core/quant_style.hpp>
|
||||
#include <boost/xpressive/detail/core/regex_impl.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// mark_placeholder
|
||||
//
|
||||
struct mark_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_variable_width, unknown_width::value, true)
|
||||
|
||||
int mark_number_;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// posix_charset_placeholder
|
||||
//
|
||||
struct posix_charset_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_fixed_width, 1, true)
|
||||
|
||||
char const *name_;
|
||||
bool not_;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// assert_word_placeholder
|
||||
//
|
||||
template<typename Cond>
|
||||
struct assert_word_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_none, 0, true)
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// range_placeholder
|
||||
//
|
||||
template<typename Char>
|
||||
struct range_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_fixed_width, 1, true)
|
||||
|
||||
Char ch_min_;
|
||||
Char ch_max_;
|
||||
bool not_;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// assert_bol_placeholder
|
||||
//
|
||||
struct assert_bol_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_none, 0, true)
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// assert_eol_placeholder
|
||||
//
|
||||
struct assert_eol_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_none, 0, true)
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// logical_newline_placeholder
|
||||
//
|
||||
struct logical_newline_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_variable_width, unknown_width::value, true)
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// self_placeholder
|
||||
//
|
||||
struct self_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_variable_width, unknown_width::value, false)
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// attribute_placeholder
|
||||
//
|
||||
template<typename Nbr>
|
||||
struct attribute_placeholder
|
||||
{
|
||||
BOOST_XPR_QUANT_STYLE(quant_variable_width, unknown_width::value, false)
|
||||
|
||||
typedef Nbr nbr_type;
|
||||
static Nbr nbr() { return Nbr(); }
|
||||
};
|
||||
|
||||
}}} // namespace boost::xpressive::detail
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,259 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// static.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_STATIC_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_STATIC_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/core/state.hpp>
|
||||
#include <boost/xpressive/detail/core/linker.hpp>
|
||||
#include <boost/xpressive/detail/core/peeker.hpp>
|
||||
#include <boost/xpressive/detail/static/placeholders.hpp>
|
||||
#include <boost/xpressive/detail/utility/width.hpp>
|
||||
|
||||
// Random thoughts:
|
||||
// - must support indirect repeat counts {$n,$m}
|
||||
// - add ws to eat whitespace (make *ws illegal)
|
||||
// - a{n,m} -> repeat<n,m>(a)
|
||||
// - a{$n,$m} -> repeat(n,m)(a)
|
||||
// - add nil to match nothing
|
||||
// - instead of s1, s2, etc., how about s[1], s[2], etc.? Needlessly verbose?
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// stacked_xpression
|
||||
//
|
||||
template<typename Top, typename Next>
|
||||
struct stacked_xpression
|
||||
: Next
|
||||
{
|
||||
// match
|
||||
// delegates to Next
|
||||
template<typename BidiIter>
|
||||
bool match(match_state<BidiIter> &state) const
|
||||
{
|
||||
return static_cast<Next const *>(this)->
|
||||
BOOST_NESTED_TEMPLATE push_match<Top>(state);
|
||||
}
|
||||
|
||||
// top_match
|
||||
// jump back to the xpression on top of the xpression stack,
|
||||
// and keep the xpression on the stack.
|
||||
template<typename BidiIter>
|
||||
static bool top_match(match_state<BidiIter> &state, void const *top)
|
||||
{
|
||||
return static_cast<Top const *>(top)->
|
||||
BOOST_NESTED_TEMPLATE push_match<Top>(state);
|
||||
}
|
||||
|
||||
// pop_match
|
||||
// jump back to the xpression on top of the xpression stack,
|
||||
// pop the xpression off the stack.
|
||||
template<typename BidiIter>
|
||||
static bool pop_match(match_state<BidiIter> &state, void const *top)
|
||||
{
|
||||
return static_cast<Top const *>(top)->match(state);
|
||||
}
|
||||
|
||||
// skip_match
|
||||
// pop the xpression off the top of the stack and ignore it; call
|
||||
// match on next.
|
||||
template<typename BidiIter>
|
||||
bool skip_match(match_state<BidiIter> &state) const
|
||||
{
|
||||
// could be static_xpression::skip_impl or stacked_xpression::skip_impl
|
||||
// depending on if there is 1 or more than 1 xpression on the
|
||||
// xpression stack
|
||||
return Top::skip_impl(*static_cast<Next const *>(this), state);
|
||||
}
|
||||
|
||||
//protected:
|
||||
|
||||
// skip_impl
|
||||
// implementation of skip_match.
|
||||
template<typename That, typename BidiIter>
|
||||
static bool skip_impl(That const &that, match_state<BidiIter> &state)
|
||||
{
|
||||
return that.BOOST_NESTED_TEMPLATE push_match<Top>(state);
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// stacked_xpression_cast
|
||||
//
|
||||
template<typename Top, typename Next>
|
||||
inline stacked_xpression<Top, Next> const &stacked_xpression_cast(Next const &next)
|
||||
{
|
||||
// NOTE: this is a little white lie. The "next" object doesn't really have
|
||||
// the type to which we're casting it. It is harmless, though. We are only using
|
||||
// the cast to decorate the next object with type information. It is done
|
||||
// this way to save stack space.
|
||||
BOOST_MPL_ASSERT_RELATION(sizeof(stacked_xpression<Top, Next>), ==, sizeof(Next));
|
||||
return *static_cast<stacked_xpression<Top, Next> const *>(&next);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// static_xpression
|
||||
//
|
||||
template<typename Matcher, typename Next>
|
||||
struct static_xpression
|
||||
: Matcher
|
||||
{
|
||||
Next next_;
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, pure = Matcher::pure && Next::pure);
|
||||
BOOST_STATIC_CONSTANT(
|
||||
std::size_t
|
||||
, width =
|
||||
Matcher::width != unknown_width::value && Next::width != unknown_width::value
|
||||
? Matcher::width + Next::width
|
||||
: unknown_width::value
|
||||
);
|
||||
|
||||
static_xpression(Matcher const &matcher = Matcher(), Next const &next = Next())
|
||||
: Matcher(matcher)
|
||||
, next_(next)
|
||||
{
|
||||
}
|
||||
|
||||
// match
|
||||
// delegates to the Matcher
|
||||
template<typename BidiIter>
|
||||
bool match(match_state<BidiIter> &state) const
|
||||
{
|
||||
return this->Matcher::match(state, this->next_);
|
||||
}
|
||||
|
||||
// push_match
|
||||
// call match on this, but also push "Top" onto the xpression
|
||||
// stack so we know what we are jumping back to later.
|
||||
template<typename Top, typename BidiIter>
|
||||
bool push_match(match_state<BidiIter> &state) const
|
||||
{
|
||||
return this->Matcher::match(state, stacked_xpression_cast<Top>(this->next_));
|
||||
}
|
||||
|
||||
// skip_impl
|
||||
// implementation of skip_match, called from stacked_xpression::skip_match
|
||||
template<typename That, typename BidiIter>
|
||||
static bool skip_impl(That const &that, match_state<BidiIter> &state)
|
||||
{
|
||||
return that.match(state);
|
||||
}
|
||||
|
||||
// for linking a compiled regular xpression
|
||||
template<typename Char>
|
||||
void link(xpression_linker<Char> &linker) const
|
||||
{
|
||||
linker.accept(*static_cast<Matcher const *>(this), &this->next_);
|
||||
this->next_.link(linker);
|
||||
}
|
||||
|
||||
// for building a lead-follow
|
||||
template<typename Char>
|
||||
void peek(xpression_peeker<Char> &peeker) const
|
||||
{
|
||||
this->peek_next_(peeker.accept(*static_cast<Matcher const *>(this)), peeker);
|
||||
}
|
||||
|
||||
// for getting xpression width
|
||||
detail::width get_width() const
|
||||
{
|
||||
return this->get_width_(mpl::size_t<width>());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static_xpression &operator =(static_xpression const &);
|
||||
|
||||
template<typename Char>
|
||||
void peek_next_(mpl::true_, xpression_peeker<Char> &peeker) const
|
||||
{
|
||||
this->next_.peek(peeker);
|
||||
}
|
||||
|
||||
template<typename Char>
|
||||
void peek_next_(mpl::false_, xpression_peeker<Char> &) const
|
||||
{
|
||||
// no-op
|
||||
}
|
||||
|
||||
template<std::size_t Width>
|
||||
detail::width get_width_(mpl::size_t<Width>) const
|
||||
{
|
||||
return Width;
|
||||
}
|
||||
|
||||
detail::width get_width_(unknown_width) const
|
||||
{
|
||||
// Should only be called in contexts where the width is
|
||||
// known to be fixed.
|
||||
return this->Matcher::get_width() + this->next_.get_width();
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// make_static
|
||||
//
|
||||
template<typename Matcher>
|
||||
inline static_xpression<Matcher> const
|
||||
make_static(Matcher const &matcher)
|
||||
{
|
||||
return static_xpression<Matcher>(matcher);
|
||||
}
|
||||
|
||||
template<typename Matcher, typename Next>
|
||||
inline static_xpression<Matcher, Next> const
|
||||
make_static(Matcher const &matcher, Next const &next)
|
||||
{
|
||||
return static_xpression<Matcher, Next>(matcher, next);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// no_next
|
||||
//
|
||||
struct no_next
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, width = 0);
|
||||
BOOST_STATIC_CONSTANT(bool, pure = true);
|
||||
|
||||
template<typename Char>
|
||||
void link(xpression_linker<Char> &) const
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Char>
|
||||
void peek(xpression_peeker<Char> &peeker) const
|
||||
{
|
||||
peeker.fail();
|
||||
}
|
||||
|
||||
detail::width get_width() const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// get_mark_number
|
||||
//
|
||||
inline int get_mark_number(basic_mark_tag const &mark)
|
||||
{
|
||||
return proto::value(mark).mark_number_;
|
||||
}
|
||||
|
||||
}}} // namespace boost::xpressive::detail
|
||||
|
||||
#endif
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_action.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler.
|
||||
// Copyright 2008 David Jenkins.
|
||||
//
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ACTION_HPP_EAN_04_05_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ACTION_HPP_EAN_04_05_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/sizeof.hpp>
|
||||
#include <boost/mpl/min_max.hpp>
|
||||
#include <boost/mpl/apply_wrap.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/core/matcher/attr_end_matcher.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/xpressive/detail/static/transforms/as_quantifier.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
#include <boost/proto/transform/arg.hpp>
|
||||
#include <boost/proto/transform/call.hpp>
|
||||
#include <boost/proto/transform/make.hpp>
|
||||
#include <boost/proto/transform/when.hpp>
|
||||
#include <boost/proto/transform/fold.hpp>
|
||||
#include <boost/proto/transform/fold_tree.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// read_attr
|
||||
// Placeholder that knows the slot number of an attribute as well as the type
|
||||
// of the object stored in it.
|
||||
template<typename Nbr, typename Matcher>
|
||||
struct read_attr
|
||||
{
|
||||
typedef Nbr nbr_type;
|
||||
typedef Matcher matcher_type;
|
||||
static Nbr nbr() { return Nbr(); }
|
||||
};
|
||||
|
||||
template<typename Nbr, typename Matcher>
|
||||
struct read_attr<Nbr, Matcher &>
|
||||
{
|
||||
typedef Nbr nbr_type;
|
||||
typedef Matcher matcher_type;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// FindAttr
|
||||
// Look for patterns like (a1= terminal<RHS>) and return the type of the RHS.
|
||||
template<typename Nbr>
|
||||
struct FindAttr
|
||||
: or_<
|
||||
// Ignore nested actions, because attributes are scoped
|
||||
when< subscript<_, _>, _state >
|
||||
, when< terminal<_>, _state >
|
||||
, when< proto::assign<terminal<detail::attribute_placeholder<Nbr> >, _>, call<_value(_right)> >
|
||||
, otherwise< fold<_, _state, FindAttr<Nbr> > >
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_read_attr
|
||||
// For patterns like (a1 = RHS)[ref(i) = a1], transform to
|
||||
// (a1 = RHS)[ref(i) = read_attr<1, RHS>] so that when reading the attribute
|
||||
// we know what type is stored in the attribute slot.
|
||||
struct as_read_attr : proto::transform<as_read_attr>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::expr expr_type;
|
||||
typedef
|
||||
typename FindAttr<typename expr_type::proto_child0::nbr_type>::template impl<
|
||||
State
|
||||
, mpl::void_
|
||||
, int
|
||||
>::result_type
|
||||
attr_type;
|
||||
|
||||
typedef
|
||||
typename proto::terminal<
|
||||
detail::read_attr<
|
||||
typename expr_type::proto_child0::nbr_type
|
||||
, BOOST_PROTO_UNCVREF(attr_type)
|
||||
>
|
||||
>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(proto::ignore, proto::ignore, proto::ignore) const
|
||||
{
|
||||
result_type that = {{}};
|
||||
return that;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// DeepCopy
|
||||
// Turn all refs into values, and also bind all attribute placeholders with
|
||||
// the types from which they are being assigned.
|
||||
struct DeepCopy
|
||||
: or_<
|
||||
when< terminal<detail::attribute_placeholder<_> >, as_read_attr>
|
||||
, when< terminal<_>, proto::_deep_copy>
|
||||
, otherwise< nary_expr<_, vararg<DeepCopy> > >
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// attr_nbr
|
||||
// For an attribute placeholder, return the attribute's slot number.
|
||||
struct attr_nbr : proto::transform<attr_nbr>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::expr expr_type;
|
||||
typedef typename expr_type::proto_child0::nbr_type::type result_type;
|
||||
};
|
||||
};
|
||||
|
||||
struct max_attr;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// MaxAttr
|
||||
// In an action (rx)[act], find the largest attribute slot being used.
|
||||
struct MaxAttr
|
||||
: or_<
|
||||
when< terminal<detail::attribute_placeholder<_> >, attr_nbr>
|
||||
, when< terminal<_>, make<mpl::int_<0> > >
|
||||
// Ignore nested actions, because attributes are scoped:
|
||||
, when< subscript<_, _>, make<mpl::int_<0> > >
|
||||
, otherwise< fold<_, make<mpl::int_<0> >, max_attr> >
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// max_attr
|
||||
// Take the maximum of the current attr slot number and the state.
|
||||
struct max_attr : proto::transform<max_attr>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
typename mpl::max<
|
||||
typename impl::state
|
||||
, typename MaxAttr::template impl<Expr, State, Data>::result_type
|
||||
>::type
|
||||
result_type;
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_attr_matcher
|
||||
// turn a1=matcher into attr_matcher<Matcher>(1)
|
||||
struct as_attr_matcher : proto::transform<as_attr_matcher>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::expr expr_type;
|
||||
typedef typename impl::data data_type;
|
||||
typedef
|
||||
detail::attr_matcher<
|
||||
typename proto::result_of::value<typename expr_type::proto_child1>::type
|
||||
, typename data_type::traits_type
|
||||
, typename data_type::icase_type
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
return result_type(
|
||||
proto::value(proto::left(expr)).nbr()
|
||||
, proto::value(proto::right(expr))
|
||||
, data.traits()
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// add_attrs
|
||||
// Wrap an expression in attr_begin_matcher/attr_end_matcher pair
|
||||
struct add_attrs : proto::transform<add_attrs>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
detail::attr_begin_matcher<
|
||||
typename MaxAttr::template impl<Expr, mpl::int_<0>, int>::result_type
|
||||
>
|
||||
begin_type;
|
||||
|
||||
typedef typename impl::expr expr_type;
|
||||
|
||||
typedef
|
||||
typename shift_right<
|
||||
typename terminal<begin_type>::type
|
||||
, typename shift_right<
|
||||
Expr
|
||||
, terminal<detail::attr_end_matcher>::type
|
||||
>::type
|
||||
>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param
|
||||
) const
|
||||
{
|
||||
begin_type begin;
|
||||
detail::attr_end_matcher end;
|
||||
result_type that = {{begin}, {expr, {end}}};
|
||||
return that;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// InsertAttrs
|
||||
struct InsertAttrs
|
||||
: if_<MaxAttr, add_attrs, _>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// CheckAssertion
|
||||
struct CheckAssertion
|
||||
: proto::function<terminal<detail::check_tag>, _>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// action_transform
|
||||
// Turn A[B] into (mark_begin(n) >> A >> mark_end(n) >> action_matcher<B>(n))
|
||||
// If A and B use attributes, wrap the above expression in
|
||||
// a attr_begin_matcher<Count> / attr_end_matcher pair, where Count is
|
||||
// the number of attribute slots used by the pattern/action.
|
||||
struct as_action : proto::transform<as_action>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename proto::result_of::left<Expr>::type expr_type;
|
||||
typedef typename proto::result_of::right<Expr>::type action_type;
|
||||
|
||||
typedef
|
||||
typename DeepCopy::impl<action_type, expr_type, int>::result_type
|
||||
action_copy_type;
|
||||
|
||||
typedef
|
||||
typename InsertMark::impl<expr_type, State, Data>::result_type
|
||||
marked_expr_type;
|
||||
|
||||
typedef
|
||||
typename mpl::if_c<
|
||||
proto::matches<action_type, CheckAssertion>::value
|
||||
, detail::predicate_matcher<action_copy_type>
|
||||
, detail::action_matcher<action_copy_type>
|
||||
>::type
|
||||
matcher_type;
|
||||
|
||||
typedef
|
||||
typename proto::shift_right<
|
||||
marked_expr_type
|
||||
, typename proto::terminal<matcher_type>::type
|
||||
>::type
|
||||
no_attr_type;
|
||||
|
||||
typedef
|
||||
typename InsertAttrs::impl<no_attr_type, State, Data>::result_type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param state
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
int dummy = 0;
|
||||
marked_expr_type marked_expr =
|
||||
InsertMark::impl<expr_type, State, Data>()(proto::left(expr), state, data);
|
||||
|
||||
no_attr_type that = {
|
||||
marked_expr
|
||||
, {
|
||||
matcher_type(
|
||||
DeepCopy::impl<action_type, expr_type, int>()(
|
||||
proto::right(expr)
|
||||
, proto::left(expr)
|
||||
, dummy
|
||||
)
|
||||
, proto::value(proto::left(marked_expr)).mark_number_
|
||||
)
|
||||
}
|
||||
};
|
||||
return InsertAttrs::impl<no_attr_type, State, Data>()(that, state, data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_alternate.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_ALTERNATE_HPP_EAN_04_01_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/xpressive/detail/core/matcher/alternate_matcher.hpp>
|
||||
#include <boost/xpressive/detail/utility/cons.hpp>
|
||||
|
||||
namespace boost { namespace xpressive
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// alternates_list
|
||||
// a fusion-compatible sequence of alternate expressions, that also keeps
|
||||
// track of the list's width and purity.
|
||||
template<typename Head, typename Tail>
|
||||
struct alternates_list
|
||||
: fusion::cons<Head, Tail>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, width = Head::width == Tail::width ? Head::width : detail::unknown_width::value);
|
||||
BOOST_STATIC_CONSTANT(bool, pure = Head::pure && Tail::pure);
|
||||
|
||||
alternates_list(Head const &head, Tail const &tail)
|
||||
: fusion::cons<Head, Tail>(head, tail)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Head>
|
||||
struct alternates_list<Head, fusion::nil>
|
||||
: fusion::cons<Head, fusion::nil>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(std::size_t, width = Head::width);
|
||||
BOOST_STATIC_CONSTANT(bool, pure = Head::pure);
|
||||
|
||||
alternates_list(Head const &head, fusion::nil const &tail)
|
||||
: fusion::cons<Head, fusion::nil>(head, tail)
|
||||
{
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
namespace grammar_detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// in_alternate_list
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct in_alternate_list : proto::transform<in_alternate_list<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
detail::alternates_list<
|
||||
typename Grammar::template impl<
|
||||
Expr
|
||||
, detail::alternate_end_xpression
|
||||
, Data
|
||||
>::result_type
|
||||
, State
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param state
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
return result_type(
|
||||
typename Grammar::template impl<Expr, detail::alternate_end_xpression, Data>()(
|
||||
expr
|
||||
, detail::alternate_end_xpression()
|
||||
, data
|
||||
)
|
||||
, state
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_alternate_matcher
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct as_alternate_matcher : proto::transform<as_alternate_matcher<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::data data_type;
|
||||
typedef
|
||||
detail::alternate_matcher<
|
||||
typename Grammar::template impl<Expr, State, Data>::result_type
|
||||
, typename data_type::traits_type
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param state
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
return result_type(
|
||||
typename Grammar::template impl<Expr, State, Data>()(expr, state, data)
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_independent.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INDEPENDENT_HPP_EAN_04_05_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INDEPENDENT_HPP_EAN_04_05_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/sizeof.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
#include <boost/proto/transform/arg.hpp>
|
||||
#include <boost/proto/transform/when.hpp>
|
||||
#include <boost/proto/transform/fold.hpp>
|
||||
#include <boost/proto/transform/fold_tree.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
struct keeper_tag
|
||||
{};
|
||||
|
||||
struct lookahead_tag
|
||||
{};
|
||||
|
||||
struct lookbehind_tag
|
||||
{};
|
||||
}}}
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
// A grammar that only accepts static regexes that
|
||||
// don't have semantic actions.
|
||||
struct NotHasAction
|
||||
: proto::switch_<struct NotHasActionCases>
|
||||
{};
|
||||
|
||||
struct NotHasActionCases
|
||||
{
|
||||
template<typename Tag, int Dummy = 0>
|
||||
struct case_
|
||||
: proto::nary_expr<Tag, proto::vararg<NotHasAction> >
|
||||
{};
|
||||
|
||||
template<int Dummy>
|
||||
struct case_<proto::tag::terminal, Dummy>
|
||||
: not_< or_<
|
||||
proto::terminal<detail::tracking_ptr<detail::regex_impl<_> > >,
|
||||
proto::terminal<reference_wrapper<_> >
|
||||
> >
|
||||
{};
|
||||
|
||||
template<int Dummy>
|
||||
struct case_<proto::tag::comma, Dummy>
|
||||
: proto::_ // because (set='a','b') can't contain an action
|
||||
{};
|
||||
|
||||
template<int Dummy>
|
||||
struct case_<proto::tag::complement, Dummy>
|
||||
: proto::_ // because in ~X, X can't contain an unscoped action
|
||||
{};
|
||||
|
||||
template<int Dummy>
|
||||
struct case_<detail::lookahead_tag, Dummy>
|
||||
: proto::_ // because actions in lookaheads are scoped
|
||||
{};
|
||||
|
||||
template<int Dummy>
|
||||
struct case_<detail::lookbehind_tag, Dummy>
|
||||
: proto::_ // because actions in lookbehinds are scoped
|
||||
{};
|
||||
|
||||
template<int Dummy>
|
||||
struct case_<detail::keeper_tag, Dummy>
|
||||
: proto::_ // because actions in keepers are scoped
|
||||
{};
|
||||
|
||||
template<int Dummy>
|
||||
struct case_<proto::tag::subscript, Dummy>
|
||||
: proto::subscript<detail::set_initializer_type, _>
|
||||
{}; // only accept set[...], not actions!
|
||||
};
|
||||
|
||||
struct IndependentEndXpression
|
||||
: or_<
|
||||
when<NotHasAction, detail::true_xpression()>
|
||||
, otherwise<detail::independent_end_xpression()>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct as_lookahead : proto::transform<as_lookahead<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename proto::result_of::child<Expr>::type arg_type;
|
||||
|
||||
typedef
|
||||
typename IndependentEndXpression::impl<arg_type, int, int>::result_type
|
||||
end_xpr_type;
|
||||
|
||||
typedef
|
||||
typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
|
||||
xpr_type;
|
||||
|
||||
typedef
|
||||
detail::lookahead_matcher<xpr_type>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
int i = 0;
|
||||
return result_type(
|
||||
typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
|
||||
proto::child(expr)
|
||||
, IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
|
||||
, data
|
||||
)
|
||||
, false
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct as_lookbehind : proto::transform<as_lookbehind<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename proto::result_of::child<Expr>::type arg_type;
|
||||
|
||||
typedef
|
||||
typename IndependentEndXpression::impl<arg_type, int, int>::result_type
|
||||
end_xpr_type;
|
||||
|
||||
typedef
|
||||
typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
|
||||
xpr_type;
|
||||
|
||||
typedef
|
||||
detail::lookbehind_matcher<xpr_type>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
int i = 0;
|
||||
xpr_type expr2 = typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
|
||||
proto::child(expr)
|
||||
, IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
|
||||
, data
|
||||
);
|
||||
std::size_t width = expr2.get_width().value();
|
||||
return result_type(expr2, width, false);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct as_keeper : proto::transform<as_keeper<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename proto::result_of::child<Expr>::type arg_type;
|
||||
|
||||
typedef
|
||||
typename IndependentEndXpression::impl<arg_type, int, int>::result_type
|
||||
end_xpr_type;
|
||||
|
||||
typedef
|
||||
typename Grammar::template impl<arg_type, end_xpr_type, Data>::result_type
|
||||
xpr_type;
|
||||
|
||||
typedef
|
||||
detail::keeper_matcher<xpr_type>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
int i = 0;
|
||||
return result_type(
|
||||
typename Grammar::template impl<arg_type, end_xpr_type, Data>()(
|
||||
proto::child(expr)
|
||||
, IndependentEndXpression::impl<arg_type, int, int>()(proto::child(expr), i, i)
|
||||
, data
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_inverse.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_INVERSE_HPP_EAN_04_05_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/sizeof.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
|
||||
#define UNCV(x) typename remove_const<x>::type
|
||||
#define UNREF(x) typename remove_reference<x>::type
|
||||
#define UNCVREF(x) UNCV(UNREF(x))
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
struct inverter
|
||||
{
|
||||
typedef T type;
|
||||
static T call(T t)
|
||||
{
|
||||
t.inverse();
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Traits, typename ICase, typename Not>
|
||||
struct inverter<detail::literal_matcher<Traits, ICase, Not> >
|
||||
{
|
||||
typedef detail::literal_matcher<Traits, ICase, typename mpl::not_<Not>::type> type;
|
||||
static type call(detail::literal_matcher<Traits, ICase, Not> t)
|
||||
{
|
||||
return type(t.ch_);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Traits>
|
||||
struct inverter<detail::logical_newline_matcher<Traits> >
|
||||
{
|
||||
// ~_ln matches any one character that is not in the "newline" character class
|
||||
typedef detail::posix_charset_matcher<Traits> type;
|
||||
static type call(detail::logical_newline_matcher<Traits> t)
|
||||
{
|
||||
return type(t.newline(), true);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename Traits>
|
||||
struct inverter<detail::assert_word_matcher<detail::word_boundary<mpl::true_>, Traits> >
|
||||
{
|
||||
typedef detail::assert_word_matcher<detail::word_boundary<mpl::false_>, Traits> type;
|
||||
static type call(detail::assert_word_matcher<detail::word_boundary<mpl::true_>, Traits> t)
|
||||
{
|
||||
return type(t.word());
|
||||
}
|
||||
};
|
||||
|
||||
struct as_inverse : proto::callable
|
||||
{
|
||||
template<typename Sig>
|
||||
struct result;
|
||||
|
||||
template<typename This, typename Matcher>
|
||||
struct result<This(Matcher)>
|
||||
: inverter<UNCVREF(Matcher)>
|
||||
{};
|
||||
|
||||
template<typename Matcher>
|
||||
typename inverter<Matcher>::type operator ()(Matcher const &matcher) const
|
||||
{
|
||||
return inverter<Matcher>::call(matcher);
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#undef UNCV
|
||||
#undef UNREF
|
||||
#undef UNCVREF
|
||||
|
||||
#endif
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_marker.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MARKER_HPP_EAN_04_01_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MARKER_HPP_EAN_04_01_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_marker
|
||||
// Insert mark tags before and after the expression
|
||||
struct as_marker : proto::transform<as_marker>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
typename shift_right<
|
||||
terminal<detail::mark_begin_matcher>::type
|
||||
, typename shift_right<
|
||||
typename proto::result_of::right<typename impl::expr>::type
|
||||
, terminal<detail::mark_end_matcher>::type
|
||||
>::type
|
||||
>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param
|
||||
) const
|
||||
{
|
||||
int mark_nbr = detail::get_mark_number(proto::left(expr));
|
||||
detail::mark_begin_matcher begin(mark_nbr);
|
||||
detail::mark_end_matcher end(mark_nbr);
|
||||
|
||||
result_type that = {{begin}, {proto::right(expr), {end}}};
|
||||
return that;
|
||||
}
|
||||
};
|
||||
};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_matcher.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MATCHER_HPP_EAN_04_01_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MATCHER_HPP_EAN_04_01_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
struct as_matcher : proto::transform<as_matcher>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::data data_type;
|
||||
|
||||
typedef
|
||||
typename data_type::template apply<
|
||||
typename proto::result_of::value<typename impl::expr>::type
|
||||
>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
return data.call(proto::value(expr));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_modifier.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MODIFIER_HPP_EAN_04_05_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_MODIFIER_HPP_EAN_04_05_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/sizeof.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
|
||||
#define UNCV(x) typename remove_const<x>::type
|
||||
#define UNREF(x) typename remove_reference<x>::type
|
||||
#define UNCVREF(x) UNCV(UNREF(x))
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// regex operator tags
|
||||
struct modifier_tag
|
||||
{};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_modifier
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct as_modifier : proto::transform<as_modifier<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
typename proto::result_of::value<
|
||||
typename proto::result_of::left<typename impl::expr>::type
|
||||
>::type
|
||||
modifier_type;
|
||||
|
||||
typedef
|
||||
typename modifier_type::template apply<typename impl::data>::type
|
||||
visitor_type;
|
||||
|
||||
typedef
|
||||
typename proto::result_of::right<Expr>::type
|
||||
expr_type;
|
||||
|
||||
typedef
|
||||
typename Grammar::template impl<expr_type, State, visitor_type &>::result_type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param state
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
visitor_type new_visitor(proto::value(proto::left(expr)).call(data));
|
||||
return typename Grammar::template impl<expr_type, State, visitor_type &>()(
|
||||
proto::right(expr)
|
||||
, state
|
||||
, new_visitor
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#undef UNCV
|
||||
#undef UNREF
|
||||
#undef UNCVREF
|
||||
|
||||
#endif
|
||||
+378
@@ -0,0 +1,378 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_quantifier.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_QUANTIFIER_HPP_EAN_04_01_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_QUANTIFIER_HPP_EAN_04_01_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// generic_quant_tag
|
||||
template<uint_t Min, uint_t Max>
|
||||
struct generic_quant_tag
|
||||
{
|
||||
typedef mpl::integral_c<uint_t, Min> min_type;
|
||||
typedef mpl::integral_c<uint_t, Max> max_type;
|
||||
};
|
||||
}}}
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
using detail::uint_t;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// min_type / max_type
|
||||
template<typename Tag>
|
||||
struct min_type : Tag::min_type {};
|
||||
|
||||
template<>
|
||||
struct min_type<proto::tag::unary_plus> : mpl::integral_c<uint_t, 1> {};
|
||||
|
||||
template<>
|
||||
struct min_type<proto::tag::dereference> : mpl::integral_c<uint_t, 0> {};
|
||||
|
||||
template<>
|
||||
struct min_type<proto::tag::logical_not> : mpl::integral_c<uint_t, 0> {};
|
||||
|
||||
template<typename Tag>
|
||||
struct max_type : Tag::max_type {};
|
||||
|
||||
template<>
|
||||
struct max_type<proto::tag::unary_plus> : mpl::integral_c<uint_t, UINT_MAX-1> {};
|
||||
|
||||
template<>
|
||||
struct max_type<proto::tag::dereference> : mpl::integral_c<uint_t, UINT_MAX-1> {};
|
||||
|
||||
template<>
|
||||
struct max_type<proto::tag::logical_not> : mpl::integral_c<uint_t, 1> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_simple_quantifier
|
||||
template<typename Grammar, typename Greedy, typename Callable = proto::callable>
|
||||
struct as_simple_quantifier : proto::transform<as_simple_quantifier<Grammar, Greedy, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
typename proto::result_of::child<Expr>::type
|
||||
arg_type;
|
||||
|
||||
typedef
|
||||
typename Grammar::template impl<arg_type, detail::true_xpression, Data>::result_type
|
||||
xpr_type;
|
||||
|
||||
typedef
|
||||
detail::simple_repeat_matcher<xpr_type, Greedy>
|
||||
matcher_type;
|
||||
|
||||
typedef
|
||||
typename proto::terminal<matcher_type>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
xpr_type xpr = typename Grammar::template impl<arg_type, detail::true_xpression, Data>()(
|
||||
proto::child(expr)
|
||||
, detail::true_xpression()
|
||||
, data
|
||||
);
|
||||
|
||||
typedef typename impl::expr expr_type;
|
||||
matcher_type matcher(
|
||||
xpr
|
||||
, (uint_t)min_type<typename expr_type::proto_tag>::value
|
||||
, (uint_t)max_type<typename expr_type::proto_tag>::value
|
||||
, xpr.get_width().value()
|
||||
);
|
||||
|
||||
return result_type::make(matcher);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// add_hidden_mark
|
||||
struct add_hidden_mark : proto::transform<add_hidden_mark>
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::expr expr_type;
|
||||
typedef
|
||||
typename shift_right<
|
||||
terminal<detail::mark_begin_matcher>::type
|
||||
, typename shift_right<
|
||||
Expr
|
||||
, terminal<detail::mark_end_matcher>::type
|
||||
>::type
|
||||
>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
// we're inserting a hidden mark ... so grab the next hidden mark number.
|
||||
int mark_nbr = data.get_hidden_mark();
|
||||
detail::mark_begin_matcher begin(mark_nbr);
|
||||
detail::mark_end_matcher end(mark_nbr);
|
||||
|
||||
result_type that = {{begin}, {expr, {end}}};
|
||||
return that;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// InsertMark
|
||||
struct InsertMark
|
||||
: or_<
|
||||
when<proto::assign<detail::basic_mark_tag, _>, _>
|
||||
, otherwise<add_hidden_mark>
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_default_quantifier_impl
|
||||
template<typename Greedy, uint_t Min, uint_t Max>
|
||||
struct as_default_quantifier_impl : proto::transform<as_default_quantifier_impl<Greedy, Min, Max> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
typename proto::result_of::child<Expr>::type
|
||||
xpr_type;
|
||||
|
||||
typedef
|
||||
typename InsertMark::impl<xpr_type, State, Data>::result_type
|
||||
marked_sub_type;
|
||||
|
||||
typedef
|
||||
typename shift_right<
|
||||
terminal<detail::repeat_begin_matcher>::type
|
||||
, typename shift_right<
|
||||
marked_sub_type
|
||||
, typename terminal<detail::repeat_end_matcher<Greedy> >::type
|
||||
>::type
|
||||
>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param state
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
// Ensure this sub-expression is book-ended with mark matchers
|
||||
marked_sub_type marked_sub =
|
||||
InsertMark::impl<xpr_type, State, Data>()(proto::child(expr), state, data);
|
||||
|
||||
// Get the mark_number from the begin_mark_matcher
|
||||
int mark_number = proto::value(proto::left(marked_sub)).mark_number_;
|
||||
BOOST_ASSERT(0 != mark_number);
|
||||
|
||||
typedef typename impl::expr expr_type;
|
||||
uint_t min_ = (uint_t)min_type<typename expr_type::proto_tag>();
|
||||
uint_t max_ = (uint_t)max_type<typename expr_type::proto_tag>();
|
||||
|
||||
detail::repeat_begin_matcher begin(mark_number);
|
||||
detail::repeat_end_matcher<Greedy> end(mark_number, min_, max_);
|
||||
|
||||
result_type that = {{begin}, {marked_sub, {end}}};
|
||||
return that;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// optional_tag
|
||||
template<typename Greedy>
|
||||
struct optional_tag
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_default_optional
|
||||
template<typename Grammar, typename Greedy, typename Callable = proto::callable>
|
||||
struct as_default_optional : proto::transform<as_default_optional<Grammar, Greedy, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
detail::alternate_end_xpression
|
||||
end_xpr;
|
||||
|
||||
typedef
|
||||
detail::optional_matcher<
|
||||
typename Grammar::template impl<Expr, end_xpr, Data>::result_type
|
||||
, Greedy
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
return result_type(
|
||||
typename Grammar::template impl<Expr, end_xpr, Data>()(expr, end_xpr(), data)
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_mark_optional
|
||||
template<typename Grammar, typename Greedy, typename Callable = proto::callable>
|
||||
struct as_mark_optional : proto::transform<as_mark_optional<Grammar, Greedy, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
detail::alternate_end_xpression
|
||||
end_xpr;
|
||||
|
||||
typedef
|
||||
detail::optional_mark_matcher<
|
||||
typename Grammar::template impl<Expr, end_xpr, Data>::result_type
|
||||
, Greedy
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
int mark_number = proto::value(proto::left(expr)).mark_number_;
|
||||
|
||||
return result_type(
|
||||
typename Grammar::template impl<Expr, end_xpr, Data>()(expr, end_xpr(), data)
|
||||
, mark_number
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IsMarkerOrRepeater
|
||||
struct IsMarkerOrRepeater
|
||||
: or_<
|
||||
shift_right<terminal<detail::repeat_begin_matcher>, _>
|
||||
, assign<terminal<detail::mark_placeholder>, _>
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_optional
|
||||
template<typename Grammar, typename Greedy>
|
||||
struct as_optional
|
||||
: or_<
|
||||
when<IsMarkerOrRepeater, as_mark_optional<Grammar, Greedy> >
|
||||
, otherwise<as_default_optional<Grammar, Greedy> >
|
||||
>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// make_optional_
|
||||
template<typename Greedy, typename Callable = proto::callable>
|
||||
struct make_optional_ : proto::transform<make_optional_<Greedy, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::expr expr_type;
|
||||
typedef
|
||||
typename unary_expr<
|
||||
optional_tag<Greedy>
|
||||
, Expr
|
||||
>::type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param
|
||||
) const
|
||||
{
|
||||
result_type that = {expr};
|
||||
return that;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_default_quantifier_impl
|
||||
template<typename Greedy, uint_t Max>
|
||||
struct as_default_quantifier_impl<Greedy, 0, Max>
|
||||
: call<make_optional_<Greedy>(as_default_quantifier_impl<Greedy, 1, Max>)>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_default_quantifier_impl
|
||||
template<typename Greedy>
|
||||
struct as_default_quantifier_impl<Greedy, 0, 1>
|
||||
: call<make_optional_<Greedy>(_child)>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_default_quantifier
|
||||
template<typename Greedy, typename Callable = proto::callable>
|
||||
struct as_default_quantifier : proto::transform<as_default_quantifier<Greedy, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::expr expr_type;
|
||||
typedef
|
||||
as_default_quantifier_impl<
|
||||
Greedy
|
||||
, min_type<typename expr_type::proto_tag>::value
|
||||
, max_type<typename expr_type::proto_tag>::value
|
||||
>
|
||||
other;
|
||||
|
||||
typedef
|
||||
typename other::template impl<Expr, State, Data>::result_type
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param state
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
return typename other::template impl<Expr, State, Data>()(expr, state, data);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_sequence.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SEQUENCE_HPP_EAN_04_01_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SEQUENCE_HPP_EAN_04_01_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct in_sequence : proto::transform<in_sequence<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef
|
||||
detail::static_xpression<
|
||||
typename Grammar::template impl<Expr, State, Data>::result_type
|
||||
, State
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param state
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
return result_type(
|
||||
typename Grammar::template impl<Expr, State, Data>()(expr, state, data)
|
||||
, state
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+224
@@ -0,0 +1,224 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_set.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SET_HPP_EAN_04_05_2007
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSFORMS_AS_SET_HPP_EAN_04_05_2007
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/proto/core.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/static.hpp>
|
||||
#include <boost/xpressive/detail/utility/chset/chset.hpp>
|
||||
#include <boost/xpressive/detail/utility/traits_utils.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace grammar_detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// CharLiteral
|
||||
template<typename Char>
|
||||
struct CharLiteral
|
||||
: or_<
|
||||
terminal<char>
|
||||
, terminal<Char>
|
||||
>
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct CharLiteral<char>
|
||||
: terminal<char>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ListSet
|
||||
// matches expressions like (set= 'a','b','c')
|
||||
// calculates the size of the set
|
||||
template<typename Char>
|
||||
struct ListSet
|
||||
: or_<
|
||||
when<
|
||||
comma<ListSet<Char>, CharLiteral<Char> >
|
||||
, make<mpl::next<call<ListSet<Char>(_left)> > > // TODO make a custom transform for this...
|
||||
>
|
||||
, when<
|
||||
assign<detail::set_initializer_type, CharLiteral<Char> >
|
||||
, make<mpl::int_<1> >
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Char, typename Traits>
|
||||
void fill_list_set(Char *&, detail::set_initializer_type, Traits const &)
|
||||
{}
|
||||
|
||||
template<typename Char, typename Expr, typename Traits>
|
||||
void fill_list_set(Char *&buffer, Expr const &expr, Traits const &traits)
|
||||
{
|
||||
fill_list_set(buffer, proto::left(expr), traits);
|
||||
*buffer++ = traits.translate(detail::char_cast<Char>(proto::value(proto::right(expr)), traits));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// as_list_set_matcher
|
||||
template<typename Char, typename Callable = proto::callable>
|
||||
struct as_list_set_matcher : proto::transform<as_list_set_matcher<Char, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::data data_type;
|
||||
typedef
|
||||
detail::set_matcher<
|
||||
typename data_type::traits_type
|
||||
, typename ListSet<Char>::template impl<Expr, State, Data>::result_type
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
result_type set;
|
||||
typedef typename impl::data data_type;
|
||||
typename data_type::char_type *buffer = set.set_;
|
||||
fill_list_set(buffer, expr, data.traits());
|
||||
return set;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// merge_charset
|
||||
//
|
||||
template<typename Grammar, typename CharSet, typename Data>
|
||||
struct merge_charset
|
||||
{
|
||||
typedef typename Data::traits_type traits_type;
|
||||
typedef typename CharSet::char_type char_type;
|
||||
typedef typename CharSet::icase_type icase_type;
|
||||
|
||||
merge_charset(CharSet &charset, Data &data)
|
||||
: charset_(charset)
|
||||
, visitor_(data)
|
||||
{}
|
||||
|
||||
template<typename Expr>
|
||||
void operator ()(Expr const &expr) const
|
||||
{
|
||||
this->call_(expr, typename Expr::proto_tag());
|
||||
}
|
||||
|
||||
private:
|
||||
merge_charset &operator =(merge_charset const &);
|
||||
|
||||
template<typename Expr, typename Tag>
|
||||
void call_(Expr const &expr, Tag) const
|
||||
{
|
||||
this->set_(
|
||||
typename Grammar::template impl<Expr const &, detail::end_xpression, Data &>()(
|
||||
expr
|
||||
, detail::end_xpression()
|
||||
, this->visitor_
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
template<typename Expr>
|
||||
void call_(Expr const &expr, tag::bitwise_or) const
|
||||
{
|
||||
(*this)(proto::left(expr));
|
||||
(*this)(proto::right(expr));
|
||||
}
|
||||
|
||||
template<typename Not>
|
||||
void set_(detail::literal_matcher<traits_type, icase_type, Not> const &ch) const
|
||||
{
|
||||
// BUGBUG fixme!
|
||||
BOOST_MPL_ASSERT_NOT((Not));
|
||||
set_char(this->charset_.charset_, ch.ch_, this->visitor_.traits(), icase_type());
|
||||
}
|
||||
|
||||
void set_(detail::range_matcher<traits_type, icase_type> const &rg) const
|
||||
{
|
||||
// BUGBUG fixme!
|
||||
BOOST_ASSERT(!rg.not_);
|
||||
set_range(this->charset_.charset_, rg.ch_min_, rg.ch_max_, this->visitor_.traits(), icase_type());
|
||||
}
|
||||
|
||||
template<typename Size>
|
||||
void set_(detail::set_matcher<traits_type, Size> const &set_) const
|
||||
{
|
||||
// BUGBUG fixme!
|
||||
BOOST_ASSERT(!set_.not_);
|
||||
for(int i = 0; i < Size::value; ++i)
|
||||
{
|
||||
set_char(this->charset_.charset_, set_.set_[i], this->visitor_.traits(), icase_type());
|
||||
}
|
||||
}
|
||||
|
||||
void set_(detail::posix_charset_matcher<traits_type> const &posix) const
|
||||
{
|
||||
set_class(this->charset_.charset_, posix.mask_, posix.not_, this->visitor_.traits());
|
||||
}
|
||||
|
||||
CharSet &charset_;
|
||||
Data &visitor_;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
template<typename Grammar, typename Callable = proto::callable>
|
||||
struct as_set_matcher : proto::transform<as_set_matcher<Grammar, Callable> >
|
||||
{
|
||||
template<typename Expr, typename State, typename Data>
|
||||
struct impl : proto::transform_impl<Expr, State, Data>
|
||||
{
|
||||
typedef typename impl::data data_type;
|
||||
typedef typename data_type::char_type char_type;
|
||||
|
||||
// if sizeof(char_type)==1, merge everything into a basic_chset
|
||||
// BUGBUG this is not optimal.
|
||||
typedef
|
||||
typename mpl::if_c<
|
||||
detail::is_narrow_char<char_type>::value
|
||||
, detail::basic_chset<char_type>
|
||||
, detail::compound_charset<typename data_type::traits_type>
|
||||
>::type
|
||||
charset_type;
|
||||
|
||||
typedef
|
||||
detail::charset_matcher<
|
||||
typename data_type::traits_type
|
||||
, typename data_type::icase_type
|
||||
, charset_type
|
||||
>
|
||||
result_type;
|
||||
|
||||
result_type operator ()(
|
||||
typename impl::expr_param expr
|
||||
, typename impl::state_param
|
||||
, typename impl::data_param data
|
||||
) const
|
||||
{
|
||||
result_type matcher;
|
||||
merge_charset<Grammar, result_type, typename impl::data> merge(matcher, data);
|
||||
merge(expr); // Walks the tree and fills in the charset
|
||||
return matcher;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,240 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// transmogrify.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TRANSMOGRIFY_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <cstring> // for std::strlen
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/core/matchers.hpp>
|
||||
#include <boost/xpressive/detail/static/placeholders.hpp>
|
||||
#include <boost/xpressive/detail/utility/dont_care.hpp>
|
||||
#include <boost/xpressive/detail/utility/traits_utils.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
template<typename T, typename Char>
|
||||
struct is_char_literal
|
||||
: mpl::or_<is_same<T, Char>, is_same<T, char> >
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// transmogrify
|
||||
//
|
||||
template<typename BidiIter, typename ICase, typename Traits, typename Matcher, typename EnableIf = void>
|
||||
struct default_transmogrify
|
||||
{
|
||||
typedef typename Traits::char_type char_type;
|
||||
typedef typename Traits::string_type string_type;
|
||||
|
||||
typedef typename mpl::if_c
|
||||
<
|
||||
is_char_literal<Matcher, char_type>::value
|
||||
, literal_matcher<Traits, ICase, mpl::false_>
|
||||
, string_matcher<Traits, ICase>
|
||||
>::type type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2 const &m, Visitor &visitor)
|
||||
{
|
||||
return default_transmogrify::call_(m, visitor, is_char_literal<Matcher2, char_type>());
|
||||
}
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call_(Matcher2 const &m, Visitor &visitor, mpl::true_)
|
||||
{
|
||||
char_type ch = char_cast<char_type>(m, visitor.traits());
|
||||
return type(ch, visitor.traits());
|
||||
}
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call_(Matcher2 const &m, Visitor &visitor, mpl::false_)
|
||||
{
|
||||
string_type str = string_cast<string_type>(m, visitor.traits());
|
||||
return type(str, visitor.traits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits, typename Matcher>
|
||||
struct default_transmogrify<BidiIter, ICase, Traits, Matcher, typename Matcher::is_boost_xpressive_xpression_>
|
||||
{
|
||||
typedef Matcher type;
|
||||
|
||||
template<typename Matcher2>
|
||||
static Matcher2 const &call(Matcher2 const &m, dont_care)
|
||||
{
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits, typename Matcher>
|
||||
struct transmogrify
|
||||
: default_transmogrify<BidiIter, ICase, Traits, Matcher>
|
||||
{};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, assert_bol_placeholder >
|
||||
{
|
||||
typedef assert_bol_matcher<Traits> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2, Visitor &visitor)
|
||||
{
|
||||
return type(visitor.traits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, assert_eol_placeholder >
|
||||
{
|
||||
typedef assert_eol_matcher<Traits> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2, Visitor &visitor)
|
||||
{
|
||||
return type(visitor.traits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, logical_newline_placeholder >
|
||||
{
|
||||
typedef logical_newline_matcher<Traits> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2, Visitor &visitor)
|
||||
{
|
||||
return type(visitor.traits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits, typename Char>
|
||||
struct transmogrify<BidiIter, ICase, Traits, range_placeholder<Char> >
|
||||
{
|
||||
// By design, we don't widen character ranges.
|
||||
typedef typename iterator_value<BidiIter>::type char_type;
|
||||
BOOST_MPL_ASSERT((is_same<Char, char_type>));
|
||||
typedef range_matcher<Traits, ICase> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2 const &m, Visitor &visitor)
|
||||
{
|
||||
return type(m.ch_min_, m.ch_max_, m.not_, visitor.traits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, mark_placeholder >
|
||||
{
|
||||
typedef mark_matcher<Traits, ICase> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2 const &m, Visitor &visitor)
|
||||
{
|
||||
return type(m.mark_number_, visitor.traits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, posix_charset_placeholder >
|
||||
{
|
||||
typedef posix_charset_matcher<Traits> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2 const &m, Visitor &visitor)
|
||||
{
|
||||
char const *name_end = m.name_ + std::strlen(m.name_);
|
||||
return type(visitor.traits().lookup_classname(m.name_, name_end, ICase::value), m.not_);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename Traits, typename Size>
|
||||
struct transmogrify<BidiIter, mpl::true_, Traits, set_matcher<Traits, Size> >
|
||||
{
|
||||
typedef set_matcher<Traits, Size> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2 m, Visitor &visitor)
|
||||
{
|
||||
m.nocase(visitor.traits());
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits, typename Cond>
|
||||
struct transmogrify<BidiIter, ICase, Traits, assert_word_placeholder<Cond> >
|
||||
{
|
||||
typedef assert_word_matcher<Cond, Traits> type;
|
||||
|
||||
template<typename Visitor>
|
||||
static type call(dont_care, Visitor &visitor)
|
||||
{
|
||||
return type(visitor.traits());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, reference_wrapper<basic_regex<BidiIter> > >
|
||||
{
|
||||
typedef regex_byref_matcher<BidiIter> type;
|
||||
|
||||
template<typename Matcher2>
|
||||
static type call(Matcher2 const &m, dont_care)
|
||||
{
|
||||
return type(detail::core_access<BidiIter>::get_regex_impl(m.get()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, reference_wrapper<basic_regex<BidiIter> const> >
|
||||
{
|
||||
typedef regex_byref_matcher<BidiIter> type;
|
||||
|
||||
template<typename Matcher2>
|
||||
static type call(Matcher2 const &m, dont_care)
|
||||
{
|
||||
return type(detail::core_access<BidiIter>::get_regex_impl(m.get()));
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, tracking_ptr<regex_impl<BidiIter> > >
|
||||
{
|
||||
typedef regex_matcher<BidiIter> type;
|
||||
|
||||
template<typename Matcher2>
|
||||
static type call(Matcher2 const &m, dont_care)
|
||||
{
|
||||
return type(m.get());
|
||||
}
|
||||
};
|
||||
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct transmogrify<BidiIter, ICase, Traits, self_placeholder >
|
||||
{
|
||||
typedef regex_byref_matcher<BidiIter> type;
|
||||
|
||||
template<typename Matcher2, typename Visitor>
|
||||
static type call(Matcher2, Visitor &visitor)
|
||||
{
|
||||
return type(visitor.self());
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,115 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// type_traits.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_TYPE_TRAITS_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_TYPE_TRAITS_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <boost/config.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// is_static_xpression
|
||||
//
|
||||
template<typename T>
|
||||
struct is_static_xpression
|
||||
: mpl::false_
|
||||
{
|
||||
};
|
||||
|
||||
template<typename Matcher, typename Next>
|
||||
struct is_static_xpression<static_xpression<Matcher, Next> >
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
|
||||
template<typename Top, typename Next>
|
||||
struct is_static_xpression<stacked_xpression<Top, Next> >
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// is_random
|
||||
//
|
||||
template<typename BidiIter>
|
||||
struct is_random
|
||||
: is_convertible
|
||||
<
|
||||
typename iterator_category<BidiIter>::type
|
||||
, std::random_access_iterator_tag
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// is_string_iterator
|
||||
//
|
||||
template<typename Iter>
|
||||
struct is_string_iterator
|
||||
: mpl::false_
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_string_iterator<std::string::iterator>
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_string_iterator<std::string::const_iterator>
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
|
||||
#ifndef BOOST_NO_STD_WSTRING
|
||||
template<>
|
||||
struct is_string_iterator<std::wstring::iterator>
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
|
||||
template<>
|
||||
struct is_string_iterator<std::wstring::const_iterator>
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// is_char
|
||||
//
|
||||
template<typename T>
|
||||
struct is_char
|
||||
: mpl::false_
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct is_char<char>
|
||||
: mpl::true_
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct is_char<wchar_t>
|
||||
: mpl::true_
|
||||
{};
|
||||
|
||||
}}} // namespace boost::xpressive::detail
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,143 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// visitor.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_VISITOR_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_VISITOR_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/core/regex_impl.hpp>
|
||||
#include <boost/xpressive/detail/static/transmogrify.hpp>
|
||||
#include <boost/xpressive/detail/core/matcher/mark_begin_matcher.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
template<typename BidiIter>
|
||||
struct xpression_visitor_base
|
||||
{
|
||||
explicit xpression_visitor_base(shared_ptr<regex_impl<BidiIter> > const &self)
|
||||
: self_(self)
|
||||
{
|
||||
}
|
||||
|
||||
void swap(xpression_visitor_base<BidiIter> &that)
|
||||
{
|
||||
this->self_.swap(that.self_);
|
||||
}
|
||||
|
||||
int get_hidden_mark()
|
||||
{
|
||||
return -(int)(++this->self_->hidden_mark_count_);
|
||||
}
|
||||
|
||||
void mark_number(int mark_nbr)
|
||||
{
|
||||
if(0 < mark_nbr)
|
||||
{
|
||||
this->self_->mark_count_ =
|
||||
(std::max)(this->self_->mark_count_, (std::size_t)mark_nbr);
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<regex_impl<BidiIter> > &self()
|
||||
{
|
||||
return this->self_;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
template<typename Matcher>
|
||||
void visit_(Matcher const &)
|
||||
{
|
||||
}
|
||||
|
||||
void visit_(reference_wrapper<basic_regex<BidiIter> > const &rex)
|
||||
{
|
||||
// when visiting an embedded regex, track the references
|
||||
this->self_->track_reference(*detail::core_access<BidiIter>::get_regex_impl(rex.get()));
|
||||
}
|
||||
|
||||
void visit_(reference_wrapper<basic_regex<BidiIter> const> const &rex)
|
||||
{
|
||||
// when visiting an embedded regex, track the references
|
||||
this->self_->track_reference(*detail::core_access<BidiIter>::get_regex_impl(rex.get()));
|
||||
}
|
||||
|
||||
void visit_(tracking_ptr<regex_impl<BidiIter> > const &rex)
|
||||
{
|
||||
// when visiting an embedded regex, track the references
|
||||
this->self_->track_reference(*rex.get());
|
||||
}
|
||||
|
||||
void visit_(mark_placeholder const &backref)
|
||||
{
|
||||
// keep track of the largest mark number found
|
||||
this->mark_number(backref.mark_number_);
|
||||
}
|
||||
|
||||
void visit_(mark_begin_matcher const &mark_begin)
|
||||
{
|
||||
// keep track of the largest mark number found
|
||||
this->mark_number(mark_begin.mark_number_);
|
||||
}
|
||||
|
||||
private:
|
||||
shared_ptr<regex_impl<BidiIter> > self_;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
template<typename BidiIter, typename ICase, typename Traits>
|
||||
struct xpression_visitor
|
||||
: xpression_visitor_base<BidiIter>
|
||||
{
|
||||
typedef BidiIter iterator_type;
|
||||
typedef ICase icase_type;
|
||||
typedef Traits traits_type;
|
||||
typedef typename boost::iterator_value<BidiIter>::type char_type;
|
||||
|
||||
explicit xpression_visitor(Traits const &tr, shared_ptr<regex_impl<BidiIter> > const &self)
|
||||
: xpression_visitor_base<BidiIter>(self)
|
||||
, traits_(tr)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename Matcher>
|
||||
struct apply
|
||||
{
|
||||
typedef typename transmogrify<BidiIter, ICase, Traits, Matcher>::type type;
|
||||
};
|
||||
|
||||
template<typename Matcher>
|
||||
typename apply<Matcher>::type
|
||||
call(Matcher const &matcher)
|
||||
{
|
||||
this->visit_(matcher);
|
||||
return transmogrify<BidiIter, ICase, Traits, Matcher>::call(matcher, *this);
|
||||
}
|
||||
|
||||
Traits const &traits() const
|
||||
{
|
||||
return this->traits_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Traits traits_;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,270 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// width_of.hpp
|
||||
//
|
||||
// Copyright 2008 Eric Niebler. 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)
|
||||
|
||||
#ifndef BOOST_XPRESSIVE_DETAIL_STATIC_WIDTH_OF_HPP_EAN_10_04_2005
|
||||
#define BOOST_XPRESSIVE_DETAIL_STATIC_WIDTH_OF_HPP_EAN_10_04_2005
|
||||
|
||||
// MS compatible compilers support #pragma once
|
||||
#if defined(_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/ref.hpp>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
#include <boost/mpl/plus.hpp>
|
||||
#include <boost/mpl/times.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/mpl/size_t.hpp>
|
||||
#include <boost/mpl/equal_to.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/xpressive/detail/detail_fwd.hpp>
|
||||
#include <boost/xpressive/detail/static/type_traits.hpp>
|
||||
#include <boost/proto/traits.hpp>
|
||||
|
||||
namespace boost { namespace xpressive { namespace detail
|
||||
{
|
||||
template<typename Expr, typename Char, typename Tag = typename Expr::proto_tag>
|
||||
struct width_of;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// add_widths
|
||||
//
|
||||
template<std::size_t N, std::size_t M>
|
||||
struct add_widths
|
||||
: mpl::size_t<N + M>
|
||||
{};
|
||||
|
||||
template<std::size_t M>
|
||||
struct add_widths<unknown_width::value, M>
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
template<std::size_t N>
|
||||
struct add_widths<N, unknown_width::value>
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct add_widths<unknown_width::value, unknown_width::value>
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// or_widths
|
||||
//
|
||||
template<std::size_t N, std::size_t M>
|
||||
struct or_widths
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
template<std::size_t N>
|
||||
struct or_widths<N, N>
|
||||
: mpl::size_t<N>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// width_of_terminal
|
||||
//
|
||||
template<typename Expr, typename Char, bool IsXpr = is_xpr<Expr>::value>
|
||||
struct width_of_terminal
|
||||
: mpl::size_t<Expr::width> // xpressive literals
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of_terminal<Expr, Char, false>
|
||||
: unknown_width // unknown literals (eg, basic_string, basic_regex, etc.)
|
||||
{};
|
||||
|
||||
template<typename Char>
|
||||
struct width_of_terminal<Char, Char, false>
|
||||
: mpl::size_t<1> // char literals
|
||||
{};
|
||||
|
||||
template<typename Char>
|
||||
struct width_of_terminal<char, Char, false>
|
||||
: mpl::size_t<1> // char literals
|
||||
{};
|
||||
|
||||
template<>
|
||||
struct width_of_terminal<char, char, false>
|
||||
: mpl::size_t<1> // char literals
|
||||
{};
|
||||
|
||||
template<typename Elem, std::size_t N, typename Char>
|
||||
struct width_of_terminal<Elem (&) [N], Char, false>
|
||||
: mpl::size_t<N-is_char<Elem>::value> // string literals
|
||||
{};
|
||||
|
||||
template<typename Elem, std::size_t N, typename Char>
|
||||
struct width_of_terminal<Elem const (&) [N], Char, false>
|
||||
: mpl::size_t<N-is_char<Elem>::value> // string literals
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// width_of
|
||||
//
|
||||
template<typename Expr, typename Char, typename Tag>
|
||||
struct width_of
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::terminal>
|
||||
: width_of_terminal<typename proto::result_of::value<Expr>::type, Char>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::shift_right>
|
||||
: add_widths<
|
||||
width_of<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>::value
|
||||
, width_of<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>::value
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::bitwise_or>
|
||||
: or_widths<
|
||||
width_of<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>::value
|
||||
, width_of<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>::value
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char, typename Left>
|
||||
struct width_of_assign
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of_assign<Expr, Char, mark_placeholder>
|
||||
: width_of<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of_assign<Expr, Char, set_initializer>
|
||||
: mpl::size_t<1>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char, typename Nbr>
|
||||
struct width_of_assign<Expr, Char, attribute_placeholder<Nbr> >
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
// either (s1 = ...) or (a1 = ...) or (set = ...)
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::assign>
|
||||
: width_of_assign<
|
||||
Expr
|
||||
, Char
|
||||
, typename proto::result_of::value<
|
||||
typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr
|
||||
>::type
|
||||
>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, modifier_tag>
|
||||
: width_of<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, lookahead_tag>
|
||||
: mpl::size_t<0>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, lookbehind_tag>
|
||||
: mpl::size_t<0>
|
||||
{};
|
||||
|
||||
// keep() is used to turn off backtracking, so they should only be used
|
||||
// for things that are variable-width (eg. quantified)
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, keeper_tag>
|
||||
: unknown_width
|
||||
{
|
||||
// TODO: keep() now has a second meaning: execute actions immediately.
|
||||
// In that sense, it is perfectly reasonable to put a fixed-width
|
||||
// sub-expression in a keep. Can fixed-width keep() sub-expressions
|
||||
// use the simple_repeat_matcher?
|
||||
};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::unary_plus>
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::dereference>
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::logical_not>
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char, uint_t Min, uint_t Max>
|
||||
struct width_of<Expr, Char, generic_quant_tag<Min, Max> >
|
||||
: unknown_width
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char, uint_t Count>
|
||||
struct width_of<Expr, Char, generic_quant_tag<Count, Count> >
|
||||
: mpl::if_c<
|
||||
mpl::equal_to<unknown_width, width_of<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char> >::value
|
||||
, unknown_width
|
||||
, mpl::times<
|
||||
width_of<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
, mpl::size_t<Count>
|
||||
>
|
||||
>::type
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::negate>
|
||||
: width_of<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
// when complementing a set or an assertion, the width is that of the set (1) or the assertion (0)
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::complement>
|
||||
: width_of<typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr, Char>
|
||||
{};
|
||||
|
||||
// The comma is used in list-initialized sets, and the width of sets are 1
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::comma>
|
||||
: mpl::size_t<1>
|
||||
{};
|
||||
|
||||
// The subscript operator[] is used for sets, as in set['a' | range('b','h')],
|
||||
// or for actions as in (any >> expr)[ action ]
|
||||
template<typename Expr, typename Char, typename Left>
|
||||
struct width_of_subscript
|
||||
: width_of<Left, Char>
|
||||
{};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of_subscript<Expr, Char, set_initializer_type>
|
||||
: mpl::size_t<1>
|
||||
{
|
||||
// If Left is "set" then make sure that Right has a width_of 1
|
||||
BOOST_MPL_ASSERT_RELATION(
|
||||
1
|
||||
, ==
|
||||
, (width_of<typename remove_reference<typename Expr::proto_child1>::type::proto_base_expr, Char>::value));
|
||||
};
|
||||
|
||||
template<typename Expr, typename Char>
|
||||
struct width_of<Expr, Char, proto::tag::subscript>
|
||||
: width_of_subscript<Expr, Char, typename remove_reference<typename Expr::proto_child0>::type::proto_base_expr>
|
||||
{};
|
||||
|
||||
}}} // namespace boost::xpressive::detail
|
||||
|
||||
#undef UNREF
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user