File indexing completed on 2025-01-31 10:01:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #if !defined(BOOST_SPIRIT_OPTIONAL_HPP)
0011 #define BOOST_SPIRIT_OPTIONAL_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 struct optional_parser_gen;
0036
0037 template <typename S>
0038 struct optional
0039 : public unary<S, parser<optional<S> > >
0040 {
0041 typedef optional<S> self_t;
0042 typedef unary_parser_category parser_category_t;
0043 typedef optional_parser_gen parser_generator_t;
0044 typedef unary<S, parser<self_t> > base_t;
0045
0046 optional(S const& a)
0047 : base_t(a) {}
0048
0049 template <typename ScannerT>
0050 typename parser_result<self_t, ScannerT>::type
0051 parse(ScannerT const& scan) const
0052 {
0053 typedef typename parser_result<self_t, ScannerT>::type result_t;
0054 typedef typename ScannerT::iterator_t iterator_t;
0055 iterator_t save = scan.first;
0056 if (result_t r = this->subject().parse(scan))
0057 {
0058 return r;
0059 }
0060 else
0061 {
0062 scan.first = save;
0063 return scan.empty_match();
0064 }
0065 }
0066 };
0067
0068 struct optional_parser_gen
0069 {
0070 template <typename S>
0071 struct result
0072 {
0073 typedef optional<S> type;
0074 };
0075
0076 template <typename S>
0077 static optional<S>
0078 generate(parser<S> const& a)
0079 {
0080 return optional<S>(a.derived());
0081 }
0082 };
0083
0084 template <typename S>
0085 optional<S>
0086 operator!(parser<S> const& a);
0087
0088 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0089
0090 }}
0091
0092 #endif
0093
0094 #include <boost/spirit/home/classic/core/composite/impl/optional.ipp>