test_attr.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_PP_IS_ITERATING)
  6. #if !defined(BOOST_SPIRIT_QI_TEST_ATTR_APR_23_2009_0605PM)
  7. #define BOOST_SPIRIT_QI_TEST_ATTR_APR_23_2009_0605PM
  8. #include <cstring>
  9. #include <string>
  10. #include <iterator>
  11. #include <iostream>
  12. #include <typeinfo>
  13. #include <boost/spirit/include/qi_parse.hpp>
  14. #include <boost/spirit/include/qi_what.hpp>
  15. #include <boost/preprocessor/cat.hpp>
  16. #include <boost/preprocessor/iterate.hpp>
  17. #include <boost/preprocessor/repetition/repeat.hpp>
  18. #include <boost/preprocessor/repetition/enum_params.hpp>
  19. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  20. #define BOOST_PP_FILENAME_1 "test_attr.hpp"
  21. #define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
  22. #include BOOST_PP_ITERATE()
  23. #endif
  24. ///////////////////////////////////////////////////////////////////////////////
  25. //
  26. // Preprocessor vertical repetition code
  27. //
  28. ///////////////////////////////////////////////////////////////////////////////
  29. #else // defined(BOOST_PP_IS_ITERATING)
  30. #define N BOOST_PP_ITERATION()
  31. #define DEFINE_ATTRIBUTE(z, n, _) \
  32. BOOST_PP_CAT(A, n) BOOST_PP_CAT(attr, n) = BOOST_PP_CAT(A, n)();
  33. #define COMPARE_ATTRIBUTE(z, n, _) \
  34. BOOST_PP_CAT(attr, n) == BOOST_PP_CAT(val, n) &&
  35. namespace spirit_test
  36. {
  37. ///////////////////////////////////////////////////////////////////////////
  38. template <typename Char, typename Parser
  39. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  40. inline bool test(Char const *in, Parser const& p
  41. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
  42. {
  43. namespace qi = boost::spirit::qi;
  44. // we don't care about the result of the "what" function.
  45. // we only care that all parsers have it:
  46. qi::what(p);
  47. Char const* last = in;
  48. while (*last)
  49. last++;
  50. BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
  51. bool result = qi::parse(in, last, p, BOOST_PP_ENUM_PARAMS(N, attr));
  52. return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
  53. }
  54. ///////////////////////////////////////////////////////////////////////////
  55. template <typename Char, typename Parser, typename Skipper
  56. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  57. inline bool test_skipped(Char const *in, Parser const& p
  58. , Skipper const& skipper, BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
  59. {
  60. namespace qi = boost::spirit::qi;
  61. // we don't care about the result of the "what" function.
  62. // we only care that all parsers have it:
  63. qi::what(p);
  64. Char const* last = in;
  65. while (*last)
  66. last++;
  67. BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
  68. bool result = qi::phrase_parse(in, last, p, skipper
  69. , BOOST_PP_ENUM_PARAMS(N, attr));
  70. return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
  71. }
  72. ///////////////////////////////////////////////////////////////////////////
  73. template <typename Char, typename Parser, typename Skipper
  74. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  75. inline bool test_postskipped(Char const *in, Parser const& p
  76. , Skipper const& skipper
  77. , BOOST_SCOPED_ENUM(boost::spirit::qi::skip_flag) post_skip
  78. , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
  79. {
  80. namespace qi = boost::spirit::qi;
  81. // we don't care about the result of the "what" function.
  82. // we only care that all parsers have it:
  83. qi::what(p);
  84. Char const* last = in;
  85. while (*last)
  86. last++;
  87. BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
  88. bool result = qi::phrase_parse(in, last, p, skipper, post_skip
  89. , BOOST_PP_ENUM_PARAMS(N, attr));
  90. return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
  91. }
  92. } // namespace spirit_test
  93. #undef COMPARE_ATTRIBUTE
  94. #undef DEFINE_ATTRIBUTE
  95. #undef N
  96. #endif