iter_pos.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright (c) 2001-2010 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(ITER_POS_NOV_20_2009_1245PM)
  6. #define ITER_POS_NOV_20_2009_1245PM
  7. #include <boost/spirit/include/qi_parse.hpp>
  8. ///////////////////////////////////////////////////////////////////////////////
  9. // definition the place holder
  10. namespace custom_parser
  11. {
  12. BOOST_SPIRIT_TERMINAL(iter_pos)
  13. }
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // implementation the enabler
  16. namespace boost { namespace spirit
  17. {
  18. // We want custom_parser::iter_pos to be usable as a terminal only,
  19. // and only for parser expressions (qi::domain).
  20. template <>
  21. struct use_terminal<qi::domain, custom_parser::tag::iter_pos>
  22. : mpl::true_
  23. {};
  24. }}
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // implementation of the parser
  27. namespace custom_parser
  28. {
  29. struct iter_pos_parser
  30. : boost::spirit::qi::primitive_parser<iter_pos_parser>
  31. {
  32. // Define the attribute type exposed by this parser component
  33. template <typename Context, typename Iterator>
  34. struct attribute
  35. {
  36. typedef Iterator type;
  37. };
  38. // This function is called during the actual parsing process
  39. template <typename Iterator, typename Context
  40. , typename Skipper, typename Attribute>
  41. bool parse(Iterator& first, Iterator const& last
  42. , Context&, Skipper const& skipper, Attribute& attr) const
  43. {
  44. boost::spirit::qi::skip_over(first, last, skipper);
  45. boost::spirit::traits::assign_to(first, attr);
  46. return true;
  47. }
  48. // This function is called during error handling to create
  49. // a human readable string for the error context.
  50. template <typename Context>
  51. boost::spirit::info what(Context&) const
  52. {
  53. return boost::spirit::info("iter_pos");
  54. }
  55. };
  56. }
  57. ///////////////////////////////////////////////////////////////////////////////
  58. // instantiation of the parser
  59. namespace boost { namespace spirit { namespace qi
  60. {
  61. // This is the factory function object invoked in order to create
  62. // an instance of our iter_pos_parser.
  63. template <typename Modifiers>
  64. struct make_primitive<custom_parser::tag::iter_pos, Modifiers>
  65. {
  66. typedef custom_parser::iter_pos_parser result_type;
  67. result_type operator()(unused_type, unused_type) const
  68. {
  69. return result_type();
  70. }
  71. };
  72. }}}
  73. #endif