File indexing completed on 2025-01-31 10:02:07
0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef BOOST_SPIRIT_CONFIX_IPP
0010 #define BOOST_SPIRIT_CONFIX_IPP
0011
0012
0013 #include <boost/spirit/home/classic/meta/refactoring.hpp>
0014 #include <boost/spirit/home/classic/core/composite/impl/directives.ipp>
0015
0016
0017 namespace boost { namespace spirit {
0018
0019 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0020
0021
0022
0023
0024
0025
0026 struct is_nested {};
0027 struct non_nested {};
0028
0029
0030
0031
0032
0033
0034
0035 struct is_lexeme {};
0036 struct non_lexeme {};
0037
0038
0039
0040
0041
0042
0043 namespace impl {
0044
0045
0046
0047
0048 template <typename LexemeT>
0049 struct select_confix_parse_lexeme;
0050
0051 template <>
0052 struct select_confix_parse_lexeme<is_lexeme> {
0053
0054 template <typename ParserT, typename ScannerT>
0055 static typename parser_result<ParserT, ScannerT>::type
0056 parse(ParserT const& p, ScannerT const& scan)
0057 {
0058 typedef typename parser_result<ParserT, ScannerT>::type result_t;
0059 return contiguous_parser_parse<result_t>(p, scan, scan);
0060 }
0061 };
0062
0063 template <>
0064 struct select_confix_parse_lexeme<non_lexeme> {
0065
0066 template <typename ParserT, typename ScannerT>
0067 static typename parser_result<ParserT, ScannerT>::type
0068 parse(ParserT const& p, ScannerT const& scan)
0069 {
0070 return p.parse(scan);
0071 }
0072 };
0073
0074
0075
0076
0077 template <typename NestedT>
0078 struct select_confix_parse_refactor;
0079
0080 template <>
0081 struct select_confix_parse_refactor<is_nested> {
0082
0083 template <
0084 typename LexemeT, typename ParserT, typename ScannerT,
0085 typename OpenT, typename ExprT, typename CloseT
0086 >
0087 static typename parser_result<ParserT, ScannerT>::type
0088 parse(
0089 LexemeT const &, ParserT const& this_, ScannerT const& scan,
0090 OpenT const& open, ExprT const& expr, CloseT const& close)
0091 {
0092 typedef refactor_action_gen<refactor_unary_gen<> > refactor_t;
0093 const refactor_t refactor_body_d = refactor_t(refactor_unary_d);
0094
0095 return select_confix_parse_lexeme<LexemeT>::parse((
0096 open
0097 >> (this_ | refactor_body_d[expr - close])
0098 >> close
0099 ), scan);
0100 }
0101 };
0102
0103 template <>
0104 struct select_confix_parse_refactor<non_nested> {
0105
0106 template <
0107 typename LexemeT, typename ParserT, typename ScannerT,
0108 typename OpenT, typename ExprT, typename CloseT
0109 >
0110 static typename parser_result<ParserT, ScannerT>::type
0111 parse(
0112 LexemeT const &, ParserT const& , ScannerT const& scan,
0113 OpenT const& open, ExprT const& expr, CloseT const& close)
0114 {
0115 typedef refactor_action_gen<refactor_unary_gen<> > refactor_t;
0116 const refactor_t refactor_body_d = refactor_t(refactor_unary_d);
0117
0118 return select_confix_parse_lexeme<LexemeT>::parse((
0119 open
0120 >> refactor_body_d[expr - close]
0121 >> close
0122 ), scan);
0123 }
0124 };
0125
0126
0127
0128
0129 template <typename NestedT>
0130 struct select_confix_parse_no_refactor;
0131
0132 template <>
0133 struct select_confix_parse_no_refactor<is_nested> {
0134
0135 template <
0136 typename LexemeT, typename ParserT, typename ScannerT,
0137 typename OpenT, typename ExprT, typename CloseT
0138 >
0139 static typename parser_result<ParserT, ScannerT>::type
0140 parse(
0141 LexemeT const &, ParserT const& this_, ScannerT const& scan,
0142 OpenT const& open, ExprT const& expr, CloseT const& close)
0143 {
0144 return select_confix_parse_lexeme<LexemeT>::parse((
0145 open
0146 >> (this_ | (expr - close))
0147 >> close
0148 ), scan);
0149 }
0150 };
0151
0152 template <>
0153 struct select_confix_parse_no_refactor<non_nested> {
0154
0155 template <
0156 typename LexemeT, typename ParserT, typename ScannerT,
0157 typename OpenT, typename ExprT, typename CloseT
0158 >
0159 static typename parser_result<ParserT, ScannerT>::type
0160 parse(
0161 LexemeT const &, ParserT const & , ScannerT const& scan,
0162 OpenT const& open, ExprT const& expr, CloseT const& close)
0163 {
0164 return select_confix_parse_lexeme<LexemeT>::parse((
0165 open
0166 >> (expr - close)
0167 >> close
0168 ), scan);
0169 }
0170 };
0171
0172
0173
0174
0175 template <typename CategoryT>
0176 struct confix_parser_type {
0177
0178 template <
0179 typename NestedT, typename LexemeT,
0180 typename ParserT, typename ScannerT,
0181 typename OpenT, typename ExprT, typename CloseT
0182 >
0183 static typename parser_result<ParserT, ScannerT>::type
0184 parse(
0185 NestedT const &, LexemeT const &lexeme,
0186 ParserT const& this_, ScannerT const& scan,
0187 OpenT const& open, ExprT const& expr, CloseT const& close)
0188 {
0189 return select_confix_parse_refactor<NestedT>::
0190 parse(lexeme, this_, scan, open, expr, close);
0191 }
0192 };
0193
0194 template <>
0195 struct confix_parser_type<plain_parser_category> {
0196
0197 template <
0198 typename NestedT, typename LexemeT,
0199 typename ParserT, typename ScannerT,
0200 typename OpenT, typename ExprT, typename CloseT
0201 >
0202 static typename parser_result<ParserT, ScannerT>::type
0203 parse(
0204 NestedT const &, LexemeT const &lexeme,
0205 ParserT const& this_, ScannerT const& scan,
0206 OpenT const& open, ExprT const& expr, CloseT const& close)
0207 {
0208 return select_confix_parse_no_refactor<NestedT>::
0209 parse(lexeme, this_, scan, open, expr, close);
0210 }
0211 };
0212
0213 }
0214
0215
0216 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0217
0218 }}
0219
0220 #endif
0221