8b370aa2ab5353f36d99fde3e9708f40e4ac9165
[platform/upstream/boost.git] / libs / spirit / example / qi / typeof.cpp
1 /*=============================================================================
2     Copyright (c) 2001-2010 Joel de Guzman
3
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 #include <boost/config/warning_disable.hpp>
8 #include <boost/spirit/include/qi.hpp>
9 #include <boost/typeof/typeof.hpp>
10 #include <iostream>
11 #include <string>
12
13 ///////////////////////////////////////////////////////////////////////////////
14 //  Main program
15 ///////////////////////////////////////////////////////////////////////////////
16
17 #define BOOST_SPIRIT_AUTO(domain_, name, expr)                                  \
18     typedef boost::proto::result_of::                                           \
19         deep_copy<BOOST_TYPEOF(expr)>::type name##_expr_type;                   \
20     BOOST_SPIRIT_ASSERT_MATCH(                                                  \
21         boost::spirit::domain_::domain, name##_expr_type);                      \
22     BOOST_AUTO(name, boost::proto::deep_copy(expr));                            \
23
24 int
25 main()
26 {
27     using boost::spirit::ascii::space;
28     using boost::spirit::ascii::char_;
29     using boost::spirit::qi::parse;
30     typedef std::string::const_iterator iterator_type;
31     
32     BOOST_SPIRIT_AUTO(qi, comment, "/*" >> *(char_ - "*/") >> "*/");
33
34     std::string str = "/*This is a comment*/";
35     std::string::const_iterator iter = str.begin();
36     std::string::const_iterator end = str.end();
37     bool r = parse(iter, end, comment);
38
39     if (r && iter == end)
40     {
41         std::cout << "-------------------------\n";
42         std::cout << "Parsing succeeded\n";
43         std::cout << "-------------------------\n";
44     }
45     else
46     {
47         std::string rest(iter, end);
48         std::cout << "-------------------------\n";
49         std::cout << "Parsing failed\n";
50         std::cout << "stopped at: \": " << rest << "\"\n";
51         std::cout << "-------------------------\n";
52     }
53
54     return 0;
55 }
56
57