parser.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  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. ==============================================================================*/
  6. #if !defined(BOOST_SPIRIT_PARSER_OCTOBER_16_2008_0254PM)
  7. #define BOOST_SPIRIT_PARSER_OCTOBER_16_2008_0254PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/mpl/has_xxx.hpp>
  12. #include <boost/spirit/home/qi/domain.hpp>
  13. namespace boost { namespace spirit { namespace qi
  14. {
  15. //[parser_base_parser
  16. template <typename Derived>
  17. struct parser
  18. {
  19. struct parser_id;
  20. typedef Derived derived_type;
  21. typedef qi::domain domain;
  22. // Requirement: p.parse(f, l, context, skip, attr) -> bool
  23. //
  24. // p: a parser
  25. // f, l: first/last iterator pair
  26. // context: enclosing rule context (can be unused_type)
  27. // skip: skipper (can be unused_type)
  28. // attr: attribute (can be unused_type)
  29. // Requirement: p.what(context) -> info
  30. //
  31. // p: a parser
  32. // context: enclosing rule context (can be unused_type)
  33. // Requirement: P::template attribute<Ctx, Iter>::type
  34. //
  35. // P: a parser type
  36. // Ctx: A context type (can be unused_type)
  37. // Iter: An iterator type (can be unused_type)
  38. Derived const& derived() const
  39. {
  40. return *static_cast<Derived const*>(this);
  41. }
  42. };
  43. //]
  44. template <typename Derived>
  45. struct primitive_parser : parser<Derived>
  46. {
  47. struct primitive_parser_id;
  48. };
  49. template <typename Derived>
  50. struct nary_parser : parser<Derived>
  51. {
  52. struct nary_parser_id;
  53. // Requirement: p.elements -> fusion sequence
  54. //
  55. // p: a composite parser
  56. // Requirement: P::elements_type -> fusion sequence
  57. //
  58. // P: a composite parser type
  59. };
  60. template <typename Derived>
  61. struct unary_parser : parser<Derived>
  62. {
  63. struct unary_parser_id;
  64. // Requirement: p.subject -> subject parser
  65. //
  66. // p: a unary parser
  67. // Requirement: P::subject_type -> subject parser type
  68. //
  69. // P: a unary parser type
  70. };
  71. template <typename Derived>
  72. struct binary_parser : parser<Derived>
  73. {
  74. struct binary_parser_id;
  75. // Requirement: p.left -> left parser
  76. //
  77. // p: a binary parser
  78. // Requirement: P::left_type -> left parser type
  79. //
  80. // P: a binary parser type
  81. // Requirement: p.right -> right parser
  82. //
  83. // p: a binary parser
  84. // Requirement: P::right_type -> right parser type
  85. //
  86. // P: a binary parser type
  87. };
  88. }}}
  89. namespace boost { namespace spirit { namespace traits // classification
  90. {
  91. namespace detail
  92. {
  93. BOOST_MPL_HAS_XXX_TRAIT_DEF(parser_id)
  94. BOOST_MPL_HAS_XXX_TRAIT_DEF(primitive_parser_id)
  95. BOOST_MPL_HAS_XXX_TRAIT_DEF(nary_parser_id)
  96. BOOST_MPL_HAS_XXX_TRAIT_DEF(unary_parser_id)
  97. BOOST_MPL_HAS_XXX_TRAIT_DEF(binary_parser_id)
  98. }
  99. // parser type identification
  100. template <typename T>
  101. struct is_parser : detail::has_parser_id<T> {};
  102. template <typename T>
  103. struct is_primitive_parser : detail::has_primitive_parser_id<T> {};
  104. template <typename T>
  105. struct is_nary_parser : detail::has_nary_parser_id<T> {};
  106. template <typename T>
  107. struct is_unary_parser : detail::has_unary_parser_id<T> {};
  108. template <typename T>
  109. struct is_binary_parser : detail::has_binary_parser_id<T> {};
  110. }}}
  111. #endif