]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/example/qi/num_list1.cpp
1 /*=============================================================================
2 Copyright (c) 2002-2010 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 ///////////////////////////////////////////////////////////////////////////////
9 // This sample demontrates a parser for a comma separated list of numbers.
12 // [ JDG May 10, 2002 ] spirit1
13 // [ JDG March 24, 2007 ] spirit2
15 ///////////////////////////////////////////////////////////////////////////////
17 #include <boost/config/warning_disable.hpp>
18 #include <boost/spirit/include/qi.hpp>
26 namespace qi
= boost::spirit::qi
;
27 namespace ascii
= boost::spirit::ascii
;
29 ///////////////////////////////////////////////////////////////////////////
30 // Our number list parser
31 ///////////////////////////////////////////////////////////////////////////
33 template <typename Iterator
>
34 bool parse_numbers(Iterator first
, Iterator last
)
37 using qi::phrase_parse
;
40 bool r
= phrase_parse(
41 first
, /*< start iterator >*/
42 last
, /*< end iterator >*/
43 double_
>> *(',' >> double_
), /*< the parser >*/
44 space
/*< the skip-parser >*/
46 if (first
!= last
) // fail if we did not get a full match
53 ////////////////////////////////////////////////////////////////////////////
55 ////////////////////////////////////////////////////////////////////////////
59 std::cout
<< "/////////////////////////////////////////////////////////\n\n";
60 std::cout
<< "\t\tA comma separated list parser for Spirit...\n\n";
61 std::cout
<< "/////////////////////////////////////////////////////////\n\n";
63 std::cout
<< "Give me a comma separated list of numbers.\n";
64 std::cout
<< "Type [q or Q] to quit\n\n";
67 while (getline(std::cin
, str
))
69 if (str
.empty() || str
[0] == 'q' || str
[0] == 'Q')
72 if (client::parse_numbers(str
.begin(), str
.end()))
74 std::cout
<< "-------------------------\n";
75 std::cout
<< "Parsing succeeded\n";
76 std::cout
<< str
<< " Parses OK: " << std::endl
;
80 std::cout
<< "-------------------------\n";
81 std::cout
<< "Parsing failed\n";
82 std::cout
<< "-------------------------\n";
86 std::cout
<< "Bye... :-) \n\n";