#include #include #include /////////////////////////////////////////////////////////////////////////////// using namespace BOOST_SPIRIT_CLASSIC_NS; //////////////////////////////////////////////////////////////////////////// // // Types // //////////////////////////////////////////////////////////////////////////// typedef char char_t; typedef file_iterator iterator_t; typedef scanner scanner_t; typedef rule rule_t; //////////////////////////////////////////////////////////////////////////// // // Actions // //////////////////////////////////////////////////////////////////////////// static bool isGoogle = false; void echoGoogle(iterator_t first, iterator_t const& last) { while (first != last) std::cout << *first++; isGoogle = true; } void echoOther(char_t c) { if (isGoogle) std::cout << c; if (c == '\n') isGoogle = false; } //////////////////////////////////////////////////////////////////////////// // // Main program // //////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { if (2 > argc) { std::cout << "Must specify a filename!\n"; return -1; } // Create a file iterator for this file iterator_t first(argv[1]); if (!first) { std::cout << "Unable to open file!\n"; return -1; } // Create an EOF iterator iterator_t last = first.make_end(); // A simple rule rule_t google = str_p("http://www.google.com")[&echoGoogle] | anychar_p[&echoOther]; // Parse parse_info info = parse( first, last, *google, space_p | eol_p ); // This really shouldn't fail... if (info.full) std::cout << "Parse succeeded!\n"; else std::cout << "Parse failed!\n"; return 0; }