| 1 | // Copyright (c) 2012 Louis Dionne |
|---|---|
| 2 | // Copyright (c) 2001-2012 Hartmut Kaiser |
| 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/spirit/include/qi.hpp> |
| 8 | |
| 9 | #include <boost/core/lightweight_test.hpp> |
| 10 | #include <iostream> |
| 11 | #include <string> |
| 12 | |
| 13 | struct MyInt |
| 14 | { |
| 15 | int i_; |
| 16 | |
| 17 | template <typename Istream> |
| 18 | friend Istream operator>>(Istream& is, MyInt& self) |
| 19 | { |
| 20 | is >> self.i_; |
| 21 | return is; |
| 22 | } |
| 23 | }; |
| 24 | |
| 25 | int main() |
| 26 | { |
| 27 | using namespace boost::spirit::qi; |
| 28 | typedef std::string::const_iterator Iterator; |
| 29 | |
| 30 | std::string input = "1"; |
| 31 | Iterator first(input.begin()), last(input.end()); |
| 32 | rule<Iterator, int()> my_int = stream_parser<char, MyInt>(); |
| 33 | BOOST_TEST(parse(first, last, my_int)); |
| 34 | BOOST_TEST(first == last); |
| 35 | |
| 36 | return boost::report_errors(); |
| 37 | } |
| 38 | |
| 39 |
