tokenize_and_parse_attr.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. // Copyright (c) 2001-2011 Joel de Guzman
  3. // Copyright (c) 2009 Carl Barron
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. #if !defined(BOOST_PP_IS_ITERATING)
  8. #if !defined(BOOST_SPIRIT_LEXER_PARSE_ATTR_MAY_27_2009_0926AM)
  9. #define BOOST_SPIRIT_LEXER_PARSE_ATTR_MAY_27_2009_0926AM
  10. #include <boost/spirit/home/lex/tokenize_and_parse.hpp>
  11. #include <boost/fusion/include/vector.hpp>
  12. #include <boost/preprocessor/cat.hpp>
  13. #include <boost/preprocessor/iterate.hpp>
  14. #include <boost/preprocessor/repetition/enum.hpp>
  15. #include <boost/preprocessor/repetition/enum_params.hpp>
  16. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  17. #define BOOST_PP_FILENAME_1 <boost/spirit/home/lex/tokenize_and_parse_attr.hpp>
  18. #define BOOST_PP_ITERATION_LIMITS (2, SPIRIT_ARGUMENTS_LIMIT)
  19. #include BOOST_PP_ITERATE()
  20. #endif
  21. ///////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Preprocessor vertical repetition code
  24. //
  25. ///////////////////////////////////////////////////////////////////////////////
  26. #else // defined(BOOST_PP_IS_ITERATING)
  27. #define N BOOST_PP_ITERATION()
  28. #define BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE(z, n, A) BOOST_PP_CAT(A, n)&
  29. namespace boost { namespace spirit { namespace lex
  30. {
  31. template <typename Iterator, typename Lexer, typename ParserExpr
  32. , BOOST_PP_ENUM_PARAMS(N, typename A)>
  33. inline bool
  34. tokenize_and_parse(Iterator& first, Iterator last, Lexer const& lex
  35. , ParserExpr const& expr, BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
  36. {
  37. // Report invalid expression error as early as possible.
  38. // If you got an error_invalid_expression error message here,
  39. // then the expression (expr) is not a valid spirit qi expression.
  40. BOOST_SPIRIT_ASSERT_MATCH(qi::domain, ParserExpr);
  41. typedef fusion::vector<
  42. BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
  43. > vector_type;
  44. vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
  45. typename Lexer::iterator_type iter = lex.begin(first, last);
  46. return compile<qi::domain>(expr).parse(
  47. iter, lex.end(), unused, unused, attr);
  48. }
  49. }}}
  50. #undef BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE
  51. #undef N
  52. #endif