• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*==============================================================================
2     Copyright (c) 2001-2011 Hartmut Kaiser
3     Copyright (c) 2001-2011 Joel de Guzman
4     Copyright (c) 2010-2011 Bryce Lelbach
5 
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 ==============================================================================*/
9 
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>
13 
14 #include "sexpr_parser.hpp"
15 
16 int
main()17 main()
18 {
19     using boost::spirit::qi::phrase_parse;
20 
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";
25 
26     typedef std::string::const_iterator iterator_type;
27     typedef sexpr::parser<iterator_type> parser;
28     typedef sexpr::whitespace<iterator_type> space;
29 
30     parser p;
31     space ws;
32 
33     std::string str;
34     while (std::getline(std::cin, str))
35     {
36         if (str.empty() || str[0] == 'q' || str[0] == 'Q')
37             break;
38 
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);
42 
43         if (r && iter == end)
44         {
45             std::cout << "-------------------------\n";
46             std::cout << "Parsing succeeded\n";
47             std::cout << "-------------------------\n";
48         }
49         else
50         {
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";
56         }
57     }
58 
59     std::cout << "Bye... :-) \n\n";
60     return 0;
61 }
62 
63