1 // Copyright (c) 2009 Chris Hoeppler
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)
6 #if !defined(BOOST_SPIRIT_REPOSITORY_QI_CONFIX_JUN_22_2009_1041AM)
7 #define BOOST_SPIRIT_REPOSITORY_QI_CONFIX_JUN_22_2009_1041AM
13 #include <boost/spirit/home/qi/domain.hpp>
14 #include <boost/spirit/home/qi/meta_compiler.hpp>
15 #include <boost/spirit/home/qi/auxiliary/lazy.hpp>
16 #include <boost/spirit/home/support/common_terminals.hpp>
17 #include <boost/spirit/home/support/info.hpp>
18 #include <boost/spirit/home/support/unused.hpp>
19 #include <boost/spirit/home/qi/detail/attributes.hpp>
21 #include <boost/spirit/repository/home/support/confix.hpp>
23 #include <boost/fusion/include/vector.hpp>
24 #include <boost/mpl/or.hpp>
26 ///////////////////////////////////////////////////////////////////////////////
27 namespace boost { namespace spirit
29 ///////////////////////////////////////////////////////////////////////////
31 ///////////////////////////////////////////////////////////////////////////
33 // enables confix(..., ...)[]
34 template <typename Prefix, typename Suffix>
35 struct use_directive<qi::domain
36 , terminal_ex<repository::tag::confix, fusion::vector2<Prefix, Suffix> > >
39 // enables *lazy* confix(..., ...)[]
41 struct use_lazy_directive<qi::domain, repository::tag::confix, 2>
46 ///////////////////////////////////////////////////////////////////////////////
47 namespace boost { namespace spirit { namespace repository { namespace qi
49 using repository::confix_type;
50 using repository::confix;
52 ///////////////////////////////////////////////////////////////////////////
53 // the confix() generated parser
54 template <typename Subject, typename Prefix, typename Suffix>
56 : spirit::qi::unary_parser<confix_parser<Subject, Prefix, Suffix> >
58 typedef Subject subject_type;
60 template <typename Context, typename Iterator>
62 : traits::attribute_of<subject_type, Context, Iterator>
65 confix_parser(Subject const& subject, Prefix const& prefix
66 , Suffix const& suffix)
67 : subject(subject), prefix(prefix), suffix(suffix) {}
69 template <typename Iterator, typename Context
70 , typename Skipper, typename Attribute>
71 bool parse(Iterator& first, Iterator const& last
72 , Context& context, Skipper const& skipper
73 , Attribute& attr) const
75 Iterator iter = first;
77 if (!(prefix.parse(iter, last, context, skipper, unused) &&
78 subject.parse(iter, last, context, skipper, attr) &&
79 suffix.parse(iter, last, context, skipper, unused)))
88 template <typename Context>
89 info what(Context const& ctx) const
91 return info("confix", subject.what(ctx));
101 ///////////////////////////////////////////////////////////////////////////////
102 namespace boost { namespace spirit { namespace qi
104 ///////////////////////////////////////////////////////////////////////////
105 // Parser generators: make_xxx function (objects)
106 ///////////////////////////////////////////////////////////////////////////
108 // creates confix(..., ...)[] directive
109 template <typename Prefix, typename Suffix, typename Subject
110 , typename Modifiers>
111 struct make_directive<
112 terminal_ex<repository::tag::confix, fusion::vector2<Prefix, Suffix> >
113 , Subject, Modifiers>
116 result_of::compile<qi::domain, Prefix, Modifiers>::type
119 result_of::compile<qi::domain, Suffix, Modifiers>::type
122 typedef repository::qi::confix_parser<
123 Subject, prefix_type, suffix_type> result_type;
125 template <typename Terminal>
126 result_type operator()(Terminal const& term, Subject const& subject
127 , Modifiers const& modifiers) const
129 return result_type(subject
130 , compile<qi::domain>(fusion::at_c<0>(term.args), modifiers)
131 , compile<qi::domain>(fusion::at_c<1>(term.args), modifiers));
137 namespace boost { namespace spirit { namespace traits
139 template <typename Subject, typename Prefix, typename Suffix>
140 struct has_semantic_action<
141 repository::qi::confix_parser<Subject, Prefix, Suffix> >
143 has_semantic_action<Subject>
144 , has_semantic_action<Prefix>
145 , has_semantic_action<Suffix>