multi_pass_compile_tests.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*=============================================================================
  2. Copyright (c) 2004 Hartmut Kaiser
  3. http://spirit.sourceforge.net/
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. // This is a compile only test for verifying, whether the multi_pass<>
  9. // iterator works ok with an input iterator, which returns a value_type and not
  10. // a reference from its dereferencing operator.
  11. #include <cstdio>
  12. #include <fstream>
  13. #include <iterator>
  14. #include <boost/spirit/include/classic_core.hpp>
  15. #include <boost/spirit/include/classic_multi_pass.hpp>
  16. using namespace BOOST_SPIRIT_CLASSIC_NS;
  17. using namespace std;
  18. int main ()
  19. {
  20. // create a sample file
  21. {
  22. ofstream out("./input_file.txt");
  23. out << 1.0 << "," << 2.0;
  24. }
  25. int result = 0;
  26. // read in the values from the sample file
  27. {
  28. ifstream in("./input_file.txt"); // we get our input from this file
  29. typedef char char_t;
  30. typedef multi_pass<istreambuf_iterator<char_t> > iterator_t;
  31. typedef skip_parser_iteration_policy<space_parser> it_policy_t;
  32. typedef scanner_policies<it_policy_t> scan_policies_t;
  33. typedef scanner<iterator_t, scan_policies_t> scanner_t;
  34. typedef rule<scanner_t> rule_t;
  35. it_policy_t iter_policy(space_p);
  36. scan_policies_t policies(iter_policy);
  37. iterator_t first(make_multi_pass(std::istreambuf_iterator<char_t>(in)));
  38. scanner_t scan(first, make_multi_pass(std::istreambuf_iterator<char_t>()),
  39. policies);
  40. rule_t n_list = real_p >> *(',' >> real_p);
  41. match<> m = n_list.parse(scan);
  42. result = !m ? 1 : 0;
  43. }
  44. std::remove("./input_file.txt");
  45. return result;
  46. }