auto.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_SPIRIT_QI_AUTO_NOV_29_2009_0336PM)
  6. #define BOOST_SPIRIT_QI_AUTO_NOV_29_2009_0336PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/support/common_terminals.hpp>
  11. #include <boost/spirit/home/support/info.hpp>
  12. #include <boost/spirit/home/support/container.hpp>
  13. #include <boost/spirit/home/support/detail/hold_any.hpp>
  14. #include <boost/spirit/home/qi/domain.hpp>
  15. #include <boost/spirit/home/qi/meta_compiler.hpp>
  16. #include <boost/spirit/home/qi/skip_over.hpp>
  17. #include <boost/spirit/home/qi/parser.hpp>
  18. #include <boost/spirit/home/qi/auto/create_parser.hpp>
  19. #include <boost/mpl/bool.hpp>
  20. ///////////////////////////////////////////////////////////////////////////////
  21. namespace boost { namespace spirit
  22. {
  23. ///////////////////////////////////////////////////////////////////////////
  24. // Enablers
  25. ///////////////////////////////////////////////////////////////////////////
  26. template <>
  27. struct use_terminal<qi::domain, tag::auto_> // enables auto_
  28. : mpl::true_ {};
  29. }}
  30. ///////////////////////////////////////////////////////////////////////////////
  31. namespace boost { namespace spirit { namespace qi
  32. {
  33. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  34. using spirit::auto_;
  35. #endif
  36. using spirit::auto_type;
  37. ///////////////////////////////////////////////////////////////////////////
  38. template <typename Modifiers>
  39. struct auto_parser
  40. : parser<auto_parser<Modifiers> >
  41. {
  42. template <typename Context, typename Iterator>
  43. struct attribute
  44. {
  45. typedef spirit::hold_any type;
  46. };
  47. auto_parser(Modifiers const& modifiers)
  48. : modifiers_(modifiers) {}
  49. template <typename Iterator, typename Context, typename Skipper
  50. , typename Attribute>
  51. bool parse(Iterator& first, Iterator const& last
  52. , Context& context, Skipper const& skipper, Attribute& attr) const
  53. {
  54. return compile<qi::domain>(create_parser<Attribute>(), modifiers_)
  55. .parse(first, last, context, skipper, attr);
  56. }
  57. template <typename Context>
  58. info what(Context& /*context*/) const
  59. {
  60. return info("auto_");
  61. }
  62. Modifiers modifiers_;
  63. };
  64. ///////////////////////////////////////////////////////////////////////////
  65. // Generator generators: make_xxx function (objects)
  66. ///////////////////////////////////////////////////////////////////////////
  67. template <typename Modifiers>
  68. struct make_primitive<tag::auto_, Modifiers>
  69. {
  70. typedef auto_parser<Modifiers> result_type;
  71. result_type operator()(unused_type, Modifiers const& modifiers) const
  72. {
  73. return result_type(modifiers);
  74. }
  75. };
  76. }}}
  77. #endif