Added thirdparty: boost library

This commit is contained in:
Viacheslav Demydiuk
2024-01-06 19:55:56 +02:00
parent bf49f439e1
commit bccd1e7051
15683 changed files with 3239840 additions and 0 deletions
+171
View File
@@ -0,0 +1,171 @@
/*=============================================================================
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 {
BOOST_STATIC_CONSTANT(int, 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;
BOOST_STATIC_CONSTANT(int, 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;
BOOST_STATIC_CONSTANT(int, 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;
BOOST_STATIC_CONSTANT(int,
leftcount = (nodes<left_category_t>
::template count<left_t, LeafCountT>::value));
BOOST_STATIC_CONSTANT(int,
rightcount = (nodes<right_category_t>
::template count<right_t, LeafCountT>::value));
BOOST_STATIC_CONSTANT(int,
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 {
BOOST_STATIC_CONSTANT(int, 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;
BOOST_STATIC_CONSTANT(int, 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;
BOOST_STATIC_CONSTANT(int, 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;
BOOST_STATIC_CONSTANT(int,
leftcount = (leafs<left_category_t>
::template count<left_t, LeafCountT>::value));
BOOST_STATIC_CONSTANT(int,
rightcount = (leafs<right_category_t>
::template count<right_t, LeafCountT>::value));
BOOST_STATIC_CONSTANT(int,
value = (self_t::leftcount + self_t::rightcount));
};
};
} // namespace impl
///////////////////////////////////////////////////////////////////////////////
BOOST_SPIRIT_CLASSIC_NAMESPACE_END
}} // namespace boost::spirit
#endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
+116
View File
@@ -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)
+451
View File
@@ -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
+393
View File
@@ -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)