tstspirit.cc
Go to the documentation of this file.
1 // cwchessboard -- A C++ chessboard tool set
2 //
3 //! @file tstspirit.cc A test application to test using boost::spirit::classic.
4 //
5 // Copyright (C) 2010, by
6 //
7 // Carlo Wood, Run on IRC <carlo@alinoe.com>
8 // RSA-1024 0x624ACAD5 1997-01-26 Sign & Encrypt
9 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6 F6 F6 55 DD 1C DC FF 61
10 //
11 // This program is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 2 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, see <http://www.gnu.org/licenses/>.
23 
24 #define BOOST_SPIRIT_DEBUG
25 
26 #include "sys.h"
27 #include <iostream>
28 #include <fstream>
29 #include <boost/spirit/include/classic_core.hpp>
30 #include <boost/spirit/include/classic_multi_pass.hpp>
31 #include "PgnGrammar.h"
32 #include "debug.h"
33 
34 namespace {
35 
36 typedef char char_t;
37 //typedef boost::spirit::classic::multi_pass<std::istreambuf_iterator<char_t> > iterator_t;
38 struct MY_ITERATOR {
39  public:
40  typedef std::input_iterator_tag iterator_category;
41  typedef char value_type;
42  typedef ptrdiff_t difference_type;
43  typedef char* pointer;
44  typedef char& reference;
45 
46  friend bool operator==(MY_ITERATOR const& a, MY_ITERATOR const& b) { return false; }
47  friend bool operator!=(MY_ITERATOR const& a, MY_ITERATOR const& b) { return true; }
48  value_type& operator*(void) { return M_dummy; }
49  value_type const& operator*(void) const { return M_dummy; }
50  MY_ITERATOR& operator++(void) { return* this; }
51 
52  MY_ITERATOR(void) : M_dummy('?') { }
53  MY_ITERATOR(MY_ITERATOR const& iter) : M_dummy(iter.M_dummy) { }
54  MY_ITERATOR& operator=(MY_ITERATOR const& iter) { M_dummy = iter.M_dummy; }
55 
56  private:
57  char M_dummy;
58 };
59 
60 typedef MY_ITERATOR iterator_t;
61 
62 typedef boost::spirit::classic::skip_parser_iteration_policy<boost::spirit::classic::space_parser> iter_policy_t;
63 typedef boost::spirit::classic::scanner_policies<iter_policy_t> scanner_policies_t;
64 typedef boost::spirit::classic::scanner<iterator_t, scanner_policies_t> scanner_t;
65 
66 iter_policy_t iter_policy(boost::spirit::classic::space_p);
67 scanner_policies_t policies(iter_policy);
68 
69 } // namespace* anonymous*
70 
71 int main(int argc, char* argv[])
72 {
73  Debug(NAMESPACE_DEBUG::init());
74 
75  for (int i = 1; i < argc; ++i)
76  {
77  if (std::string(argv[i]) == "/home/carlo/chess/freechess.ladder/0018.pgn")
78  continue;
79  std::cout << "Trying to parse file \"" << argv[i] << "\"." << std::endl;
80  std::ifstream in(argv[i]);
81  iterator_t first; // FIXME (boost::spirit::classic::make_multi_pass(std::istreambuf_iterator<char_t>(in)));
82  iterator_t /*const*/ last; // FIXME (boost::spirit::classic::make_multi_pass(std::istreambuf_iterator<char_t>()));
83 
85  boost::spirit::classic::parse_info<iterator_t> info = boost::spirit::classic::parse(first, last, g);
86  if (!info.hit)
87  {
88  std::cout << "Failure to parse anything." << std::endl;
89  return 1;
90  }
91  else
92  std::cout << info.length << " characters have been parsed successfully." << std::endl;
93  }
94 }
This file contains the declaration of class PgnGrammar.

Copyright © 2006 - 2010 Carlo Wood.  All rights reserved.