/Src/Dependencies/Boost/boost/spirit/repository/home/qi/operator/detail/keywords.hpp

http://hadesmem.googlecode.com/ · C++ Header · 115 lines · 88 code · 14 blank · 13 comment · 2 complexity · 0e89cc4b3b53c29cfdd8808543732707 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2011 Thomas Bernard
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #if !defined(SPIRIT_KEYWORDS_DETAIL_MARCH_13_2007_1145PM)
  8. #define SPIRIT_KEYWORDS_DETAIL_MARCH_13_2007_1145PM
  9. #if defined(_MSC_VER)
  10. #pragma once
  11. #endif
  12. namespace boost { namespace spirit { namespace repository { namespace qi { namespace detail {
  13. // This helper class enables jumping over intermediate directives
  14. // down the kwd parser iteration count checking policy
  15. struct register_successful_parse
  16. {
  17. template <typename Subject>
  18. static bool call(Subject const &subject,bool &flag, int &counter)
  19. {
  20. return subject.iter.register_successful_parse(flag,counter);
  21. }
  22. template <typename Subject, typename Action>
  23. static bool call(spirit::qi::action<Subject, Action> const &subject,bool &flag, int &counter)
  24. {
  25. return subject.subject.iter.register_successful_parse(flag,counter);
  26. }
  27. template <typename Subject>
  28. static bool call(spirit::qi::hold_directive<Subject> const &subject,bool &flag, int &counter)
  29. {
  30. return subject.subject.iter.register_successful_parse(flag,counter);
  31. }
  32. };
  33. // Variant visitor class which handles dispatching the parsing to the selected parser
  34. // This also handles passing the correct attributes and flags/counters to the subject parsers
  35. template < typename Elements, typename Iterator ,typename Context ,typename Skipper
  36. ,typename Flags ,typename Counters ,typename Attribute, typename NoCasePass>
  37. class parse_dispatcher
  38. : public boost::static_visitor<bool>
  39. {
  40. public:
  41. parse_dispatcher(const Elements &elements,Iterator& first, Iterator const& last
  42. , Context& context, Skipper const& skipper
  43. , Flags &flags, Counters &counters, Attribute& attr) :
  44. elements(elements), first(first), last(last)
  45. , context(context), skipper(skipper)
  46. , flags(flags),counters(counters), attr(attr)
  47. {}
  48. template<typename T> bool operator()(T& idx) const
  49. {
  50. return call(idx,typename traits::not_is_unused<Attribute>::type());
  51. }
  52. template <typename Subject,typename Index>
  53. bool call_subject_unused(
  54. Subject const &subject, Iterator &first, Iterator const &last
  55. , Context& context, Skipper const& skipper
  56. , Index& idx ) const
  57. {
  58. Iterator save = first;
  59. skipper_keyword_marker<Skipper,NoCasePass> marked_skipper(skipper,flags[Index::value],counters[Index::value]);
  60. if(subject.parse(first,last,context,marked_skipper,unused))
  61. {
  62. return true;
  63. }
  64. save = save;
  65. return false;
  66. }
  67. template <typename Subject,typename Index>
  68. bool call_subject(
  69. Subject const &subject, Iterator &first, Iterator const &last
  70. , Context& context, Skipper const& skipper
  71. , Index& idx ) const
  72. {
  73. Iterator save = first;
  74. skipper_keyword_marker<Skipper,NoCasePass> marked_skipper(skipper,flags[Index::value],counters[Index::value]);
  75. if(subject.parse(first,last,context,marked_skipper,fusion::at_c<Index::value>(attr)))
  76. {
  77. return true;
  78. }
  79. save = save;
  80. return false;
  81. }
  82. // Handle unused attributes
  83. template <typename T> bool call(T &idx, mpl::false_) const{
  84. return call_subject_unused(fusion::at_c<T::value>(elements), first, last, context, skipper, idx );
  85. }
  86. // Handle normal attributes
  87. template <typename T> bool call(T &idx, mpl::true_) const{
  88. return call_subject(fusion::at_c<T::value>(elements), first, last, context, skipper, idx);
  89. }
  90. const Elements &elements;
  91. Iterator &first;
  92. const Iterator &last;
  93. Context & context;
  94. const Skipper &skipper;
  95. Flags &flags;
  96. Counters &counters;
  97. Attribute &attr;
  98. };
  99. }}}}}
  100. #endif