source_position_tag.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #ifndef BOOST_METAPARSE_V1_SOURCE_POSITION_TAG_HPP
  2. #define BOOST_METAPARSE_V1_SOURCE_POSITION_TAG_HPP
  3. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2013.
  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 <boost/metaparse/v1/fwd/source_position.hpp>
  8. #include <boost/metaparse/v1/fwd/get_prev_char.hpp>
  9. #include <boost/metaparse/v1/fwd/next_line.hpp>
  10. #include <boost/metaparse/v1/fwd/next_char.hpp>
  11. #include <boost/metaparse/v1/get_col.hpp>
  12. #include <boost/metaparse/v1/get_line.hpp>
  13. #include <boost/mpl/int.hpp>
  14. namespace boost
  15. {
  16. namespace metaparse
  17. {
  18. namespace v1
  19. {
  20. struct source_position_tag { typedef source_position_tag type; };
  21. template <>
  22. struct get_col_impl<source_position_tag>
  23. {
  24. template <class P>
  25. struct apply : P::col {};
  26. };
  27. template <>
  28. struct get_line_impl<source_position_tag>
  29. {
  30. template <class P>
  31. struct apply : P::line {};
  32. };
  33. template <>
  34. struct get_prev_char_impl<source_position_tag>
  35. {
  36. template <class P>
  37. struct apply : P::prev_char {};
  38. };
  39. template <>
  40. struct next_char_impl<source_position_tag>
  41. {
  42. template <class P, class Ch>
  43. struct apply :
  44. source_position<
  45. typename get_line<P>::type,
  46. boost::mpl::int_<get_col<P>::type::value + 1>,
  47. Ch
  48. >
  49. {};
  50. };
  51. template <>
  52. struct next_line_impl<source_position_tag>
  53. {
  54. template <class P, class Ch>
  55. struct apply :
  56. source_position<
  57. boost::mpl::int_<get_line<P>::type::value + 1>,
  58. boost::mpl::int_<1>,
  59. Ch
  60. >
  61. {};
  62. };
  63. }
  64. }
  65. }
  66. #endif