1 /*==============================================================================
2 Copyright (c) 2001-2011 Hartmut Kaiser
3 Copyright (c) 2001-2011 Joel de Guzman
4 Copyright (c) 2010-2011 Bryce Lelbach
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file BOOST_LICENSE_1_0.rst or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
10 #include <boost/spirit/include/support_istream_iterator.hpp>
11 #include <boost/spirit/include/support_line_pos_iterator.hpp>
12 #include <boost/spirit/include/qi_parse.hpp>
14 #include "sexpr_parser.hpp"
19 using boost::spirit::qi::phrase_parse
;
21 std::cout
<< "/////////////////////////////////////////////////////////\n\n";
22 std::cout
<< "sexpr parser...\n\n";
23 std::cout
<< "/////////////////////////////////////////////////////////\n\n";
24 std::cout
<< "Type an expression... or [q or Q] to quit\n\n";
26 typedef std::string::const_iterator iterator_type
;
27 typedef sexpr::parser
<iterator_type
> parser
;
28 typedef sexpr::whitespace
<iterator_type
> space
;
34 while (std::getline(std::cin
, str
))
36 if (str
.empty() || str
[0] == 'q' || str
[0] == 'Q')
39 std::string::const_iterator iter
= str
.begin();
40 std::string::const_iterator end
= str
.end();
41 bool r
= phrase_parse(iter
, end
, p
, ws
);
45 std::cout
<< "-------------------------\n";
46 std::cout
<< "Parsing succeeded\n";
47 std::cout
<< "-------------------------\n";
51 std::string
rest(iter
, end
);
52 std::cout
<< "-------------------------\n";
53 std::cout
<< "Parsing failed\n";
54 std::cout
<< "stopped at: \": " << rest
<< "\"\n";
55 std::cout
<< "-------------------------\n";
59 std::cout
<< "Bye... :-) \n\n";