Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // width_of.hpp Chris@16: // Chris@16: // Copyright 2008 Eric Niebler. Distributed under the Boost Chris@16: // Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_WIDTH_OF_HPP_EAN_10_04_2005 Chris@16: #define BOOST_XPRESSIVE_DETAIL_STATIC_WIDTH_OF_HPP_EAN_10_04_2005 Chris@16: Chris@16: // MS compatible compilers support #pragma once Chris@101: #if defined(_MSC_VER) Chris@16: # pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace xpressive { namespace detail Chris@16: { Chris@16: template Chris@16: struct width_of; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // add_widths Chris@16: // Chris@16: template Chris@16: struct add_widths Chris@16: : mpl::size_t Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct add_widths Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct add_widths Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: template<> Chris@16: struct add_widths Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // or_widths Chris@16: // Chris@16: template Chris@16: struct or_widths Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct or_widths Chris@16: : mpl::size_t Chris@16: {}; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // width_of_terminal Chris@16: // Chris@16: template::value> Chris@16: struct width_of_terminal Chris@16: : mpl::size_t // xpressive literals Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_terminal Chris@16: : unknown_width // unknown literals (eg, basic_string, basic_regex, etc.) Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_terminal Chris@16: : mpl::size_t<1> // char literals Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_terminal Chris@16: : mpl::size_t<1> // char literals Chris@16: {}; Chris@16: Chris@16: template<> Chris@16: struct width_of_terminal Chris@16: : mpl::size_t<1> // char literals Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_terminal Chris@16: : mpl::size_t::value> // string literals Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_terminal Chris@16: : mpl::size_t::value> // string literals Chris@16: {}; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////////////// Chris@16: // width_of Chris@16: // Chris@16: template Chris@16: struct width_of Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : width_of_terminal::type, Char> Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : add_widths< Chris@16: width_of::type::proto_base_expr, Char>::value Chris@16: , width_of::type::proto_base_expr, Char>::value Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : or_widths< Chris@16: width_of::type::proto_base_expr, Char>::value Chris@16: , width_of::type::proto_base_expr, Char>::value Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_assign Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_assign Chris@16: : width_of::type::proto_base_expr, Char> Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_assign Chris@16: : mpl::size_t<1> Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_assign > Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: // either (s1 = ...) or (a1 = ...) or (set = ...) Chris@16: template Chris@16: struct width_of Chris@16: : width_of_assign< Chris@16: Expr Chris@16: , Char Chris@16: , typename proto::result_of::value< Chris@16: typename remove_reference::type::proto_base_expr Chris@16: >::type Chris@16: > Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : width_of::type::proto_base_expr, Char> Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : mpl::size_t<0> Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : mpl::size_t<0> Chris@16: {}; Chris@16: Chris@16: // keep() is used to turn off backtracking, so they should only be used Chris@16: // for things that are variable-width (eg. quantified) Chris@16: template Chris@16: struct width_of Chris@16: : unknown_width Chris@16: { Chris@16: // TODO: keep() now has a second meaning: execute actions immediately. Chris@16: // In that sense, it is perfectly reasonable to put a fixed-width Chris@16: // sub-expression in a keep. Can fixed-width keep() sub-expressions Chris@16: // use the simple_repeat_matcher? Chris@16: }; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of > Chris@16: : unknown_width Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of > Chris@16: : mpl::if_c< Chris@16: mpl::equal_to::type::proto_base_expr, Char> >::value Chris@16: , unknown_width Chris@16: , mpl::times< Chris@16: width_of::type::proto_base_expr, Char> Chris@16: , mpl::size_t Chris@16: > Chris@16: >::type Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : width_of::type::proto_base_expr, Char> Chris@16: {}; Chris@16: Chris@16: // when complementing a set or an assertion, the width is that of the set (1) or the assertion (0) Chris@16: template Chris@16: struct width_of Chris@16: : width_of::type::proto_base_expr, Char> Chris@16: {}; Chris@16: Chris@16: // The comma is used in list-initialized sets, and the width of sets are 1 Chris@16: template Chris@16: struct width_of Chris@16: : mpl::size_t<1> Chris@16: {}; Chris@16: Chris@16: // The subscript operator[] is used for sets, as in set['a' | range('b','h')], Chris@16: // or for actions as in (any >> expr)[ action ] Chris@16: template Chris@16: struct width_of_subscript Chris@16: : width_of Chris@16: {}; Chris@16: Chris@16: template Chris@16: struct width_of_subscript Chris@16: : mpl::size_t<1> Chris@16: { Chris@16: // If Left is "set" then make sure that Right has a width_of 1 Chris@16: BOOST_MPL_ASSERT_RELATION( Chris@16: 1 Chris@16: , == Chris@16: , (width_of::type::proto_base_expr, Char>::value)); Chris@16: }; Chris@16: Chris@16: template Chris@16: struct width_of Chris@16: : width_of_subscript::type::proto_base_expr> Chris@16: {}; Chris@16: Chris@16: }}} // namespace boost::xpressive::detail Chris@16: Chris@16: #undef UNREF Chris@16: Chris@16: #endif