]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2001-2014 Joel de Guzman | |
3 | Copyright (c) 2001-2011 Hartmut Kaiser | |
4 | ||
5 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | =============================================================================*/ | |
11fdf7f2 TL |
8 | #if !defined(BOOST_SPIRIT_X3_LIST_MARCH_24_2007_1031AM) |
9 | #define BOOST_SPIRIT_X3_LIST_MARCH_24_2007_1031AM | |
7c673cae FG |
10 | |
11 | #include <boost/spirit/home/x3/core/parser.hpp> | |
12 | #include <boost/spirit/home/x3/support/traits/container_traits.hpp> | |
13 | #include <boost/spirit/home/x3/support/traits/attribute_of.hpp> | |
14 | #include <boost/spirit/home/x3/core/detail/parse_into_container.hpp> | |
15 | ||
16 | namespace boost { namespace spirit { namespace x3 | |
17 | { | |
18 | template <typename Left, typename Right> | |
19 | struct list : binary_parser<Left, Right, list<Left, Right>> | |
20 | { | |
21 | typedef binary_parser<Left, Right, list<Left, Right>> base_type; | |
22 | static bool const handles_container = true; | |
23 | static bool const has_attribute = true; | |
24 | ||
25 | list(Left const& left, Right const& right) | |
26 | : base_type(left, right) {} | |
27 | ||
28 | template <typename Iterator, typename Context | |
29 | , typename RContext, typename Attribute> | |
30 | bool parse(Iterator& first, Iterator const& last | |
31 | , Context const& context, RContext& rcontext, Attribute& attr) const | |
32 | { | |
33 | // in order to succeed we need to match at least one element | |
34 | if (!detail::parse_into_container( | |
35 | this->left, first, last, context, rcontext, attr)) | |
36 | return false; | |
37 | ||
38 | Iterator save = first; | |
39 | while (this->right.parse(first, last, context, rcontext, unused) | |
40 | && detail::parse_into_container( | |
41 | this->left, first, last, context, rcontext, attr)) | |
42 | { | |
43 | save = first; | |
44 | } | |
45 | ||
46 | first = save; | |
47 | return true; | |
48 | } | |
49 | }; | |
50 | ||
51 | template <typename Left, typename Right> | |
52 | inline list< | |
53 | typename extension::as_parser<Left>::value_type | |
54 | , typename extension::as_parser<Right>::value_type> | |
55 | operator%(Left const& left, Right const& right) | |
56 | { | |
57 | return { as_parser(left), as_parser(right) }; | |
58 | } | |
59 | }}} | |
60 | ||
61 | namespace boost { namespace spirit { namespace x3 { namespace traits | |
62 | { | |
63 | template <typename Left, typename Right, typename Context> | |
64 | struct attribute_of<x3::list<Left, Right>, Context> | |
65 | : traits::build_container< | |
66 | typename attribute_of<Left, Context>::type> {}; | |
67 | }}}} | |
68 | ||
69 | #endif |