token.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef META_HS_TOKEN_HPP
  2. #define META_HS_TOKEN_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2012.
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. #include <ast.hpp>
  8. #include <except_keywords.hpp>
  9. #include <boost/metaparse/string.hpp>
  10. #include <boost/metaparse/token.hpp>
  11. #include <boost/metaparse/always_c.hpp>
  12. #include <boost/metaparse/lit_c.hpp>
  13. #include <boost/metaparse/one_of.hpp>
  14. #include <boost/metaparse/last_of.hpp>
  15. #include <boost/metaparse/return_.hpp>
  16. #include <boost/metaparse/int_.hpp>
  17. #include <boost/metaparse/foldl_reject_incomplete_start_with_parser.hpp>
  18. #include <boost/metaparse/alphanum.hpp>
  19. #include <boost/metaparse/transform.hpp>
  20. #include <boost/metaparse/letter.hpp>
  21. #include <boost/metaparse/keyword.hpp>
  22. #include <boost/metaparse/optional.hpp>
  23. #include <boost/mpl/lambda.hpp>
  24. #include <boost/mpl/push_back.hpp>
  25. #include <boost/mpl/vector.hpp>
  26. namespace token
  27. {
  28. typedef
  29. boost::metaparse::token<
  30. boost::metaparse::always_c<'+',boost::metaparse::string<'.','+','.'> >
  31. >
  32. plus;
  33. typedef
  34. boost::metaparse::token<
  35. boost::metaparse::always_c<'-',boost::metaparse::string<'.','-','.'> >
  36. >
  37. minus;
  38. typedef
  39. boost::metaparse::token<
  40. boost::metaparse::always_c<'*',boost::metaparse::string<'.','*','.'> >
  41. >
  42. mult;
  43. typedef
  44. boost::metaparse::token<
  45. boost::metaparse::always_c<'/',boost::metaparse::string<'.','/','.'> >
  46. >
  47. div;
  48. typedef
  49. boost::metaparse::token<
  50. boost::metaparse::one_of<
  51. boost::metaparse::last_of<
  52. boost::metaparse::lit_c<'='>,
  53. boost::metaparse::lit_c<'='>,
  54. boost::metaparse::return_<
  55. boost::metaparse::string<'.','=','=','.'>
  56. >
  57. >,
  58. boost::metaparse::last_of<
  59. boost::metaparse::lit_c<'/'>,
  60. boost::metaparse::lit_c<'='>,
  61. boost::metaparse::return_<
  62. boost::metaparse::string<'.','/','=','.'>
  63. >
  64. >,
  65. boost::metaparse::last_of<
  66. boost::metaparse::lit_c<'<'>,
  67. boost::metaparse::one_of<
  68. boost::metaparse::always_c<
  69. '=',
  70. boost::metaparse::string<'.','<','=','.'>
  71. >,
  72. boost::metaparse::return_<
  73. boost::metaparse::string<'.','<','.'>
  74. >
  75. >
  76. >,
  77. boost::metaparse::last_of<
  78. boost::metaparse::lit_c<'>'>,
  79. boost::metaparse::optional<
  80. boost::metaparse::always_c<
  81. '=',
  82. boost::metaparse::string<'.','>','=','.'>
  83. >,
  84. boost::metaparse::string<'.','>','.'>
  85. >
  86. >
  87. >
  88. >
  89. cmp;
  90. typedef
  91. boost::metaparse::token<boost::metaparse::lit_c<'('> >
  92. open_bracket;
  93. typedef
  94. boost::metaparse::token<boost::metaparse::lit_c<')'> >
  95. close_bracket;
  96. typedef
  97. boost::metaparse::token<boost::metaparse::lit_c<'='> >
  98. define;
  99. typedef boost::metaparse::token<boost::metaparse::int_> int_;
  100. typedef
  101. boost::metaparse::token<
  102. except_keywords<
  103. boost::metaparse::foldl_reject_incomplete_start_with_parser<
  104. boost::metaparse::one_of<
  105. boost::metaparse::alphanum,
  106. boost::metaparse::lit_c<'_'>
  107. >,
  108. boost::metaparse::transform<
  109. boost::metaparse::one_of<
  110. boost::metaparse::letter,
  111. boost::metaparse::lit_c<'_'>
  112. >,
  113. boost::mpl::lambda<
  114. boost::mpl::push_back<
  115. boost::metaparse::string<>,
  116. boost::mpl::_1
  117. >
  118. >::type
  119. >,
  120. boost::mpl::lambda<
  121. boost::mpl::push_back<boost::mpl::_1, boost::mpl::_2>
  122. >::type
  123. >,
  124. boost::mpl::vector<
  125. boost::metaparse::string<'i','f'>,
  126. boost::metaparse::string<'t','h','e','n'>,
  127. boost::metaparse::string<'e','l','s','e'>
  128. >
  129. >
  130. >
  131. name;
  132. typedef
  133. boost::metaparse::token<
  134. boost::metaparse::keyword<boost::metaparse::string<'i','f'> >
  135. >
  136. if_;
  137. typedef
  138. boost::metaparse::token<
  139. boost::metaparse::keyword<boost::metaparse::string<'t','h','e','n'> >
  140. >
  141. then;
  142. typedef
  143. boost::metaparse::token<
  144. boost::metaparse::keyword<boost::metaparse::string<'e','l','s','e'> >
  145. >
  146. else_;
  147. }
  148. #endif