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