File indexing completed on 2025-01-31 10:01:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #if !defined(BOOST_SPIRIT_ALTERNATIVE_HPP)
0011 #define BOOST_SPIRIT_ALTERNATIVE_HPP
0012
0013 #include <boost/spirit/home/classic/namespace.hpp>
0014 #include <boost/spirit/home/classic/core/parser.hpp>
0015 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
0016 #include <boost/spirit/home/classic/core/composite/composite.hpp>
0017 #include <boost/spirit/home/classic/meta/as_parser.hpp>
0018
0019 namespace boost { namespace spirit {
0020
0021 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 struct alternative_parser_gen;
0041
0042 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0043 #pragma warning(push)
0044 #pragma warning(disable:4512)
0045 #endif
0046
0047 template <typename A, typename B>
0048 struct alternative
0049 : public binary<A, B, parser<alternative<A, B> > >
0050 {
0051 typedef alternative<A, B> self_t;
0052 typedef binary_parser_category parser_category_t;
0053 typedef alternative_parser_gen parser_generator_t;
0054 typedef binary<A, B, parser<self_t> > base_t;
0055
0056 alternative(A const& a, B const& b)
0057 : base_t(a, b) {}
0058
0059 template <typename ScannerT>
0060 typename parser_result<self_t, ScannerT>::type
0061 parse(ScannerT const& scan) const
0062 {
0063 typedef typename parser_result<self_t, ScannerT>::type result_t;
0064 typedef typename ScannerT::iterator_t iterator_t;
0065 {
0066 iterator_t save = scan.first;
0067 if (result_t hit = this->left().parse(scan))
0068 return hit;
0069 scan.first = save;
0070 }
0071 return this->right().parse(scan);
0072 }
0073 };
0074
0075 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
0076 #pragma warning(pop)
0077 #endif
0078
0079 struct alternative_parser_gen
0080 {
0081 template <typename A, typename B>
0082 struct result
0083 {
0084 typedef
0085 alternative<
0086 typename as_parser<A>::type
0087 , typename as_parser<B>::type
0088 >
0089 type;
0090 };
0091
0092 template <typename A, typename B>
0093 static alternative<
0094 typename as_parser<A>::type
0095 , typename as_parser<B>::type
0096 >
0097 generate(A const& a, B const& b)
0098 {
0099 return alternative<BOOST_DEDUCED_TYPENAME as_parser<A>::type,
0100 BOOST_DEDUCED_TYPENAME as_parser<B>::type>
0101 (as_parser<A>::convert(a), as_parser<B>::convert(b));
0102 }
0103 };
0104
0105 template <typename A, typename B>
0106 alternative<A, B>
0107 operator|(parser<A> const& a, parser<B> const& b);
0108
0109 template <typename A>
0110 alternative<A, chlit<char> >
0111 operator|(parser<A> const& a, char b);
0112
0113 template <typename B>
0114 alternative<chlit<char>, B>
0115 operator|(char a, parser<B> const& b);
0116
0117 template <typename A>
0118 alternative<A, strlit<char const*> >
0119 operator|(parser<A> const& a, char const* b);
0120
0121 template <typename B>
0122 alternative<strlit<char const*>, B>
0123 operator|(char const* a, parser<B> const& b);
0124
0125 template <typename A>
0126 alternative<A, chlit<wchar_t> >
0127 operator|(parser<A> const& a, wchar_t b);
0128
0129 template <typename B>
0130 alternative<chlit<wchar_t>, B>
0131 operator|(wchar_t a, parser<B> const& b);
0132
0133 template <typename A>
0134 alternative<A, strlit<wchar_t const*> >
0135 operator|(parser<A> const& a, wchar_t const* b);
0136
0137 template <typename B>
0138 alternative<strlit<wchar_t const*>, B>
0139 operator|(wchar_t const* a, parser<B> const& b);
0140
0141 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0142
0143 }}
0144
0145 #endif
0146
0147 #include <boost/spirit/home/classic/core/composite/impl/alternative.ipp>