sequence.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(SPIRIT_LEX_SEQUENCE_MAR_28_2007_0610PM)
  6. #define SPIRIT_LEX_SEQUENCE_MAR_28_2007_0610PM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/lex/domain.hpp>
  11. #include <boost/spirit/home/lex/lexer_type.hpp>
  12. #include <boost/spirit/home/lex/meta_compiler.hpp>
  13. #include <boost/spirit/home/lex/detail/sequence_function.hpp>
  14. #include <boost/fusion/include/any.hpp>
  15. namespace boost { namespace spirit
  16. {
  17. ///////////////////////////////////////////////////////////////////////////
  18. // Enablers
  19. ///////////////////////////////////////////////////////////////////////////
  20. template <>
  21. struct use_operator<lex::domain, proto::tag::bitwise_or> // enables |
  22. : mpl::true_ {};
  23. template <>
  24. struct flatten_tree<lex::domain, proto::tag::bitwise_or> // flattens |
  25. : mpl::true_ {};
  26. }}
  27. namespace boost { namespace spirit { namespace lex
  28. {
  29. template <typename Elements>
  30. struct sequence : nary_lexer<sequence<Elements> >
  31. {
  32. sequence(Elements const& elements)
  33. : elements(elements) {}
  34. template <typename LexerDef, typename String>
  35. void collect(LexerDef& lexdef, String const& state
  36. , String const& targetstate) const
  37. {
  38. typedef detail::sequence_collect_function<LexerDef, String>
  39. collect_function_type;
  40. collect_function_type f (lexdef, state, targetstate);
  41. fusion::any(elements, f);
  42. }
  43. template <typename LexerDef>
  44. void add_actions(LexerDef& lexdef) const
  45. {
  46. detail::sequence_add_actions_function<LexerDef> f (lexdef);
  47. fusion::any(elements, f);
  48. }
  49. Elements elements;
  50. };
  51. ///////////////////////////////////////////////////////////////////////////
  52. // Lexer generator: make_xxx function (objects)
  53. ///////////////////////////////////////////////////////////////////////////
  54. template <typename Elements, typename Modifiers>
  55. struct make_composite<proto::tag::bitwise_or, Elements, Modifiers>
  56. : make_nary_composite<Elements, sequence>
  57. {};
  58. }}} // namespace boost::spirit::lex
  59. #endif