1 // Copyright (c) 2001-2011 Hartmut Kaiser 2 // Copyright (c) 2001-2011 Joel de Guzman 3 // Copyright (c) 2009 Carl Barron 4 // 5 // Distributed under the Boost Software License, Version 1.0. (See accompanying 6 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8 #if !defined(BOOST_PP_IS_ITERATING) 9 10 #if !defined(BOOST_SPIRIT_PARSE_ATTR_APRIL_24_2009_1043AM) 11 #define BOOST_SPIRIT_PARSE_ATTR_APRIL_24_2009_1043AM 12 13 #include <boost/spirit/home/qi/parse.hpp> 14 15 #include <boost/fusion/include/vector.hpp> 16 #include <boost/preprocessor/cat.hpp> 17 #include <boost/preprocessor/iterate.hpp> 18 #include <boost/preprocessor/repetition/enum.hpp> 19 #include <boost/preprocessor/repetition/enum_params.hpp> 20 #include <boost/preprocessor/repetition/enum_binary_params.hpp> 21 22 #define BOOST_PP_FILENAME_1 <boost/spirit/home/qi/parse_attr.hpp> 23 #define BOOST_PP_ITERATION_LIMITS (2, SPIRIT_ARGUMENTS_LIMIT) 24 #include BOOST_PP_ITERATE() 25 26 #endif 27 28 /////////////////////////////////////////////////////////////////////////////// 29 // 30 // Preprocessor vertical repetition code 31 // 32 /////////////////////////////////////////////////////////////////////////////// 33 #else // defined(BOOST_PP_IS_ITERATING) 34 35 #define N BOOST_PP_ITERATION() 36 #define BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE(z, n, A) BOOST_PP_CAT(A, n)& 37 38 namespace boost { namespace spirit { namespace qi 39 { 40 /////////////////////////////////////////////////////////////////////////// 41 template <typename Iterator, typename Expr 42 , BOOST_PP_ENUM_PARAMS(N, typename A)> 43 inline bool parse(Iterator & first,Iterator last,Expr const & expr,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))44 parse( 45 Iterator& first 46 , Iterator last 47 , Expr const& expr 48 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr)) 49 { 50 // Make sure the iterator is at least a forward_iterator. If you got an 51 // compilation error here, then you are using an input_iterator while 52 // calling this function, you need to supply at least a 53 // forward_iterator instead. 54 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>)); 55 56 // Report invalid expression error as early as possible. 57 // If you got an error_invalid_expression error message here, 58 // then the expression (expr) is not a valid spirit qi expression. 59 BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr); 60 61 typedef fusion::vector< 62 BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A) 63 > vector_type; 64 65 vector_type lattr (BOOST_PP_ENUM_PARAMS(N, attr)); 66 return compile<qi::domain>(expr).parse(first, last, unused, unused, lattr); 67 } 68 69 template <typename Iterator, typename Expr 70 , BOOST_PP_ENUM_PARAMS(N, typename A)> 71 inline bool parse(Iterator const & first_,Iterator last,Expr const & expr,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))72 parse( 73 Iterator const& first_ 74 , Iterator last 75 , Expr const& expr 76 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr)) 77 { 78 Iterator first = first_; 79 return qi::parse(first, last, expr, BOOST_PP_ENUM_PARAMS(N, attr)); 80 } 81 82 /////////////////////////////////////////////////////////////////////////// 83 template <typename Iterator, typename Expr, typename Skipper 84 , BOOST_PP_ENUM_PARAMS(N, typename A)> 85 inline bool phrase_parse(Iterator & first,Iterator last,Expr const & expr,Skipper const & skipper,BOOST_SCOPED_ENUM (skip_flag)post_skip,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))86 phrase_parse( 87 Iterator& first 88 , Iterator last 89 , Expr const& expr 90 , Skipper const& skipper 91 , BOOST_SCOPED_ENUM(skip_flag) post_skip 92 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr)) 93 { 94 // Make sure the iterator is at least a forward_iterator. If you got an 95 // compilation error here, then you are using an input_iterator while 96 // calling this function, you need to supply at least a 97 // forward_iterator instead. 98 BOOST_CONCEPT_ASSERT((ForwardIterator<Iterator>)); 99 100 // Report invalid expression error as early as possible. 101 // If you got an error_invalid_expression error message here, 102 // then either the expression (expr) or skipper is not a valid 103 // spirit qi expression. 104 BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr); 105 BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper); 106 107 typedef 108 typename result_of::compile<qi::domain, Skipper>::type 109 skipper_type; 110 skipper_type const skipper_ = compile<qi::domain>(skipper); 111 112 typedef fusion::vector< 113 BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A) 114 > vector_type; 115 116 vector_type lattr (BOOST_PP_ENUM_PARAMS(N, attr)); 117 if (!compile<qi::domain>(expr).parse( 118 first, last, unused, skipper_, lattr)) 119 return false; 120 121 if (post_skip == skip_flag::postskip) 122 qi::skip_over(first, last, skipper_); 123 return true; 124 } 125 126 template <typename Iterator, typename Expr, typename Skipper 127 , BOOST_PP_ENUM_PARAMS(N, typename A)> 128 inline bool phrase_parse(Iterator const & first_,Iterator last,Expr const & expr,Skipper const & skipper,BOOST_SCOPED_ENUM (skip_flag)post_skip,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))129 phrase_parse( 130 Iterator const& first_ 131 , Iterator last 132 , Expr const& expr 133 , Skipper const& skipper 134 , BOOST_SCOPED_ENUM(skip_flag) post_skip 135 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr)) 136 { 137 Iterator first = first_; 138 return qi::phrase_parse(first, last, expr, skipper, post_skip 139 , BOOST_PP_ENUM_PARAMS(N, attr)); 140 } 141 142 /////////////////////////////////////////////////////////////////////////// 143 template <typename Iterator, typename Expr, typename Skipper 144 , BOOST_PP_ENUM_PARAMS(N, typename A)> 145 inline bool phrase_parse(Iterator & first,Iterator last,Expr const & expr,Skipper const & skipper,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))146 phrase_parse( 147 Iterator& first 148 , Iterator last 149 , Expr const& expr 150 , Skipper const& skipper 151 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr)) 152 { 153 return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip 154 , BOOST_PP_ENUM_PARAMS(N, attr)); 155 } 156 157 template <typename Iterator, typename Expr, typename Skipper 158 , BOOST_PP_ENUM_PARAMS(N, typename A)> 159 inline bool phrase_parse(Iterator const & first_,Iterator last,Expr const & expr,Skipper const & skipper,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))160 phrase_parse( 161 Iterator const& first_ 162 , Iterator last 163 , Expr const& expr 164 , Skipper const& skipper 165 , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr)) 166 { 167 Iterator first = first_; 168 return qi::phrase_parse(first, last, expr, skipper, skip_flag::postskip 169 , BOOST_PP_ENUM_PARAMS(N, attr)); 170 } 171 }}} 172 173 #undef BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE 174 #undef N 175 176 #endif 177 178