stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,113 @@
/*=============================================================================
Copyright (c) 2002-2003 Joel de Guzman
Copyright (c) 2002-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_AS_PARSER_HPP)
#define BOOST_SPIRIT_AS_PARSER_HPP
#include <boost/spirit/home/classic/namespace.hpp>
#include <boost/spirit/home/classic/core/primitives/primitives.hpp>
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////
//
// Helper templates to derive the parser type from an auxilliary type
// and to generate an object of the required parser type given an
// auxilliary object. Supported types to convert are parsers,
// single characters and character strings.
//
///////////////////////////////////////////////////////////////////////////
namespace impl
{
template<typename T>
struct default_as_parser
{
typedef T type;
static type const& convert(type const& p)
{
return p;
}
};
struct char_as_parser
{
typedef chlit<char> type;
static type convert(char ch)
{
return type(ch);
}
};
struct wchar_as_parser
{
typedef chlit<wchar_t> type;
static type convert(wchar_t ch)
{
return type(ch);
}
};
struct string_as_parser
{
typedef strlit<char const*> type;
static type convert(char const* str)
{
return type(str);
}
};
struct wstring_as_parser
{
typedef strlit<wchar_t const*> type;
static type convert(wchar_t const* str)
{
return type(str);
}
};
}
template<typename T>
struct as_parser : impl::default_as_parser<T> {};
template<>
struct as_parser<char> : impl::char_as_parser {};
template<>
struct as_parser<wchar_t> : impl::wchar_as_parser {};
template<>
struct as_parser<char*> : impl::string_as_parser {};
template<>
struct as_parser<char const*> : impl::string_as_parser {};
template<>
struct as_parser<wchar_t*> : impl::wstring_as_parser {};
template<>
struct as_parser<wchar_t const*> : impl::wstring_as_parser {};
template<int N>
struct as_parser<char[N]> : impl::string_as_parser {};
template<int N>
struct as_parser<wchar_t[N]> : impl::wstring_as_parser {};
template<int N>
struct as_parser<char const[N]> : impl::string_as_parser {};
template<int N>
struct as_parser<wchar_t const[N]> : impl::wstring_as_parser {};
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace BOOST_SPIRIT_CLASSIC_NS
#endif
@@ -0,0 +1,56 @@
/*=============================================================================
Copyright (c) 2002-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_FUNDAMENTAL_HPP)
#define BOOST_SPIRIT_FUNDAMENTAL_HPP
#include <boost/spirit/home/classic/namespace.hpp>
#include <boost/spirit/home/classic/meta/impl/fundamental.ipp>
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////
//
// Helper template for counting the number of nodes contained in a
// given parser type.
// All parser_category type parsers are counted as nodes.
//
///////////////////////////////////////////////////////////////////////////
template <typename ParserT>
struct node_count {
typedef typename ParserT::parser_category_t parser_category_t;
typedef typename impl::nodes<parser_category_t>
::template count<ParserT, mpl::int_<0> > count_t;
BOOST_STATIC_CONSTANT(int, value = count_t::value);
};
///////////////////////////////////////////////////////////////////////////
//
// Helper template for counting the number of leaf nodes contained in a
// given parser type.
// Only plain_parser_category type parsers are counted as leaf nodes.
//
///////////////////////////////////////////////////////////////////////////
template <typename ParserT>
struct leaf_count {
typedef typename ParserT::parser_category_t parser_category_t;
typedef typename impl::leafs<parser_category_t>
::template count<ParserT, mpl::int_<0> > count_t;
BOOST_STATIC_CONSTANT(int, value = count_t::value);
};
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace BOOST_SPIRIT_CLASSIC_NS
#endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_HPP)
@@ -0,0 +1,177 @@
/*=============================================================================
Copyright (c) 2002-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
#define BOOST_SPIRIT_FUNDAMENTAL_IPP
#include <boost/mpl/int.hpp>
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
namespace impl
{
///////////////////////////////////////////////////////////////////////////
//
// Helper template for counting the number of nodes contained in a
// given parser type.
// All parser_category type parsers are counted as nodes.
//
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct nodes;
template <>
struct nodes<plain_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum { value = (LeafCountT::value + 1) };
};
};
template <>
struct nodes<unary_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
typedef typename ParserT::subject_t subject_t;
typedef typename subject_t::parser_category_t subject_category_t;
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum { value = (nodes<subject_category_t>
::template count<subject_t, LeafCountT>::value + 1) };
};
};
template <>
struct nodes<action_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
typedef typename ParserT::subject_t subject_t;
typedef typename subject_t::parser_category_t subject_category_t;
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum { value = (nodes<subject_category_t>
::template count<subject_t, LeafCountT>::value + 1) };
};
};
template <>
struct nodes<binary_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
typedef typename ParserT::left_t left_t;
typedef typename ParserT::right_t right_t;
typedef typename left_t::parser_category_t left_category_t;
typedef typename right_t::parser_category_t right_category_t;
typedef count self_t;
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum {
leftcount = (nodes<left_category_t>
::template count<left_t, LeafCountT>::value),
rightcount = (nodes<right_category_t>
::template count<right_t, LeafCountT>::value),
value = ((self_t::leftcount) + (self_t::rightcount) + 1)
};
};
};
///////////////////////////////////////////////////////////////////////////
//
// Helper template for counting the number of leaf nodes contained in a
// given parser type.
// Only plain_parser_category type parsers are counted as leaf nodes.
//
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct leafs;
template <>
struct leafs<plain_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum { value = (LeafCountT::value + 1) };
};
};
template <>
struct leafs<unary_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
typedef typename ParserT::subject_t subject_t;
typedef typename subject_t::parser_category_t subject_category_t;
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum { value = (leafs<subject_category_t>
::template count<subject_t, LeafCountT>::value) };
};
};
template <>
struct leafs<action_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
typedef typename ParserT::subject_t subject_t;
typedef typename subject_t::parser_category_t subject_category_t;
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum { value = (leafs<subject_category_t>
::template count<subject_t, LeafCountT>::value) };
};
};
template <>
struct leafs<binary_parser_category> {
template <typename ParserT, typename LeafCountT>
struct count {
typedef typename ParserT::left_t left_t;
typedef typename ParserT::right_t right_t;
typedef typename left_t::parser_category_t left_category_t;
typedef typename right_t::parser_category_t right_category_t;
typedef count self_t;
// __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
enum {
leftcount = (leafs<left_category_t>
::template count<left_t, LeafCountT>::value),
rightcount = (leafs<right_category_t>
::template count<right_t, LeafCountT>::value),
value = (self_t::leftcount + self_t::rightcount)
};
};
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace boost::spirit
#endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
@@ -0,0 +1,116 @@
/*=============================================================================
Copyright (c) 2002-2003 Joel de Guzman
Copyright (c) 2002-2003 Hartmut Kaiser
Copyright (c) 2003 Martin Wille
http://spirit.sourceforge.net/
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)
#define BOOST_SPIRIT_PARSER_TRAITS_IPP
#include <boost/spirit/home/classic/core/composite/operators.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
namespace impl
{
///////////////////////////////////////////////////////////////////////////
struct parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_alternative = false);
BOOST_STATIC_CONSTANT(bool, is_sequence = false);
BOOST_STATIC_CONSTANT(bool, is_sequential_or = false);
BOOST_STATIC_CONSTANT(bool, is_intersection = false);
BOOST_STATIC_CONSTANT(bool, is_difference = false);
BOOST_STATIC_CONSTANT(bool, is_exclusive_or = false);
BOOST_STATIC_CONSTANT(bool, is_optional = false);
BOOST_STATIC_CONSTANT(bool, is_kleene_star = false);
BOOST_STATIC_CONSTANT(bool, is_positive = false);
};
template <typename ParserT>
struct parser_type_traits : public parser_type_traits_base {
// no definition here, fallback for all not explicitly mentioned parser
// types
};
template <typename A, typename B>
struct parser_type_traits<alternative<A, B> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_alternative = true);
};
template <typename A, typename B>
struct parser_type_traits<sequence<A, B> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_sequence = true);
};
template <typename A, typename B>
struct parser_type_traits<sequential_or<A, B> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_sequential_or = true);
};
template <typename A, typename B>
struct parser_type_traits<intersection<A, B> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_intersection = true);
};
template <typename A, typename B>
struct parser_type_traits<difference<A, B> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_difference = true);
};
template <typename A, typename B>
struct parser_type_traits<exclusive_or<A, B> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_exclusive_or = true);
};
template <typename S>
struct parser_type_traits<optional<S> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_optional = true);
};
template <typename S>
struct parser_type_traits<kleene_star<S> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_kleene_star = true);
};
template <typename S>
struct parser_type_traits<positive<S> >
: public parser_type_traits_base {
BOOST_STATIC_CONSTANT(bool, is_positive = true);
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace boost::spirit
#endif // !defined(BOOST_SPIRIT_PARSER_TRAITS_IPP)
@@ -0,0 +1,451 @@
/*=============================================================================
Copyright (c) 2002-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
Use, modification and distribution is subject to 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_SPIRIT_REFACTORING_IPP
#define BOOST_SPIRIT_REFACTORING_IPP
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
//
// The struct 'self_nested_refactoring' is used to indicate, that the
// refactoring algorithm should be 'self-nested'.
//
// The struct 'non_nested_refactoring' is used to indicate, that no nesting
// of refactoring algorithms is reqired.
//
///////////////////////////////////////////////////////////////////////////////
struct non_nested_refactoring { typedef non_nested_refactoring embed_t; };
struct self_nested_refactoring { typedef self_nested_refactoring embed_t; };
///////////////////////////////////////////////////////////////////////////////
namespace impl {
///////////////////////////////////////////////////////////////////////////////
//
// Helper templates for refactoring parsers
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
// refactor the left unary operand of a binary parser
//
// The refactoring should be done only if the left operand is an
// unary_parser_category parser.
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct refactor_unary_nested {
template <
typename ParserT, typename NestedT,
typename ScannerT, typename BinaryT
>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary,
NestedT const& /*nested_d*/)
{
return binary.parse(scan);
}
};
template <>
struct refactor_unary_nested<unary_parser_category> {
template <
typename ParserT, typename ScannerT, typename BinaryT,
typename NestedT
>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary,
NestedT const& nested_d)
{
typedef typename BinaryT::parser_generator_t op_t;
typedef
typename BinaryT::left_t::parser_generator_t
unary_t;
return
unary_t::generate(
nested_d[
op_t::generate(binary.left().subject(), binary.right())
]
).parse(scan);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct refactor_unary_non_nested {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary)
{
return binary.parse(scan);
}
};
template <>
struct refactor_unary_non_nested<unary_parser_category> {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary)
{
typedef typename BinaryT::parser_generator_t op_t;
typedef
typename BinaryT::left_t::parser_generator_t
unary_t;
return unary_t::generate(
op_t::generate(binary.left().subject(), binary.right())
).parse(scan);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename NestedT>
struct refactor_unary_type {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, BinaryT const& binary,
NestedT const& nested_d)
{
typedef
typename BinaryT::left_t::parser_category_t
parser_category_t;
return refactor_unary_nested<parser_category_t>::
parse(p, scan, binary, nested_d);
}
};
template <>
struct refactor_unary_type<non_nested_refactoring> {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, BinaryT const& binary,
non_nested_refactoring const&)
{
typedef
typename BinaryT::left_t::parser_category_t
parser_category_t;
return refactor_unary_non_nested<parser_category_t>::
parse(p, scan, binary);
}
};
template <>
struct refactor_unary_type<self_nested_refactoring> {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, BinaryT const& binary,
self_nested_refactoring const &nested_tag)
{
typedef
typename BinaryT::left_t::parser_category_t
parser_category_t;
typedef typename ParserT::parser_generator_t parser_generator_t;
parser_generator_t nested_d(nested_tag);
return refactor_unary_nested<parser_category_t>::
parse(p, scan, binary, nested_d);
}
};
///////////////////////////////////////////////////////////////////////////
//
// refactor the action on the left operand of a binary parser
//
// The refactoring should be done only if the left operand is an
// action_parser_category parser.
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct refactor_action_nested {
template <
typename ParserT, typename ScannerT, typename BinaryT,
typename NestedT
>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary,
NestedT const& nested_d)
{
return nested_d[binary].parse(scan);
}
};
template <>
struct refactor_action_nested<action_parser_category> {
template <
typename ParserT, typename ScannerT, typename BinaryT,
typename NestedT
>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary,
NestedT const& nested_d)
{
typedef typename BinaryT::parser_generator_t binary_gen_t;
return (
nested_d[
binary_gen_t::generate(
binary.left().subject(),
binary.right()
)
][binary.left().predicate()]
).parse(scan);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct refactor_action_non_nested {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary)
{
return binary.parse(scan);
}
};
template <>
struct refactor_action_non_nested<action_parser_category> {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, BinaryT const& binary)
{
typedef typename BinaryT::parser_generator_t binary_gen_t;
return (
binary_gen_t::generate(
binary.left().subject(),
binary.right()
)[binary.left().predicate()]
).parse(scan);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename NestedT>
struct refactor_action_type {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, BinaryT const& binary,
NestedT const& nested_d)
{
typedef
typename BinaryT::left_t::parser_category_t
parser_category_t;
return refactor_action_nested<parser_category_t>::
parse(p, scan, binary, nested_d);
}
};
template <>
struct refactor_action_type<non_nested_refactoring> {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, BinaryT const& binary,
non_nested_refactoring const&)
{
typedef
typename BinaryT::left_t::parser_category_t
parser_category_t;
return refactor_action_non_nested<parser_category_t>::
parse(p, scan, binary);
}
};
template <>
struct refactor_action_type<self_nested_refactoring> {
template <typename ParserT, typename ScannerT, typename BinaryT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, BinaryT const& binary,
self_nested_refactoring const &nested_tag)
{
typedef typename ParserT::parser_generator_t parser_generator_t;
typedef
typename BinaryT::left_t::parser_category_t
parser_category_t;
parser_generator_t nested_d(nested_tag);
return refactor_action_nested<parser_category_t>::
parse(p, scan, binary, nested_d);
}
};
///////////////////////////////////////////////////////////////////////////
//
// refactor the action attached to a binary parser
//
// The refactoring should be done only if the given parser is an
// binary_parser_category parser.
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct attach_action_nested {
template <
typename ParserT, typename ScannerT, typename ActionT,
typename NestedT
>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, ActionT const &action,
NestedT const& nested_d)
{
return action.parse(scan);
}
};
template <>
struct attach_action_nested<binary_parser_category> {
template <
typename ParserT, typename ScannerT, typename ActionT,
typename NestedT
>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, ActionT const &action,
NestedT const& nested_d)
{
typedef
typename ActionT::subject_t::parser_generator_t
binary_gen_t;
return (
binary_gen_t::generate(
nested_d[action.subject().left()[action.predicate()]],
nested_d[action.subject().right()[action.predicate()]]
)
).parse(scan);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct attach_action_non_nested {
template <typename ParserT, typename ScannerT, typename ActionT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, ActionT const &action)
{
return action.parse(scan);
}
};
template <>
struct attach_action_non_nested<binary_parser_category> {
template <typename ParserT, typename ScannerT, typename ActionT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &, ScannerT const& scan, ActionT const &action)
{
typedef
typename ActionT::subject_t::parser_generator_t
binary_gen_t;
return (
binary_gen_t::generate(
action.subject().left()[action.predicate()],
action.subject().right()[action.predicate()]
)
).parse(scan);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename NestedT>
struct attach_action_type {
template <typename ParserT, typename ScannerT, typename ActionT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, ActionT const& action,
NestedT const& nested_d)
{
typedef
typename ActionT::subject_t::parser_category_t
parser_category_t;
return attach_action_nested<parser_category_t>::
parse(p, scan, action, nested_d);
}
};
template <>
struct attach_action_type<non_nested_refactoring> {
template <typename ParserT, typename ScannerT, typename ActionT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, ActionT const &action,
non_nested_refactoring const&)
{
typedef
typename ActionT::subject_t::parser_category_t
parser_category_t;
return attach_action_non_nested<parser_category_t>::
parse(p, scan, action);
}
};
template <>
struct attach_action_type<self_nested_refactoring> {
template <typename ParserT, typename ScannerT, typename ActionT>
static typename parser_result<ParserT, ScannerT>::type
parse(ParserT const &p, ScannerT const& scan, ActionT const &action,
self_nested_refactoring const& nested_tag)
{
typedef typename ParserT::parser_generator_t parser_generator_t;
typedef
typename ActionT::subject_t::parser_category_t
parser_category_t;
parser_generator_t nested_d(nested_tag);
return attach_action_nested<parser_category_t>::
parse(p, scan, action, nested_d);
}
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace boost::spirit
#endif
@@ -0,0 +1,393 @@
/*=============================================================================
Copyright (c) 2002-2003 Joel de Guzman
Copyright (c) 2002-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
Use, modification and distribution is subject to the Boost Software
License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_TRAVERSE_IPP)
#define BOOST_SPIRIT_TRAVERSE_IPP
///////////////////////////////////////////////////////////////////////////////
#include <boost/spirit/home/classic/meta/fundamental.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
template <typename CategoryT>
struct traverse_post_order_return_category;
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
//
// Environment class for post_order_traversal
//
///////////////////////////////////////////////////////////////////////////////
template <int Level, int Node, int Index, int LastLeft>
struct traverse_post_order_env {
BOOST_STATIC_CONSTANT(int, level = Level);
BOOST_STATIC_CONSTANT(int, node = Node);
BOOST_STATIC_CONSTANT(int, index = Index);
BOOST_STATIC_CONSTANT(int, lastleft = LastLeft);
};
///////////////////////////////////////////////////////////////////////////////
//
// traverse_post_order_return template
//
// This template is a helper for dispatching the calculation of a parser
// type result for a traversal level to the corresponding parser_category
// based specialization.
//
///////////////////////////////////////////////////////////////////////////////
template <typename MetaT, typename ParserT, typename EnvT>
struct traverse_post_order_return {
typedef typename ParserT::parser_category_t parser_category_t;
typedef typename impl::traverse_post_order_return_category<parser_category_t>
::template result<MetaT, ParserT, EnvT>::type type;
};
///////////////////////////////////////////////////////////////////////////////
//
// parser_traversal_..._result templates
//
// These are metafunctions, which calculate the resulting parser type
// for all subparsers and feed these types to the user supplied
// metafunctions to get back the resulting parser type of this traversal
// level.
//
///////////////////////////////////////////////////////////////////////////////
template <typename MetaT, typename ParserT, typename EnvT>
struct parser_traversal_plain_result {
typedef typename MetaT::template plain_result<ParserT, EnvT>::type type;
};
///////////////////////////////////////////////////////////////////////////////
template <typename MetaT, typename UnaryT, typename SubjectT, typename EnvT>
struct parser_traversal_unary_result {
typedef typename MetaT
::template unary_result<UnaryT, SubjectT, EnvT>::type type;
};
///////////////////////////////////////////////////////////////////////////////
template <typename MetaT, typename ActionT, typename SubjectT, typename EnvT>
struct parser_traversal_action_result {
typedef typename MetaT
::template action_result<ActionT, SubjectT, EnvT>::type type;
};
///////////////////////////////////////////////////////////////////////////////
template <
typename MetaT, typename BinaryT, typename LeftT,
typename RightT, typename EnvT
>
struct parser_traversal_binary_result {
BOOST_STATIC_CONSTANT(int,
thisnum = (node_count<BinaryT>::value + EnvT::lastleft-1));
BOOST_STATIC_CONSTANT(int,
leftnum = (node_count<LeftT>::value + EnvT::lastleft-1));
BOOST_STATIC_CONSTANT(int,
leafnum = (leaf_count<LeftT>::value + EnvT::index));
typedef parser_traversal_binary_result self_t;
// left traversal environment and resulting parser type
typedef traverse_post_order_env<
(EnvT::level+1), (self_t::leftnum), (EnvT::index), (EnvT::lastleft)
> left_sub_env_t;
typedef typename traverse_post_order_return<
MetaT, LeftT, left_sub_env_t
>::type
left_t;
// right traversal environment and resulting parser type
typedef traverse_post_order_env<
(EnvT::level+1), (self_t::thisnum-1), (self_t::leafnum), (self_t::leftnum+1)
> right_sub_env_t;
typedef typename traverse_post_order_return<
MetaT, RightT, right_sub_env_t
>::type
right_t;
typedef typename MetaT::template binary_result<
BinaryT, left_t, right_t, EnvT
>::type
type;
};
///////////////////////////////////////////////////////////////////////////////
namespace impl
{
///////////////////////////////////////////////////////////////////////////
//
// Meta functions, which dispatch the calculation of the return type of
// of the post_order traverse function to the result template of the
// corresponding parser_category based metafunction template.
//
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct traverse_post_order_return_category;
template <>
struct traverse_post_order_return_category<plain_parser_category> {
template <typename MetaT, typename ParserT, typename EnvT>
struct result {
typedef typename parser_traversal_plain_result<
MetaT, ParserT, EnvT
>::type
type;
};
};
template <>
struct traverse_post_order_return_category<unary_parser_category> {
template <typename MetaT, typename ParserT, typename EnvT>
struct result {
typedef typename parser_traversal_unary_result<
MetaT, ParserT, typename ParserT::subject_t, EnvT
>::type
type;
};
};
template <>
struct traverse_post_order_return_category<action_parser_category> {
template <typename MetaT, typename ParserT, typename EnvT>
struct result {
typedef typename parser_traversal_action_result<
MetaT, ParserT, typename ParserT::subject_t, EnvT
>::type
type;
};
};
template <>
struct traverse_post_order_return_category<binary_parser_category> {
template <typename MetaT, typename ParserT, typename EnvT>
struct result {
typedef typename parser_traversal_binary_result<
MetaT, ParserT, typename ParserT::left_t,
typename ParserT::right_t, EnvT
>::type
type;
};
};
///////////////////////////////////////////////////////////////////////////
//
// Post-order parser traversal
//
// The following templates contain the parser_category based code for
//
// - calculating the type of the resulting parser, which is to be
// returned from a level of traversal
// - traversing down the composite parser structure, this traversal
// returnes a new parser object
//
// Both tasks are delegated to the MetaT metafunction supplied by the
// user.
//
///////////////////////////////////////////////////////////////////////////
template <typename CategoryT>
struct traverse_post_order;
template <>
struct traverse_post_order<plain_parser_category> {
template <typename MetaT, typename ParserT, typename EnvT>
struct result {
typedef
typename parser_traversal_plain_result<MetaT, ParserT, EnvT>::type
type;
};
template <typename MetaT, typename ParserT, typename EnvT>
static
typename parser_traversal_plain_result<MetaT, ParserT, EnvT>::type
generate(MetaT const &meta_, ParserT const &parser_, EnvT const &env)
{
return meta_.generate_plain(parser_, env);
}
};
template <>
struct traverse_post_order<unary_parser_category> {
template <
typename MetaT, typename ParserT, typename SubjectT, typename EnvT
>
struct result {
typedef typename parser_traversal_unary_result<
MetaT, ParserT, SubjectT, EnvT
>::type
type;
};
template <typename MetaT, typename ParserT, typename EnvT>
static
typename parser_traversal_unary_result<
MetaT, ParserT,
typename traverse_post_order_return<
MetaT, typename ParserT::subject_t, EnvT
>::type,
EnvT
>::type
generate(MetaT const &meta_, ParserT const &unary_, EnvT const &env)
{
typedef typename ParserT::subject_t subject_t;
typedef typename subject_t::parser_category_t subject_category_t;
return meta_.generate_unary(
unary_,
traverse_post_order<subject_category_t>::generate(meta_,
unary_.subject(),
traverse_post_order_env<
EnvT::level+1, EnvT::node-1, EnvT::index, EnvT::lastleft
>()
),
env
);
}
};
template <>
struct traverse_post_order<action_parser_category> {
template <
typename MetaT, typename ParserT, typename SubjectT, typename EnvT
>
struct result {
typedef typename parser_traversal_action_result<
MetaT, ParserT, SubjectT, EnvT
>::type
type;
};
template <typename MetaT, typename ParserT, typename EnvT>
static
typename parser_traversal_action_result<
MetaT, ParserT,
typename traverse_post_order_return<
MetaT, typename ParserT::subject_t, EnvT
>::type,
EnvT
>::type
generate(MetaT const &meta_, ParserT const &action_, EnvT const &env)
{
typedef typename ParserT::subject_t subject_t;
typedef typename subject_t::parser_category_t subject_category_t;
return meta_.generate_action(
action_,
traverse_post_order<subject_category_t>::generate(meta_,
action_.subject(),
traverse_post_order_env<
EnvT::level+1, EnvT::node-1, EnvT::index, EnvT::lastleft
>()
),
env
);
}
};
template <>
struct traverse_post_order<binary_parser_category> {
template <
typename MetaT, typename ParserT, typename LeftT,
typename RightT, typename EnvT
>
struct result {
typedef typename parser_traversal_binary_result<
MetaT, ParserT, LeftT, RightT, EnvT
>::type
type;
};
template <typename MetaT, typename ParserT, typename EnvT>
static
typename parser_traversal_binary_result<
MetaT, ParserT,
typename traverse_post_order_return<
MetaT, typename ParserT::left_t, EnvT
>::type,
typename traverse_post_order_return<
MetaT, typename ParserT::right_t, EnvT
>::type,
EnvT
>::type
generate(MetaT const &meta_, ParserT const &binary_, EnvT const& /*env*/)
{
typedef typename ParserT::left_t left_t;
typedef typename ParserT::right_t right_t;
typedef typename left_t::parser_category_t left_category_t;
typedef typename right_t::parser_category_t right_category_t;
enum {
leftnum = (node_count<left_t>::value + EnvT::lastleft-1),
thisnum = (node_count<ParserT>::value + EnvT::lastleft-1),
rightnum = (thisnum-1),
leafnum = (leaf_count<left_t>::value + EnvT::index)
};
return meta_.generate_binary(
binary_,
traverse_post_order<left_category_t>::generate(
meta_, binary_.left(),
traverse_post_order_env<
EnvT::level+1, leftnum, EnvT::index, EnvT::lastleft
>()
),
traverse_post_order<right_category_t>::generate(
meta_, binary_.right(),
traverse_post_order_env<
EnvT::level+1, rightnum, leafnum, leftnum+1
>()
),
traverse_post_order_env<
EnvT::level, thisnum, EnvT::index, EnvT::lastleft
>()
);
}
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace boost::spirit
#endif // !defined(BOOST_SPIRIT_TRAVERSE_IPP)
@@ -0,0 +1,320 @@
/*=============================================================================
Copyright (c) 2002-2003 Joel de Guzman
Copyright (c) 2002-2003 Hartmut Kaiser
Copyright (c) 2003 Martin Wille
http://spirit.sourceforge.net/
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_PARSER_TRAITS_HPP)
#define BOOST_SPIRIT_PARSER_TRAITS_HPP
#include <boost/type_traits/is_base_and_derived.hpp>
#include <boost/static_assert.hpp>
#include <boost/spirit/home/classic/namespace.hpp>
#include <boost/spirit/home/classic/core/parser.hpp>
#include <boost/spirit/home/classic/meta/impl/parser_traits.ipp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////////
//
// Parser traits templates
//
// Used to determine the type and several other characteristics of a given
// parser type.
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// The is_parser traits template can be used to tell wether a given
// class is a parser.
//
///////////////////////////////////////////////////////////////////////////////
template <typename T>
struct is_parser
{
BOOST_STATIC_CONSTANT(bool, value =
(::boost::is_base_and_derived<parser<T>, T>::value));
// [JDG 2/3/03] simplified implementation by
// using boost::is_base_and_derived
};
///////////////////////////////////////////////////////////////////////////////
//
// The is_unary_composite traits template can be used to tell if a given
// parser is a unary parser as for instance kleene_star or optional.
//
///////////////////////////////////////////////////////////////////////////////
template <typename UnaryT>
struct is_unary_composite {
BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<
typename UnaryT::parser_category_t, unary_parser_category>::value));
};
///////////////////////////////////////////////////////////////////////////////
//
// The is_acction_parser traits template can be used to tell if a given
// parser is a action parser, i.e. it is a composite consisting of a
// auxilliary parser and an attached semantic action.
//
///////////////////////////////////////////////////////////////////////////////
template <typename ActionT>
struct is_action_parser {
BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<
typename ActionT::parser_category_t, action_parser_category>::value));
};
///////////////////////////////////////////////////////////////////////////////
//
// The is_binary_composite traits template can be used to tell if a given
// parser is a binary parser as for instance sequence or difference.
//
///////////////////////////////////////////////////////////////////////////////
template <typename BinaryT>
struct is_binary_composite {
BOOST_STATIC_CONSTANT(bool, value = (::boost::is_convertible<
typename BinaryT::parser_category_t, binary_parser_category>::value));
};
///////////////////////////////////////////////////////////////////////////////
//
// The is_composite_parser traits template can be used to tell if a given
// parser is a unary or a binary parser composite type.
//
///////////////////////////////////////////////////////////////////////////////
template <typename CompositeT>
struct is_composite_parser {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::is_unary_composite<CompositeT>::value ||
::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<CompositeT>::value));
};
///////////////////////////////////////////////////////////////////////////////
template <typename ParserT>
struct is_alternative {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_alternative));
};
template <typename ParserT>
struct is_sequence {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_sequence));
};
template <typename ParserT>
struct is_sequential_or {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_sequential_or));
};
template <typename ParserT>
struct is_intersection {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_intersection));
};
template <typename ParserT>
struct is_difference {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_difference));
};
template <typename ParserT>
struct is_exclusive_or {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_exclusive_or));
};
template <typename ParserT>
struct is_optional {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_optional));
};
template <typename ParserT>
struct is_kleene_star {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_kleene_star));
};
template <typename ParserT>
struct is_positive {
BOOST_STATIC_CONSTANT(bool, value = (
::BOOST_SPIRIT_CLASSIC_NS::impl::parser_type_traits<ParserT>::is_positive));
};
///////////////////////////////////////////////////////////////////////////////
//
// Parser extraction templates
//
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
//
// The unary_subject template can be used to return the type of the
// parser used as the subject of an unary parser.
// If the parser under inspection is not an unary type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename UnaryT>
struct unary_subject {
BOOST_STATIC_ASSERT(BOOST_SPIRIT_CLASSIC_NS::is_unary_composite<UnaryT>::value);
typedef typename UnaryT::subject_t type;
};
///////////////////////////////////////////////////////////////////////////////
//
// The get_unary_subject template function returns the parser object, which
// is used as the subject of an unary parser.
// If the parser under inspection is not an unary type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename UnaryT>
inline typename unary_subject<UnaryT>::type const &
get_unary_subject(UnaryT const &unary_)
{
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_unary_composite<UnaryT>::value);
return unary_.subject();
}
///////////////////////////////////////////////////////////////////////////////
//
// The binary_left_subject and binary_right_subject templates can be used to
// return the types of the parsers used as the left and right subject of an
// binary parser.
// If the parser under inspection is not a binary type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename BinaryT>
struct binary_left_subject {
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
typedef typename BinaryT::left_t type;
};
template <typename BinaryT>
struct binary_right_subject {
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
typedef typename BinaryT::right_t type;
};
///////////////////////////////////////////////////////////////////////////////
//
// The get_binary_left_subject and get_binary_right_subject template functions
// return the parser object, which is used as the left or right subject of a
// binary parser.
// If the parser under inspection is not a binary type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename BinaryT>
inline typename binary_left_subject<BinaryT>::type const &
get_binary_left_subject(BinaryT const &binary_)
{
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
return binary_.left();
}
template <typename BinaryT>
inline typename binary_right_subject<BinaryT>::type const &
get_binary_right_subject(BinaryT const &binary_)
{
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_binary_composite<BinaryT>::value);
return binary_.right();
}
///////////////////////////////////////////////////////////////////////////////
//
// The action_subject template can be used to return the type of the
// parser used as the subject of an action parser.
// If the parser under inspection is not an action type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename ActionT>
struct action_subject {
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
typedef typename ActionT::subject_t type;
};
///////////////////////////////////////////////////////////////////////////////
//
// The get_action_subject template function returns the parser object, which
// is used as the subject of an action parser.
// If the parser under inspection is not an action type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename ActionT>
inline typename action_subject<ActionT>::type const &
get_action_subject(ActionT const &action_)
{
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
return action_.subject();
}
///////////////////////////////////////////////////////////////////////////////
//
// The semantic_action template can be used to return the type of the
// attached semantic action of an action parser.
// If the parser under inspection is not an action type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename ActionT>
struct semantic_action {
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
typedef typename ActionT::predicate_t type;
};
///////////////////////////////////////////////////////////////////////////////
//
// The get_semantic_action template function returns the attached semantic
// action of an action parser.
// If the parser under inspection is not an action type parser the compilation
// will fail.
//
///////////////////////////////////////////////////////////////////////////////
template <typename ActionT>
inline typename semantic_action<ActionT>::type const &
get_semantic_action(ActionT const &action_)
{
BOOST_STATIC_ASSERT(::BOOST_SPIRIT_CLASSIC_NS::is_action_parser<ActionT>::value);
return action_.predicate();
}
///////////////////////////////////////////////////////////////////////////////
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace BOOST_SPIRIT_CLASSIC_NS
#endif // !defined(BOOST_SPIRIT_PARSER_TRAITS_HPP)
@@ -0,0 +1,287 @@
/*=============================================================================
Copyright (c) 2002-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
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_SPIRIT_REFACTORING_HPP
#define BOOST_SPIRIT_REFACTORING_HPP
///////////////////////////////////////////////////////////////////////////////
#include <boost/static_assert.hpp>
#include <boost/spirit/home/classic/namespace.hpp>
#include <boost/spirit/home/classic/meta/as_parser.hpp>
#include <boost/spirit/home/classic/core/parser.hpp>
#include <boost/spirit/home/classic/core/composite/composite.hpp>
#include <boost/spirit/home/classic/meta/impl/refactoring.ipp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(push)
#pragma warning(disable:4512) //assignment operator could not be generated
#endif
///////////////////////////////////////////////////////////////////////////////
//
// refactor_unary_parser class
//
// This helper template allows to attach an unary operation to a newly
// constructed parser, which combines the subject of the left operand of
// the original given parser (BinaryT) with the right operand of the
// original binary parser through the original binary operation and
// rewraps the resulting parser with the original unary operator.
//
// For instance given the parser:
// *some_parser - another_parser
//
// will be refactored to:
// *(some_parser - another_parser)
//
// If the parser to refactor is not a unary parser, no refactoring is done
// at all.
//
// The original parser should be a binary_parser_category parser,
// else the compilation will fail
//
///////////////////////////////////////////////////////////////////////////////
template <typename NestedT = non_nested_refactoring>
class refactor_unary_gen;
template <typename BinaryT, typename NestedT = non_nested_refactoring>
class refactor_unary_parser :
public parser<refactor_unary_parser<BinaryT, NestedT> > {
public:
// the parser to refactor has to be at least a binary_parser_category
// parser
BOOST_STATIC_ASSERT((
boost::is_convertible<typename BinaryT::parser_category_t,
binary_parser_category>::value
));
refactor_unary_parser(BinaryT const& binary_, NestedT const& nested_)
: binary(binary_), nested(nested_) {}
typedef refactor_unary_parser<BinaryT, NestedT> self_t;
typedef refactor_unary_gen<NestedT> parser_generator_t;
typedef typename BinaryT::left_t::parser_category_t parser_category_t;
template <typename ScannerT>
typename parser_result<self_t, ScannerT>::type
parse(ScannerT const& scan) const
{
return impl::refactor_unary_type<NestedT>::
parse(*this, scan, binary, nested);
}
private:
typename as_parser<BinaryT>::type::embed_t binary;
typename NestedT::embed_t nested;
};
//////////////////////////////////
template <typename NestedT>
class refactor_unary_gen {
public:
typedef refactor_unary_gen<NestedT> embed_t;
refactor_unary_gen(NestedT const& nested_ = non_nested_refactoring())
: nested(nested_) {}
template <typename ParserT>
refactor_unary_parser<ParserT, NestedT>
operator[](parser<ParserT> const& subject) const
{
return refactor_unary_parser<ParserT, NestedT>
(subject.derived(), nested);
}
private:
typename NestedT::embed_t nested;
};
const refactor_unary_gen<> refactor_unary_d = refactor_unary_gen<>();
///////////////////////////////////////////////////////////////////////////////
//
// refactor_action_parser class
//
// This helper template allows to attach an action taken from the left
// operand of the given binary parser to a newly constructed parser,
// which combines the subject of the left operand of the original binary
// parser with the right operand of the original binary parser by means of
// the original binary operator parser.
//
// For instance the parser:
// some_parser[some_attached_functor] - another_parser
//
// will be refactored to:
// (some_parser - another_parser)[some_attached_functor]
//
// If the left operand to refactor is not an action parser, no refactoring
// is done at all.
//
// The original parser should be a binary_parser_category parser,
// else the compilation will fail
//
///////////////////////////////////////////////////////////////////////////////
template <typename NestedT = non_nested_refactoring>
class refactor_action_gen;
template <typename BinaryT, typename NestedT = non_nested_refactoring>
class refactor_action_parser :
public parser<refactor_action_parser<BinaryT, NestedT> > {
public:
// the parser to refactor has to be at least a binary_parser_category
// parser
BOOST_STATIC_ASSERT((
boost::is_convertible<typename BinaryT::parser_category_t,
binary_parser_category>::value
));
refactor_action_parser(BinaryT const& binary_, NestedT const& nested_)
: binary(binary_), nested(nested_) {}
typedef refactor_action_parser<BinaryT, NestedT> self_t;
typedef refactor_action_gen<NestedT> parser_generator_t;
typedef typename BinaryT::left_t::parser_category_t parser_category_t;
template <typename ScannerT>
typename parser_result<self_t, ScannerT>::type
parse(ScannerT const& scan) const
{
return impl::refactor_action_type<NestedT>::
parse(*this, scan, binary, nested);
}
private:
typename as_parser<BinaryT>::type::embed_t binary;
typename NestedT::embed_t nested;
};
//////////////////////////////////
template <typename NestedT>
class refactor_action_gen {
public:
typedef refactor_action_gen<NestedT> embed_t;
refactor_action_gen(NestedT const& nested_ = non_nested_refactoring())
: nested(nested_) {}
template <typename ParserT>
refactor_action_parser<ParserT, NestedT>
operator[](parser<ParserT> const& subject) const
{
return refactor_action_parser<ParserT, NestedT>
(subject.derived(), nested);
}
private:
typename NestedT::embed_t nested;
};
const refactor_action_gen<> refactor_action_d = refactor_action_gen<>();
///////////////////////////////////////////////////////////////////////////////
//
// attach_action_parser class
//
// This helper template allows to attach an action given separately
// to all parsers, out of which the given parser is constructed and
// reconstructs a new parser having the same structure.
//
// For instance the parser:
// (some_parser >> another_parser)[some_attached_functor]
//
// will be refactored to:
// some_parser[some_attached_functor]
// >> another_parser[some_attached_functor]
//
// The original parser should be a action_parser_category parser,
// else the compilation will fail.
//
// If the parser, to which the action is attached is not an binary parser,
// no refactoring is done at all.
//
///////////////////////////////////////////////////////////////////////////////
template <typename NestedT = non_nested_refactoring>
class attach_action_gen;
template <typename ActionT, typename NestedT = non_nested_refactoring>
class attach_action_parser :
public parser<attach_action_parser<ActionT, NestedT> > {
public:
// the parser to refactor has to be at least a action_parser_category
// parser
BOOST_STATIC_ASSERT((
boost::is_convertible<typename ActionT::parser_category_t,
action_parser_category>::value
));
attach_action_parser(ActionT const& actor_, NestedT const& nested_)
: actor(actor_), nested(nested_) {}
typedef attach_action_parser<ActionT, NestedT> self_t;
typedef attach_action_gen<NestedT> parser_generator_t;
typedef typename ActionT::parser_category_t parser_category_t;
template <typename ScannerT>
typename parser_result<self_t, ScannerT>::type
parse(ScannerT const& scan) const
{
return impl::attach_action_type<NestedT>::
parse(*this, scan, actor, nested);
}
private:
typename as_parser<ActionT>::type::embed_t actor;
typename NestedT::embed_t nested;
};
//////////////////////////////////
template <typename NestedT>
class attach_action_gen {
public:
typedef attach_action_gen<NestedT> embed_t;
attach_action_gen(NestedT const& nested_ = non_nested_refactoring())
: nested(nested_) {}
template <typename ParserT, typename ActionT>
attach_action_parser<action<ParserT, ActionT>, NestedT>
operator[](action<ParserT, ActionT> const& actor) const
{
return attach_action_parser<action<ParserT, ActionT>, NestedT>
(actor, nested);
}
private:
typename NestedT::embed_t nested;
};
const attach_action_gen<> attach_action_d = attach_action_gen<>();
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
#pragma warning(pop)
#endif
///////////////////////////////////////////////////////////////////////////////
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace BOOST_SPIRIT_CLASSIC_NS
#endif // BOOST_SPIRIT_REFACTORING_HPP
@@ -0,0 +1,222 @@
/*=============================================================================
Copyright (c) 2002-2003 Joel de Guzman
Copyright (c) 2002-2003 Hartmut Kaiser
http://spirit.sourceforge.net/
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#if !defined(BOOST_SPIRIT_TRAVERSE_HPP)
#define BOOST_SPIRIT_TRAVERSE_HPP
#include <boost/spirit/home/classic/namespace.hpp>
#include <boost/spirit/home/classic/meta/impl/traverse.ipp>
namespace boost { namespace spirit {
BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
///////////////////////////////////////////////////////////////////////////
//
// Post-order traversal of auxilliary parsers.
//
///////////////////////////////////////////////////////////////////////////
struct post_order
{
// Return the parser type, which is generated as the result of the
// traverse function below.
template <typename MetaT, typename ParserT>
struct result
{
typedef typename
traverse_post_order_return<
MetaT
, ParserT
, traverse_post_order_env<0, 0, 0, 0>
>::type
type;
};
// Traverse a given parser and refactor it with the help of the given
// MetaT metafunction template.
template <typename MetaT, typename ParserT>
static typename result<MetaT, ParserT>::type
traverse(MetaT const &meta_, ParserT const &parser_)
{
typedef typename ParserT::parser_category_t parser_category_t;
return impl::traverse_post_order<parser_category_t>::generate(
meta_, parser_, traverse_post_order_env<0, 0, 0, 0>());
}
};
///////////////////////////////////////////////////////////////////////////
//
// Transform policies
//
// The following policy classes could be used to assemble some new
// transformation metafunction which uses identity transformations
// for some parser_category type parsers.
//
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
// transform plain parsers
template <typename TransformT>
struct plain_identity_policy
{
template <typename ParserT, typename EnvT>
struct plain_result
{
// plain parsers should be embedded and returned correctly
typedef typename ParserT::embed_t type;
};
template <typename ParserT, typename EnvT>
typename parser_traversal_plain_result<TransformT, ParserT, EnvT>::type
generate_plain(ParserT const &parser_, EnvT const& /*env*/) const
{
return parser_;
}
};
//////////////////////////////////
// transform unary parsers
template <typename UnaryT, typename SubjectT>
struct unary_identity_policy_return
{
typedef typename UnaryT::parser_generator_t parser_generator_t;
typedef typename parser_generator_t
::template result<SubjectT>::type type;
};
template <typename TransformT>
struct unary_identity_policy
{
template <typename UnaryT, typename SubjectT, typename EnvT>
struct unary_result
{
typedef
typename unary_identity_policy_return<UnaryT, SubjectT>::type
type;
};
template <typename UnaryT, typename SubjectT, typename EnvT>
typename parser_traversal_unary_result<
TransformT, UnaryT, SubjectT, EnvT>::type
generate_unary(
UnaryT const &, SubjectT const &subject_, EnvT const& /*env*/) const
{
typedef typename UnaryT::parser_generator_t parser_generator_t;
return parser_generator_t::template generate<SubjectT>(subject_);
}
};
//////////////////////////////////
// transform action parsers
template <typename TransformT>
struct action_identity_policy
{
template <typename ActionT, typename SubjectT, typename EnvT>
struct action_result
{
typedef action<SubjectT, typename ActionT::predicate_t> type;
};
template <typename ActionT, typename SubjectT, typename EnvT>
typename parser_traversal_action_result<
TransformT, ActionT, SubjectT, EnvT
>::type
generate_action(ActionT const &action_, SubjectT const &subject_,
EnvT const& /*env*/) const
{
return subject_[action_.predicate()];
}
};
//////////////////////////////////
// transform binary parsers
template <typename BinaryT, typename LeftT, typename RightT>
struct binary_identity_policy_return
{
typedef typename BinaryT::parser_generator_t parser_generator_t;
typedef typename parser_generator_t
::template result<LeftT, RightT>::type type;
};
template <typename TransformT>
struct binary_identity_policy
{
template <typename BinaryT, typename LeftT
, typename RightT, typename EnvT>
struct binary_result {
typedef typename
binary_identity_policy_return<BinaryT, LeftT, RightT>::type
type;
};
template <typename BinaryT, typename LeftT
, typename RightT, typename EnvT>
typename parser_traversal_binary_result<
TransformT, BinaryT, LeftT, RightT, EnvT
>::type
generate_binary(
BinaryT const &, LeftT const& left_
, RightT const& right_, EnvT const& /*env*/) const
{
typedef typename BinaryT::parser_generator_t parser_generator_t;
return parser_generator_t::
template generate<LeftT, RightT>(left_, right_);
}
};
///////////////////////////////////////////////////////////////////////////
//
// transform_policies template
//
// The transform_policies template metafunction could serve as a
// base class for new metafunctions to be passed to the traverse meta
// template (see above), where only minimal parts have to be
// overwritten.
//
///////////////////////////////////////////////////////////////////////////
template <
typename TransformT,
typename PlainPolicyT = plain_identity_policy<TransformT>,
typename UnaryPolicyT = unary_identity_policy<TransformT>,
typename ActionPolicyT = action_identity_policy<TransformT>,
typename BinaryPolicyT = binary_identity_policy<TransformT>
>
struct transform_policies :
public PlainPolicyT,
public UnaryPolicyT,
public ActionPolicyT,
public BinaryPolicyT
{
};
///////////////////////////////////////////////////////////////////////////
//
// Identity transformation
//
// The identity_transform metafunction supplied to the traverse
// template will generate a new parser, which will be exactly
// identical to the parser given as the parameter to the traverse
// metafunction. I.e. the following conceptual 'equation' will be
// always true:
//
// some_parser ==
// post_order::traverse(identity_transform(), some_parser)
//
///////////////////////////////////////////////////////////////////////////
struct identity_transform : transform_policies<identity_transform> {};
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace BOOST_SPIRIT_CLASSIC_NS
#endif // !defined(BOOST_SPIRIT_TRAVERSE_HPP)