1 /*=============================================================================
2 Copyright (c) 2002-2003 Hartmut Kaiser
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #if !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)
10 #define BOOST_SPIRIT_FUNDAMENTAL_IPP
12 #include <boost/mpl/int.hpp>
14 namespace boost { namespace spirit {
16 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
20 ///////////////////////////////////////////////////////////////////////////
22 // Helper template for counting the number of nodes contained in a
24 // All parser_category type parsers are counted as nodes.
26 ///////////////////////////////////////////////////////////////////////////
27 template <typename CategoryT>
31 struct nodes<plain_parser_category> {
33 template <typename ParserT, typename LeafCountT>
36 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
37 enum { value = (LeafCountT::value + 1) };
42 struct nodes<unary_parser_category> {
44 template <typename ParserT, typename LeafCountT>
47 typedef typename ParserT::subject_t subject_t;
48 typedef typename subject_t::parser_category_t subject_category_t;
50 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
51 enum { value = (nodes<subject_category_t>
52 ::template count<subject_t, LeafCountT>::value + 1) };
57 struct nodes<action_parser_category> {
59 template <typename ParserT, typename LeafCountT>
62 typedef typename ParserT::subject_t subject_t;
63 typedef typename subject_t::parser_category_t subject_category_t;
65 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
66 enum { value = (nodes<subject_category_t>
67 ::template count<subject_t, LeafCountT>::value + 1) };
72 struct nodes<binary_parser_category> {
74 template <typename ParserT, typename LeafCountT>
77 typedef typename ParserT::left_t left_t;
78 typedef typename ParserT::right_t right_t;
79 typedef typename left_t::parser_category_t left_category_t;
80 typedef typename right_t::parser_category_t right_category_t;
84 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
86 leftcount = (nodes<left_category_t>
87 ::template count<left_t, LeafCountT>::value),
88 rightcount = (nodes<right_category_t>
89 ::template count<right_t, LeafCountT>::value),
90 value = ((self_t::leftcount) + (self_t::rightcount) + 1)
95 ///////////////////////////////////////////////////////////////////////////
97 // Helper template for counting the number of leaf nodes contained in a
99 // Only plain_parser_category type parsers are counted as leaf nodes.
101 ///////////////////////////////////////////////////////////////////////////
102 template <typename CategoryT>
106 struct leafs<plain_parser_category> {
108 template <typename ParserT, typename LeafCountT>
111 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
112 enum { value = (LeafCountT::value + 1) };
117 struct leafs<unary_parser_category> {
119 template <typename ParserT, typename LeafCountT>
122 typedef typename ParserT::subject_t subject_t;
123 typedef typename subject_t::parser_category_t subject_category_t;
125 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
126 enum { value = (leafs<subject_category_t>
127 ::template count<subject_t, LeafCountT>::value) };
132 struct leafs<action_parser_category> {
134 template <typename ParserT, typename LeafCountT>
137 typedef typename ParserT::subject_t subject_t;
138 typedef typename subject_t::parser_category_t subject_category_t;
140 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
141 enum { value = (leafs<subject_category_t>
142 ::template count<subject_t, LeafCountT>::value) };
147 struct leafs<binary_parser_category> {
149 template <typename ParserT, typename LeafCountT>
152 typedef typename ParserT::left_t left_t;
153 typedef typename ParserT::right_t right_t;
154 typedef typename left_t::parser_category_t left_category_t;
155 typedef typename right_t::parser_category_t right_category_t;
157 typedef count self_t;
159 // __BORLANDC__ == 0x0561 isn't happy with BOOST_STATIC_CONSTANT
161 leftcount = (leafs<left_category_t>
162 ::template count<left_t, LeafCountT>::value),
163 rightcount = (leafs<right_category_t>
164 ::template count<right_t, LeafCountT>::value),
165 value = (self_t::leftcount + self_t::rightcount)
172 ///////////////////////////////////////////////////////////////////////////////
173 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
175 }} // namespace boost::spirit
177 #endif // !defined(BOOST_SPIRIT_FUNDAMENTAL_IPP)