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_LEXER_PARSE_ATTR_MAY_27_2009_0926AM)
11 #define BOOST_SPIRIT_LEXER_PARSE_ATTR_MAY_27_2009_0926AM
12 
13 #include <boost/spirit/home/lex/tokenize_and_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/lex/tokenize_and_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 lex
39 {
40     template <typename Iterator, typename Lexer, typename ParserExpr
41       , BOOST_PP_ENUM_PARAMS(N, typename A)>
42     inline bool
tokenize_and_parse(Iterator & first,Iterator last,Lexer const & lex,ParserExpr const & expr,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))43     tokenize_and_parse(Iterator& first, Iterator last, Lexer const& lex
44       , ParserExpr const& expr, BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
45     {
46         // Report invalid expression error as early as possible.
47         // If you got an error_invalid_expression error message here,
48         // then the expression (expr) is not a valid spirit qi expression.
49         BOOST_SPIRIT_ASSERT_MATCH(qi::domain, ParserExpr);
50 
51         typedef fusion::vector<
52             BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
53         > vector_type;
54 
55         vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
56         typename Lexer::iterator_type iter = lex.begin(first, last);
57         return compile<qi::domain>(expr).parse(
58             iter, lex.end(), unused, unused, attr);
59     }
60 
61     ///////////////////////////////////////////////////////////////////////////
62     template <typename Iterator, typename Lexer, typename ParserExpr
63       , typename Skipper, BOOST_PP_ENUM_PARAMS(N, typename A)>
64     inline bool
tokenize_and_phrase_parse(Iterator & first,Iterator last,Lexer const & lex,ParserExpr const & expr,Skipper const & skipper,BOOST_SCOPED_ENUM (skip_flag)post_skip,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))65     tokenize_and_phrase_parse(Iterator& first, Iterator last, Lexer const& lex
66       , ParserExpr const& expr, Skipper const& skipper
67       , BOOST_SCOPED_ENUM(skip_flag) post_skip
68       , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
69     {
70         // Report invalid expression error as early as possible.
71         // If you got an error_invalid_expression error message here,
72         // then either the expression (expr) or skipper is not a valid
73         // spirit qi expression.
74         BOOST_SPIRIT_ASSERT_MATCH(qi::domain, ParserExpr);
75         BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Skipper);
76 
77         typedef
78             typename spirit::result_of::compile<qi::domain, Skipper>::type
79         skipper_type;
80         skipper_type const skipper_ = compile<qi::domain>(skipper);
81 
82         typedef fusion::vector<
83             BOOST_PP_ENUM(N, BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE, A)
84         > vector_type;
85 
86         vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
87         typename Lexer::iterator_type iter = lex.begin(first, last);
88         if (!compile<qi::domain>(expr).parse(
89                 iter, lex.end(), unused, skipper_, attr))
90             return false;
91 
92         if (post_skip == skip_flag::postskip)
93             qi::skip_over(first, last, skipper_);
94         return true;
95     }
96 
97     template <typename Iterator, typename Lexer, typename ParserExpr
98       , typename Skipper, BOOST_PP_ENUM_PARAMS(N, typename A)>
99     inline bool
tokenize_and_phrase_parse(Iterator & first,Iterator last,Lexer const & lex,ParserExpr const & expr,Skipper const & skipper,BOOST_PP_ENUM_BINARY_PARAMS (N,A,& attr))100     tokenize_and_phrase_parse(Iterator& first, Iterator last, Lexer const& lex
101       , ParserExpr const& expr, Skipper const& skipper
102       , BOOST_PP_ENUM_BINARY_PARAMS(N, A, & attr))
103     {
104         return tokenize_and_phrase_parse(first, last, expr, skipper
105           , skip_flag::postskip, BOOST_PP_ENUM_PARAMS(N, attr));
106     }
107 
108 }}}
109 
110 #undef BOOST_SPIRIT_QI_ATTRIBUTE_REFERENCE
111 #undef N
112 
113 #endif
114 
115