/*============================================================================= Copyright (c) 2001-2003 Joel de Guzman 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_CHSET_OPERATORS_IPP #define BOOST_SPIRIT_CHSET_OPERATORS_IPP /////////////////////////////////////////////////////////////////////////////// #include /////////////////////////////////////////////////////////////////////////////// namespace boost { namespace spirit { BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN /////////////////////////////////////////////////////////////////////////////// // // chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, chset const& b) { return chset(a) |= b; } ////////////////////////////////// template inline chset operator-(chset const& a, chset const& b) { return chset(a) -= b; } ////////////////////////////////// template inline chset operator~(chset const& a) { return chset(a).inverse(); } ////////////////////////////////// template inline chset operator&(chset const& a, chset const& b) { return chset(a) &= b; } ////////////////////////////////// template inline chset operator^(chset const& a, chset const& b) { return chset(a) ^= b; } /////////////////////////////////////////////////////////////////////////////// // // range <--> chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, range const& b) { chset a_(a); a_.set(b); return a_; } ////////////////////////////////// template inline chset operator&(chset const& a, range const& b) { chset a_(a); if(b.first != (std::numeric_limits::min)()) { a_.clear(range((std::numeric_limits::min)(), b.first - 1)); } if(b.last != (std::numeric_limits::max)()) { a_.clear(range(b.last + 1, (std::numeric_limits::max)())); } return a_; } ////////////////////////////////// template inline chset operator-(chset const& a, range const& b) { chset a_(a); a_.clear(b); return a_; } ////////////////////////////////// template inline chset operator^(chset const& a, range const& b) { return a ^ chset(b); } ////////////////////////////////// template inline chset operator|(range const& a, chset const& b) { chset b_(b); b_.set(a); return b_; } ////////////////////////////////// template inline chset operator&(range const& a, chset const& b) { chset b_(b); if(a.first != (std::numeric_limits::min)()) { b_.clear(range((std::numeric_limits::min)(), a.first - 1)); } if(a.last != (std::numeric_limits::max)()) { b_.clear(range(a.last + 1, (std::numeric_limits::max)())); } return b_; } ////////////////////////////////// template inline chset operator-(range const& a, chset const& b) { return chset(a) - b; } ////////////////////////////////// template inline chset operator^(range const& a, chset const& b) { return chset(a) ^ b; } /////////////////////////////////////////////////////////////////////////////// // // literal primitives <--> chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, CharT b) { return a | chset(b); } ////////////////////////////////// template inline chset operator&(chset const& a, CharT b) { return a & chset(b); } ////////////////////////////////// template inline chset operator-(chset const& a, CharT b) { return a - chset(b); } ////////////////////////////////// template inline chset operator^(chset const& a, CharT b) { return a ^ chset(b); } ////////////////////////////////// template inline chset operator|(CharT a, chset const& b) { return chset(a) | b; } ////////////////////////////////// template inline chset operator&(CharT a, chset const& b) { return chset(a) & b; } ////////////////////////////////// template inline chset operator-(CharT a, chset const& b) { return chset(a) - b; } ////////////////////////////////// template inline chset operator^(CharT a, chset const& b) { return chset(a) ^ b; } /////////////////////////////////////////////////////////////////////////////// // // chlit <--> chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, chlit const& b) { return a | chset(b.ch); } ////////////////////////////////// template inline chset operator&(chset const& a, chlit const& b) { return a & chset(b.ch); } ////////////////////////////////// template inline chset operator-(chset const& a, chlit const& b) { return a - chset(b.ch); } ////////////////////////////////// template inline chset operator^(chset const& a, chlit const& b) { return a ^ chset(b.ch); } ////////////////////////////////// template inline chset operator|(chlit const& a, chset const& b) { return chset(a.ch) | b; } ////////////////////////////////// template inline chset operator&(chlit const& a, chset const& b) { return chset(a.ch) & b; } ////////////////////////////////// template inline chset operator-(chlit const& a, chset const& b) { return chset(a.ch) - b; } ////////////////////////////////// template inline chset operator^(chlit const& a, chset const& b) { return chset(a.ch) ^ b; } #if BOOST_WORKAROUND(BOOST_MSVC, < 1300) /////////////////////////////////////////////////////////////////////////////// // // negated_char_parser <--> chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, negated_char_parser const& b) { return a | chset(b); } ////////////////////////////////// template inline chset operator&(chset const& a, negated_char_parser const& b) { return a & chset(b); } ////////////////////////////////// template inline chset operator-(chset const& a, negated_char_parser const& b) { return a - chset(b); } ////////////////////////////////// template inline chset operator^(chset const& a, negated_char_parser const& b) { return a ^ chset(b); } ////////////////////////////////// template inline chset operator|(negated_char_parser const& a, chset const& b) { return chset(a) | b; } ////////////////////////////////// template inline chset operator&(negated_char_parser const& a, chset const& b) { return chset(a) & b; } ////////////////////////////////// template inline chset operator-(negated_char_parser const& a, chset const& b) { return chset(a) - b; } ////////////////////////////////// template inline chset operator^(negated_char_parser const& a, chset const& b) { return chset(a) ^ b; } #else // BOOST_WORKAROUND(BOOST_MSVC, < 1300) /////////////////////////////////////////////////////////////////////////////// // // negated_char_parser <--> chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, negated_char_parser > const& b) { return a | chset(b); } ////////////////////////////////// template inline chset operator&(chset const& a, negated_char_parser > const& b) { return a & chset(b); } ////////////////////////////////// template inline chset operator-(chset const& a, negated_char_parser > const& b) { return a - chset(b); } ////////////////////////////////// template inline chset operator^(chset const& a, negated_char_parser > const& b) { return a ^ chset(b); } ////////////////////////////////// template inline chset operator|(negated_char_parser > const& a, chset const& b) { return chset(a) | b; } ////////////////////////////////// template inline chset operator&(negated_char_parser > const& a, chset const& b) { return chset(a) & b; } ////////////////////////////////// template inline chset operator-(negated_char_parser > const& a, chset const& b) { return chset(a) - b; } ////////////////////////////////// template inline chset operator^(negated_char_parser > const& a, chset const& b) { return chset(a) ^ b; } /////////////////////////////////////////////////////////////////////////////// // // negated_char_parser <--> chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, negated_char_parser > const& b) { return a | chset(b); } ////////////////////////////////// template inline chset operator&(chset const& a, negated_char_parser > const& b) { return a & chset(b); } ////////////////////////////////// template inline chset operator-(chset const& a, negated_char_parser > const& b) { return a - chset(b); } ////////////////////////////////// template inline chset operator^(chset const& a, negated_char_parser > const& b) { return a ^ chset(b); } ////////////////////////////////// template inline chset operator|(negated_char_parser > const& a, chset const& b) { return chset(a) | b; } ////////////////////////////////// template inline chset operator&(negated_char_parser > const& a, chset const& b) { return chset(a) & b; } ////////////////////////////////// template inline chset operator-(negated_char_parser > const& a, chset const& b) { return chset(a) - b; } ////////////////////////////////// template inline chset operator^(negated_char_parser > const& a, chset const& b) { return chset(a) ^ b; } #endif // BOOST_WORKAROUND(BOOST_MSVC, < 1300) /////////////////////////////////////////////////////////////////////////////// // // anychar_parser <--> chset free operators // // Where a is chset and b is a anychar_parser, and vice-versa, implements: // // a | b, a & b, a - b, a ^ b // /////////////////////////////////////////////////////////////////////////////// namespace impl { template inline BOOST_SPIRIT_CLASSIC_NS::range const& full() { static BOOST_SPIRIT_CLASSIC_NS::range full_( (std::numeric_limits::min)(), (std::numeric_limits::max)()); return full_; } template inline BOOST_SPIRIT_CLASSIC_NS::range const& empty() { static BOOST_SPIRIT_CLASSIC_NS::range empty_; return empty_; } } ////////////////////////////////// template inline chset operator|(chset const&, anychar_parser) { return chset(impl::full()); } ////////////////////////////////// template inline chset operator&(chset const& a, anychar_parser) { return a; } ////////////////////////////////// template inline chset operator-(chset const&, anychar_parser) { return chset(); } ////////////////////////////////// template inline chset operator^(chset const& a, anychar_parser) { return ~a; } ////////////////////////////////// template inline chset operator|(anychar_parser, chset const& /*b*/) { return chset(impl::full()); } ////////////////////////////////// template inline chset operator&(anychar_parser, chset const& b) { return b; } ////////////////////////////////// template inline chset operator-(anychar_parser, chset const& b) { return ~b; } ////////////////////////////////// template inline chset operator^(anychar_parser, chset const& b) { return ~b; } /////////////////////////////////////////////////////////////////////////////// // // nothing_parser <--> chset free operators implementation // /////////////////////////////////////////////////////////////////////////////// template inline chset operator|(chset const& a, nothing_parser) { return a; } ////////////////////////////////// template inline chset operator&(chset const& /*a*/, nothing_parser) { return impl::empty(); } ////////////////////////////////// template inline chset operator-(chset const& a, nothing_parser) { return a; } ////////////////////////////////// template inline chset operator^(chset const& a, nothing_parser) { return a; } ////////////////////////////////// template inline chset operator|(nothing_parser, chset const& b) { return b; } ////////////////////////////////// template inline chset operator&(nothing_parser, chset const& /*b*/) { return impl::empty(); } ////////////////////////////////// template inline chset operator-(nothing_parser, chset const& /*b*/) { return impl::empty(); } ////////////////////////////////// template inline chset operator^(nothing_parser, chset const& b) { return b; } /////////////////////////////////////////////////////////////////////////////// BOOST_SPIRIT_CLASSIC_NAMESPACE_END }} // namespace boost::spirit #endif