1 /*//////////////////////////////////////////////////////////////////////////////
2 Copyright (c) 2011 Jamboree
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //////////////////////////////////////////////////////////////////////////////*/
7 #ifndef BOOST_SPIRIT_REPOSITORY_QI_SEEK
8 #define BOOST_SPIRIT_REPOSITORY_QI_SEEK
16 #include <boost/spirit/home/qi/meta_compiler.hpp>
17 #include <boost/spirit/home/qi/parser.hpp>
18 #include <boost/spirit/home/qi/detail/attributes.hpp>
19 #include <boost/spirit/home/support/info.hpp>
20 #include <boost/spirit/home/support/unused.hpp>
21 #include <boost/spirit/home/support/has_semantic_action.hpp>
22 #include <boost/spirit/home/support/handles_container.hpp>
23 #include <boost/spirit/repository/home/support/seek.hpp>
26 namespace boost { namespace spirit
28 ///////////////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////////////
34 struct use_directive<qi::domain, repository::tag::seek>
36 }} // namespace boost::spirit
39 namespace boost { namespace spirit { namespace repository {namespace qi
41 #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
42 using repository::seek;
44 using repository::seek_type;
46 template <typename Subject>
48 : spirit::qi::unary_parser<seek_directive<Subject> >
50 typedef Subject subject_type;
52 template <typename Context, typename Iterator>
56 traits::attribute_of<subject_type, Context, Iterator>::type
60 seek_directive(Subject const& subject)
66 typename Iterator, typename Context
67 , typename Skipper, typename Attribute
71 Iterator& first, Iterator const& last
72 , Context& context, Skipper const& skipper
76 for (Iterator it(first); ; ++it)
78 if (subject.parse(it, last, context, skipper, attr))
83 // fail only after subject fails & no input
89 template <typename Context>
90 info what(Context& context) const
92 return info("seek", subject.what(context));
97 }}}} // namespace boost::spirit::repository::qi
100 namespace boost { namespace spirit { namespace qi
102 ///////////////////////////////////////////////////////////////////////////
103 // Parser generators: make_xxx function (objects)
104 ///////////////////////////////////////////////////////////////////////////
105 template <typename Subject, typename Modifiers>
106 struct make_directive<repository::tag::seek, Subject, Modifiers>
108 typedef repository::qi::seek_directive<Subject> result_type;
110 result_type operator()(unused_type, Subject const& subject, unused_type) const
112 return result_type(subject);
115 }}} // namespace boost::spirit::qi
118 namespace boost { namespace spirit { namespace traits
120 ///////////////////////////////////////////////////////////////////////////
121 template <typename Subject>
122 struct has_semantic_action<repository::qi::seek_directive<Subject> >
123 : unary_has_semantic_action<Subject> {};
125 ///////////////////////////////////////////////////////////////////////////
126 template <typename Subject, typename Attribute, typename Context
128 struct handles_container<repository::qi::seek_directive<Subject>, Attribute
130 : unary_handles_container<Subject, Attribute, Context, Iterator> {};
131 }}} // namespace boost::spirit::traits