source: NonGTP/Boost/boost/spirit/utility/impl/lists.ipp @ 857

Revision 857, 5.7 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 2002-2003 Hartmut Kaiser
3    http://spirit.sourceforge.net/
4
5    Use, modification and distribution is subject to the Boost Software
6    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7    http://www.boost.org/LICENSE_1_0.txt)
8=============================================================================*/
9#ifndef BOOST_SPIRIT_LISTS_IPP
10#define BOOST_SPIRIT_LISTS_IPP
11
12///////////////////////////////////////////////////////////////////////////////
13#include <boost/spirit/meta/refactoring.hpp>
14
15///////////////////////////////////////////////////////////////////////////////
16namespace boost { namespace spirit {
17
18///////////////////////////////////////////////////////////////////////////////
19//
20//  list_parser_type class implementation
21//
22///////////////////////////////////////////////////////////////////////////////
23struct no_list_endtoken { typedef no_list_endtoken embed_t; };
24
25namespace impl {
26
27///////////////////////////////////////////////////////////////////////////////
28//
29//  Refactor the original list item parser
30//
31///////////////////////////////////////////////////////////////////////////////
32
33    //  match list with 'extended' syntax
34    template <typename EndT>
35    struct select_list_parse_refactor {
36
37        template <
38            typename ParserT, typename ScannerT,
39            typename ItemT, typename DelimT
40        >
41        static typename parser_result<ParserT, ScannerT>::type
42        parse(ScannerT const& scan, ParserT const& /*p*/,
43            ItemT const &item, DelimT const &delim, EndT const &end)
44        {
45            typedef refactor_action_gen<refactor_unary_gen<> > refactor_t;
46            const refactor_t refactor_item_d = refactor_t(refactor_unary_d);
47
48            return (
49                    refactor_item_d[item - (end | delim)]
50                >> *(delim >> refactor_item_d[item - (end | delim)])
51                >> !(delim >> end)
52            ).parse(scan);
53        }
54    };
55
56    //  match list with 'normal' syntax (without an 'end' parser)
57    template <>
58    struct select_list_parse_refactor<no_list_endtoken> {
59
60        template <
61            typename ParserT, typename ScannerT,
62            typename ItemT, typename DelimT
63        >
64        static typename parser_result<ParserT, ScannerT>::type
65        parse(ScannerT const& scan, ParserT const& /*p*/,
66            ItemT const &item, DelimT const &delim, no_list_endtoken const&)
67        {
68            typedef refactor_action_gen<refactor_unary_gen<> > refactor_t;
69            const refactor_t refactor_item_d = refactor_t(refactor_unary_d);
70
71            return (
72                    refactor_item_d[item - delim]
73                >> *(delim >> refactor_item_d[item - delim])
74            ).parse(scan);
75        }
76    };
77
78///////////////////////////////////////////////////////////////////////////////
79//
80//  Do not refactor the original list item parser.
81//
82///////////////////////////////////////////////////////////////////////////////
83
84    //  match list with 'extended' syntax
85    template <typename EndT>
86    struct select_list_parse_no_refactor {
87
88        template <
89            typename ParserT, typename ScannerT,
90            typename ItemT, typename DelimT
91        >
92        static typename parser_result<ParserT, ScannerT>::type
93        parse(ScannerT const& scan, ParserT const& /*p*/,
94            ItemT const &item, DelimT const &delim, EndT const &end)
95        {
96            return (
97                    (item - (end | delim))
98                >> *(delim >> (item - (end | delim)))
99                >> !(delim >> end)
100            ).parse(scan);
101        }
102    };
103
104    //  match list with 'normal' syntax (without an 'end' parser)
105    template <>
106    struct select_list_parse_no_refactor<no_list_endtoken> {
107
108        template <
109            typename ParserT, typename ScannerT,
110            typename ItemT, typename DelimT
111        >
112        static typename parser_result<ParserT, ScannerT>::type
113        parse(ScannerT const& scan, ParserT const& /*p*/,
114            ItemT const &item, DelimT const &delim, no_list_endtoken const&)
115        {
116            return (
117                    (item - delim)
118                >> *(delim >> (item - delim))
119            ).parse(scan);
120        }
121    };
122
123    // the refactoring is handled by the refactoring parsers, so here there
124    // is no need to pay attention to these issues.
125
126    template <typename CategoryT>
127    struct list_parser_type {
128
129        template <
130            typename ParserT, typename ScannerT,
131            typename ItemT, typename DelimT, typename EndT
132        >
133        static typename parser_result<ParserT, ScannerT>::type
134        parse(ScannerT const& scan, ParserT const& p,
135              ItemT const &item, DelimT const &delim, EndT const &end)
136        {
137            return select_list_parse_refactor<EndT>::
138                parse(scan, p, item, delim, end);
139        }
140    };
141
142    template <>
143    struct list_parser_type<plain_parser_category> {
144
145        template <
146            typename ParserT, typename ScannerT,
147            typename ItemT, typename DelimT, typename EndT
148        >
149        static typename parser_result<ParserT, ScannerT>::type
150        parse(ScannerT const& scan, ParserT const& p,
151              ItemT const &item, DelimT const &delim, EndT const &end)
152        {
153            return select_list_parse_no_refactor<EndT>::
154                parse(scan, p, item, delim, end);
155        }
156    };
157
158}   // namespace impl
159
160///////////////////////////////////////////////////////////////////////////////
161}} // namespace boost::spirit
162
163#endif
164
Note: See TracBrowser for help on using the repository browser.