sequence.hpp 2.4 KB

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