| 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/detail/lightweight_test.hpp>
|
|---|
| 8 | #include <boost/spirit/include/qi_operator.hpp>
|
|---|
| 9 | #include <boost/spirit/include/qi_char.hpp>
|
|---|
| 10 | #include <boost/spirit/include/qi_string.hpp>
|
|---|
| 11 | #include <boost/spirit/include/qi_numeric.hpp>
|
|---|
| 12 | #include <boost/spirit/include/qi_nonterminal.hpp>
|
|---|
| 13 | #include <boost/spirit/include/qi_action.hpp>
|
|---|
| 14 | #include <boost/spirit/include/phoenix_core.hpp>
|
|---|
| 15 | #include <boost/spirit/include/phoenix_function.hpp>
|
|---|
| 16 | #include <boost/spirit/include/phoenix_operator.hpp>
|
|---|
| 17 |
|
|---|
| 18 | #include <string>
|
|---|
| 19 | #include <iostream>
|
|---|
| 20 | #include "test.hpp"
|
|---|
| 21 |
|
|---|
| 22 | using spirit_test::test;
|
|---|
| 23 | using spirit_test::test_attr;
|
|---|
| 24 |
|
|---|
| 25 | using boost::spirit::int_;
|
|---|
| 26 | using boost::spirit::qi::grammar;
|
|---|
| 27 | using boost::spirit::qi::rule;
|
|---|
| 28 |
|
|---|
| 29 | struct error_handler
|
|---|
| 30 | {
|
|---|
| 31 | template <typename>
|
|---|
| 32 | struct result { typedef void type; };
|
|---|
| 33 |
|
|---|
| 34 | template<typename What>
|
|---|
| 35 | void operator()(What const& what) const
|
|---|
| 36 | {
|
|---|
| 37 | std::wcout << L"What: " << what << std::endl;
|
|---|
| 38 | }
|
|---|
| 39 | };
|
|---|
| 40 |
|
|---|
| 41 | struct parser : grammar<char const*>
|
|---|
| 42 | {
|
|---|
| 43 | parser() : base_type(start)
|
|---|
| 44 | {
|
|---|
| 45 | typedef boost::phoenix::function<error_handler> error_handler_function;
|
|---|
| 46 | using boost::spirit::qi::_4;
|
|---|
| 47 | using boost::spirit::qi::fail;
|
|---|
| 48 | using boost::spirit::qi::on_error;
|
|---|
| 49 |
|
|---|
| 50 | start = int_;
|
|---|
| 51 |
|
|---|
| 52 | on_error<fail>(start,
|
|---|
| 53 | error_handler_function(error_handler())
|
|---|
| 54 | (_4));
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | rule<char const*> start;
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | int
|
|---|
| 61 | main()
|
|---|
| 62 | {
|
|---|
| 63 | {
|
|---|
| 64 | parser p;
|
|---|
| 65 | BOOST_TEST(test("123", p));
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | return boost::report_errors();
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|