source: NonGTP/Boost/boost/spirit/core/composite/sequence.hpp @ 857

Revision 857, 4.2 KB checked in by igarcia, 19 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 1998-2003 Joel de Guzman
3    Copyright (c) 2001 Daniel Nuffer
4    Copyright (c) 2002 Hartmut Kaiser
5    http://spirit.sourceforge.net/
6
7    Use, modification and distribution is subject to the Boost Software
8    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9    http://www.boost.org/LICENSE_1_0.txt)
10=============================================================================*/
11#if !defined(BOOST_SPIRIT_SEQUENCE_HPP)
12#define BOOST_SPIRIT_SEQUENCE_HPP
13
14#include <boost/spirit/core/parser.hpp>
15#include <boost/spirit/core/primitives/primitives.hpp>
16#include <boost/spirit/core/composite/composite.hpp>
17#include <boost/spirit/meta/as_parser.hpp>
18
19namespace boost { namespace spirit {
20
21    ///////////////////////////////////////////////////////////////////////////
22    //
23    //  sequence class
24    //
25    //      Handles expressions of the form:
26    //
27    //          a >> b
28    //
29    //      where a and b are parsers. The expression returns a composite
30    //      parser that matches a and b in sequence. One (not both) of the
31    //      operands may be a literal char, wchar_t or a primitive string
32    //      char const*, wchar_t const*.
33    //
34    //////////////////////////////////////////////////////////////////////////
35    struct sequence_parser_gen;
36   
37    template <typename A, typename B>
38    struct sequence : public binary<A, B, parser<sequence<A, B> > >
39    {
40        typedef sequence<A, B>                  self_t;
41        typedef binary_parser_category          parser_category_t;
42        typedef sequence_parser_gen             parser_generator_t;
43        typedef binary<A, B, parser<self_t> >   base_t;
44   
45        sequence(A const& a, B const& b)
46        : base_t(a, b) {}
47   
48        template <typename ScannerT>
49        typename parser_result<self_t, ScannerT>::type
50        parse(ScannerT const& scan) const
51        {
52            typedef typename parser_result<self_t, ScannerT>::type result_t;
53            if (result_t ma = this->left().parse(scan))
54                if (result_t mb = this->right().parse(scan))
55                {
56                    scan.concat_match(ma, mb);
57                    return ma;
58                }
59            return scan.no_match();
60        }
61    };
62   
63    struct sequence_parser_gen
64    {
65        template <typename A, typename B>
66        struct result
67        {
68            typedef
69                sequence<
70                    typename as_parser<A>::type
71                  , typename as_parser<B>::type
72                >
73            type;
74        };
75   
76        template <typename A, typename B>
77        static sequence<
78            typename as_parser<A>::type
79          , typename as_parser<B>::type
80        >
81        generate(A const& a, B const& b)
82        {
83            return sequence<BOOST_DEDUCED_TYPENAME as_parser<A>::type,
84                BOOST_DEDUCED_TYPENAME as_parser<B>::type>
85                    (as_parser<A>::convert(a), as_parser<B>::convert(b));
86        }
87    };
88   
89    template <typename A, typename B>
90    sequence<A, B>
91    operator>>(parser<A> const& a, parser<B> const& b);
92   
93    template <typename A>
94    sequence<A, chlit<char> >
95    operator>>(parser<A> const& a, char b);
96   
97    template <typename B>
98    sequence<chlit<char>, B>
99    operator>>(char a, parser<B> const& b);
100   
101    template <typename A>
102    sequence<A, strlit<char const*> >
103    operator>>(parser<A> const& a, char const* b);
104   
105    template <typename B>
106    sequence<strlit<char const*>, B>
107    operator>>(char const* a, parser<B> const& b);
108   
109    template <typename A>
110    sequence<A, chlit<wchar_t> >
111    operator>>(parser<A> const& a, wchar_t b);
112   
113    template <typename B>
114    sequence<chlit<wchar_t>, B>
115    operator>>(wchar_t a, parser<B> const& b);
116   
117    template <typename A>
118    sequence<A, strlit<wchar_t const*> >
119    operator>>(parser<A> const& a, wchar_t const* b);
120   
121    template <typename B>
122    sequence<strlit<wchar_t const*>, B>
123    operator>>(wchar_t const* a, parser<B> const& b);
124   
125}} // namespace boost::spirit
126
127#endif
128
129#include <boost/spirit/core/composite/impl/sequence.ipp>
Note: See TracBrowser for help on using the repository browser.