msm_grammar.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2008 Christophe Henry
  2. // henry UNDERSCORE christophe AT hotmail DOT com
  3. // This is an extended version of the state machine available in the boost::mpl library
  4. // Distributed under the same license as the original.
  5. // Copyright for the original version:
  6. // Copyright 2005 David Abrahams and Aleksey Gurtovoy. Distributed
  7. // under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_MSM_GRAMMAR_H
  11. #define BOOST_MSM_GRAMMAR_H
  12. #include <boost/proto/core.hpp>
  13. #include <boost/msm/common.hpp>
  14. namespace boost { namespace msm
  15. {
  16. // base grammar for all of msm's proto-based grammars
  17. struct basic_grammar : proto::_
  18. {};
  19. // Forward-declare an expression wrapper
  20. template<typename Expr>
  21. struct msm_terminal;
  22. struct msm_domain
  23. : proto::domain< proto::generator<msm_terminal>, basic_grammar >
  24. {};
  25. template<typename Expr>
  26. struct msm_terminal
  27. : proto::extends<Expr, msm_terminal<Expr>, msm_domain>
  28. {
  29. typedef
  30. proto::extends<Expr, msm_terminal<Expr>, msm_domain>
  31. base_type;
  32. // Needs a constructor
  33. msm_terminal(Expr const &e = Expr())
  34. : base_type(e)
  35. {}
  36. };
  37. // grammar forbidding address of for terminals
  38. struct terminal_grammar : proto::not_<proto::address_of<proto::_> >
  39. {};
  40. // Forward-declare an expression wrapper
  41. template<typename Expr>
  42. struct euml_terminal;
  43. struct sm_domain
  44. : proto::domain< proto::generator<euml_terminal>, terminal_grammar, boost::msm::msm_domain >
  45. {};
  46. struct state_grammar :
  47. proto::and_<
  48. proto::not_<proto::address_of<proto::_> >,
  49. proto::not_<proto::shift_right<proto::_,proto::_> >,
  50. proto::not_<proto::shift_left<proto::_,proto::_> >,
  51. proto::not_<proto::bitwise_and<proto::_,proto::_> >
  52. >
  53. {};
  54. struct state_domain
  55. : proto::domain< proto::generator<euml_terminal>, boost::msm::state_grammar,boost::msm::sm_domain >
  56. {};
  57. template<typename Expr>
  58. struct euml_terminal
  59. : proto::extends<Expr, euml_terminal<Expr>, boost::msm::sm_domain>
  60. {
  61. typedef
  62. proto::extends<Expr, euml_terminal<Expr>, boost::msm::sm_domain>
  63. base_type;
  64. // Needs a constructor
  65. euml_terminal(Expr const &e = Expr())
  66. : base_type(e)
  67. {}
  68. // Unhide Proto's overloaded assignment operator
  69. using base_type::operator=;
  70. };
  71. } } // boost::msm
  72. #endif //BOOST_MSM_GRAMMAR_H