]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/repository/example/qi/distinct.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / repository / example / qi / distinct.cpp
1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 // The purpose of this example is to demonstrate different use cases for the
7 // distinct parser.
8
9 #include <iostream>
10 #include <string>
11 #include <vector>
12
13 //[qi_distinct_includes
14 #include <boost/spirit/include/qi.hpp>
15 #include <boost/spirit/repository/include/qi_distinct.hpp>
16 //]
17
18 //[qi_distinct_namespace
19 using namespace boost::spirit;
20 using namespace boost::spirit::ascii;
21 using boost::spirit::repository::distinct;
22 //]
23
24 int main()
25 {
26 //[qi_distinct_description_ident
27 {
28 std::string str("description ident");
29 std::string::iterator first(str.begin());
30 bool r = qi::phrase_parse(first, str.end()
31 , distinct(alnum | '_')["description"] >> -lit("--") >> +(alnum | '_')
32 , space);
33 BOOST_ASSERT(r && first == str.end());
34 }
35 //]
36
37 //[qi_distinct_description__ident
38 {
39 std::string str("description--ident");
40 std::string::iterator first(str.begin());
41 bool r = qi::phrase_parse(first, str.end()
42 , distinct(alnum | '_')["description"] >> -lit("--") >> +(alnum | '_')
43 , space);
44 BOOST_ASSERT(r && first == str.end());
45 }
46 //]
47
48 //[qi_distinct_description_ident_error
49 {
50 std::string str("description-ident");
51 std::string::iterator first(str.begin());
52 bool r = qi::phrase_parse(first, str.end()
53 , distinct(alnum | '_')["description"] >> -lit("--") >> +(alnum | '_')
54 , space);
55 BOOST_ASSERT(!r && first == str.begin());
56 }
57 //]
58
59 return 0;
60 }