Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #define BOOST_SPIRIT_DEBUG
00025
00026 #include "sys.h"
00027 #include <iostream>
00028 #include <fstream>
00029 #include <boost/spirit/include/classic_core.hpp>
00030 #include <boost/spirit/include/classic_multi_pass.hpp>
00031 #include "PgnGrammar.h"
00032 #include "debug.h"
00033
00034 namespace {
00035
00036 typedef char char_t;
00037
00038 struct MY_ITERATOR {
00039 public:
00040 typedef std::input_iterator_tag iterator_category;
00041 typedef char value_type;
00042 typedef ptrdiff_t difference_type;
00043 typedef char* pointer;
00044 typedef char& reference;
00045
00046 friend bool operator==(MY_ITERATOR const& a, MY_ITERATOR const& b) { return false; }
00047 friend bool operator!=(MY_ITERATOR const& a, MY_ITERATOR const& b) { return true; }
00048 value_type& operator*(void) { return M_dummy; }
00049 value_type const& operator*(void) const { return M_dummy; }
00050 MY_ITERATOR& operator++(void) { return* this; }
00051
00052 MY_ITERATOR(void) : M_dummy('?') { }
00053 MY_ITERATOR(MY_ITERATOR const& iter) : M_dummy(iter.M_dummy) { }
00054 MY_ITERATOR& operator=(MY_ITERATOR const& iter) { M_dummy = iter.M_dummy; }
00055
00056 private:
00057 char M_dummy;
00058 };
00059
00060 typedef MY_ITERATOR iterator_t;
00061
00062 typedef boost::spirit::classic::skip_parser_iteration_policy<boost::spirit::classic::space_parser> iter_policy_t;
00063 typedef boost::spirit::classic::scanner_policies<iter_policy_t> scanner_policies_t;
00064 typedef boost::spirit::classic::scanner<iterator_t, scanner_policies_t> scanner_t;
00065
00066 iter_policy_t iter_policy(boost::spirit::classic::space_p);
00067 scanner_policies_t policies(iter_policy);
00068
00069 }
00070
00071 int main(int argc, char* argv[])
00072 {
00073 Debug(debug::init());
00074
00075 for (int i = 1; i < argc; ++i)
00076 {
00077 if (std::string(argv[i]) == "/home/carlo/chess/freechess.ladder/0018.pgn")
00078 continue;
00079 std::cout << "Trying to parse file \"" << argv[i] << "\"." << std::endl;
00080 std::ifstream in(argv[i]);
00081 iterator_t first;
00082 iterator_t last;
00083
00084 cwchess::pgn::grammar::PgnGrammar g;
00085 boost::spirit::classic::parse_info<iterator_t> info = boost::spirit::classic::parse(first, last, g);
00086 if (!info.hit)
00087 {
00088 std::cout << "Failure to parse anything." << std::endl;
00089 return 1;
00090 }
00091 else
00092 std::cout << info.length << " characters have been parsed successfully." << std::endl;
00093 }
00094 }