File indexing completed on 2025-01-31 10:01:54
0001
0002
0003
0004
0005
0006
0007
0008
0009 #if !defined(BOOST_SPIRIT_DIRECTIVES_HPP)
0010 #define BOOST_SPIRIT_DIRECTIVES_HPP
0011
0012
0013 #include <algorithm>
0014
0015 #include <boost/spirit/home/classic/namespace.hpp>
0016 #include <boost/spirit/home/classic/core/parser.hpp>
0017 #include <boost/spirit/home/classic/core/scanner/skipper.hpp>
0018 #include <boost/spirit/home/classic/core/primitives/primitives.hpp>
0019 #include <boost/spirit/home/classic/core/composite/composite.hpp>
0020 #include <boost/spirit/home/classic/core/composite/impl/directives.ipp>
0021
0022 namespace boost { namespace spirit {
0023
0024 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0025
0026
0027
0028
0029
0030
0031 struct lexeme_parser_gen;
0032
0033 template <typename ParserT>
0034 struct contiguous
0035 : public unary<ParserT, parser<contiguous<ParserT> > >
0036 {
0037 typedef contiguous<ParserT> self_t;
0038 typedef unary_parser_category parser_category_t;
0039 typedef lexeme_parser_gen parser_generator_t;
0040 typedef unary<ParserT, parser<self_t> > base_t;
0041
0042 template <typename ScannerT>
0043 struct result
0044 {
0045 typedef typename parser_result<ParserT, ScannerT>::type type;
0046 };
0047
0048 contiguous(ParserT const& p)
0049 : base_t(p) {}
0050
0051 template <typename ScannerT>
0052 typename parser_result<self_t, ScannerT>::type
0053 parse(ScannerT const& scan) const
0054 {
0055 typedef typename parser_result<self_t, ScannerT>::type result_t;
0056 return impl::contiguous_parser_parse<result_t>
0057 (this->subject(), scan, scan);
0058 }
0059 };
0060
0061 struct lexeme_parser_gen
0062 {
0063 template <typename ParserT>
0064 struct result {
0065
0066 typedef contiguous<ParserT> type;
0067 };
0068
0069 template <typename ParserT>
0070 static contiguous<ParserT>
0071 generate(parser<ParserT> const& subject)
0072 {
0073 return contiguous<ParserT>(subject.derived());
0074 }
0075
0076 template <typename ParserT>
0077 contiguous<ParserT>
0078 operator[](parser<ParserT> const& subject) const
0079 {
0080 return contiguous<ParserT>(subject.derived());
0081 }
0082 };
0083
0084
0085 const lexeme_parser_gen lexeme_d = lexeme_parser_gen();
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096 template <typename ScannerT>
0097 struct lexeme_scanner
0098 {
0099 typedef scanner_policies<
0100 no_skipper_iteration_policy<
0101 typename ScannerT::iteration_policy_t>,
0102 typename ScannerT::match_policy_t,
0103 typename ScannerT::action_policy_t
0104 > policies_t;
0105
0106 typedef typename
0107 rebind_scanner_policies<ScannerT, policies_t>::type type;
0108 };
0109
0110
0111
0112
0113
0114
0115 template <typename BaseT>
0116 struct inhibit_case_iteration_policy : public BaseT
0117 {
0118 typedef BaseT base_t;
0119
0120 inhibit_case_iteration_policy()
0121 : BaseT() {}
0122
0123 template <typename PolicyT>
0124 inhibit_case_iteration_policy(PolicyT const& other)
0125 : BaseT(other) {}
0126
0127 template <typename CharT>
0128 CharT filter(CharT ch) const
0129 { return impl::tolower_(ch); }
0130 };
0131
0132
0133
0134
0135
0136
0137 struct inhibit_case_parser_gen;
0138
0139 template <typename ParserT>
0140 struct inhibit_case
0141 : public unary<ParserT, parser<inhibit_case<ParserT> > >
0142 {
0143 typedef inhibit_case<ParserT> self_t;
0144 typedef unary_parser_category parser_category_t;
0145 typedef inhibit_case_parser_gen parser_generator_t;
0146 typedef unary<ParserT, parser<self_t> > base_t;
0147
0148 template <typename ScannerT>
0149 struct result
0150 {
0151 typedef typename parser_result<ParserT, ScannerT>::type type;
0152 };
0153
0154 inhibit_case(ParserT const& p)
0155 : base_t(p) {}
0156
0157 template <typename ScannerT>
0158 typename parser_result<self_t, ScannerT>::type
0159 parse(ScannerT const& scan) const
0160 {
0161 typedef typename parser_result<self_t, ScannerT>::type result_t;
0162 return impl::inhibit_case_parser_parse<result_t>
0163 (this->subject(), scan, scan);
0164 }
0165 };
0166
0167 template <int N>
0168 struct inhibit_case_parser_gen_base
0169 {
0170
0171
0172
0173
0174
0175 static inhibit_case<strlit<char const*> >
0176 generate(char const* str)
0177 { return inhibit_case<strlit<char const*> >(str); }
0178
0179 static inhibit_case<strlit<wchar_t const*> >
0180 generate(wchar_t const* str)
0181 { return inhibit_case<strlit<wchar_t const*> >(str); }
0182
0183 static inhibit_case<chlit<char> >
0184 generate(char ch)
0185 { return inhibit_case<chlit<char> >(ch); }
0186
0187 static inhibit_case<chlit<wchar_t> >
0188 generate(wchar_t ch)
0189 { return inhibit_case<chlit<wchar_t> >(ch); }
0190
0191 template <typename ParserT>
0192 static inhibit_case<ParserT>
0193 generate(parser<ParserT> const& subject)
0194 { return inhibit_case<ParserT>(subject.derived()); }
0195
0196 inhibit_case<strlit<char const*> >
0197 operator[](char const* str) const
0198 { return inhibit_case<strlit<char const*> >(str); }
0199
0200 inhibit_case<strlit<wchar_t const*> >
0201 operator[](wchar_t const* str) const
0202 { return inhibit_case<strlit<wchar_t const*> >(str); }
0203
0204 inhibit_case<chlit<char> >
0205 operator[](char ch) const
0206 { return inhibit_case<chlit<char> >(ch); }
0207
0208 inhibit_case<chlit<wchar_t> >
0209 operator[](wchar_t ch) const
0210 { return inhibit_case<chlit<wchar_t> >(ch); }
0211
0212 template <typename ParserT>
0213 inhibit_case<ParserT>
0214 operator[](parser<ParserT> const& subject) const
0215 { return inhibit_case<ParserT>(subject.derived()); }
0216 };
0217
0218
0219 struct inhibit_case_parser_gen : public inhibit_case_parser_gen_base<0>
0220 {
0221 inhibit_case_parser_gen() {}
0222 };
0223
0224
0225
0226 const inhibit_case_parser_gen nocase_d = inhibit_case_parser_gen();
0227
0228
0229 const inhibit_case_parser_gen as_lower_d = inhibit_case_parser_gen();
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240 template <typename ScannerT>
0241 struct as_lower_scanner
0242 {
0243 typedef scanner_policies<
0244 inhibit_case_iteration_policy<
0245 typename ScannerT::iteration_policy_t>,
0246 typename ScannerT::match_policy_t,
0247 typename ScannerT::action_policy_t
0248 > policies_t;
0249
0250 typedef typename
0251 rebind_scanner_policies<ScannerT, policies_t>::type type;
0252 };
0253
0254
0255
0256
0257
0258
0259 struct longest_parser_gen;
0260
0261 template <typename A, typename B>
0262 struct longest_alternative
0263 : public binary<A, B, parser<longest_alternative<A, B> > >
0264 {
0265 typedef longest_alternative<A, B> self_t;
0266 typedef binary_parser_category parser_category_t;
0267 typedef longest_parser_gen parser_generator_t;
0268 typedef binary<A, B, parser<self_t> > base_t;
0269
0270 longest_alternative(A const& a, B const& b)
0271 : base_t(a, b) {}
0272
0273 template <typename ScannerT>
0274 typename parser_result<self_t, ScannerT>::type
0275 parse(ScannerT const& scan) const
0276 {
0277 typedef typename parser_result<self_t, ScannerT>::type result_t;
0278 typename ScannerT::iterator_t save = scan.first;
0279 result_t l = this->left().parse(scan);
0280 std::swap(scan.first, save);
0281 result_t r = this->right().parse(scan);
0282
0283 if (l || r)
0284 {
0285 if (l.length() > r.length())
0286 {
0287 scan.first = save;
0288 return l;
0289 }
0290 return r;
0291 }
0292
0293 return scan.no_match();
0294 }
0295 };
0296
0297 struct longest_parser_gen
0298 {
0299 template <typename A, typename B>
0300 struct result {
0301
0302 typedef typename
0303 impl::to_longest_alternative<alternative<A, B> >::result_t
0304 type;
0305 };
0306
0307 template <typename A, typename B>
0308 static typename
0309 impl::to_longest_alternative<alternative<A, B> >::result_t
0310 generate(alternative<A, B> const& alt)
0311 {
0312 return impl::to_longest_alternative<alternative<A, B> >::
0313 convert(alt);
0314 }
0315
0316
0317 template <typename A, typename B>
0318 static
0319 longest_alternative<A, B>
0320 generate(A const &left, B const &right)
0321 {
0322 return longest_alternative<A, B>(left, right);
0323 }
0324
0325 template <typename A, typename B>
0326 typename impl::to_longest_alternative<alternative<A, B> >::result_t
0327 operator[](alternative<A, B> const& alt) const
0328 {
0329 return impl::to_longest_alternative<alternative<A, B> >::
0330 convert(alt);
0331 }
0332 };
0333
0334 const longest_parser_gen longest_d = longest_parser_gen();
0335
0336
0337
0338
0339
0340
0341 struct shortest_parser_gen;
0342
0343 template <typename A, typename B>
0344 struct shortest_alternative
0345 : public binary<A, B, parser<shortest_alternative<A, B> > >
0346 {
0347 typedef shortest_alternative<A, B> self_t;
0348 typedef binary_parser_category parser_category_t;
0349 typedef shortest_parser_gen parser_generator_t;
0350 typedef binary<A, B, parser<self_t> > base_t;
0351
0352 shortest_alternative(A const& a, B const& b)
0353 : base_t(a, b) {}
0354
0355 template <typename ScannerT>
0356 typename parser_result<self_t, ScannerT>::type
0357 parse(ScannerT const& scan) const
0358 {
0359 typedef typename parser_result<self_t, ScannerT>::type result_t;
0360 typename ScannerT::iterator_t save = scan.first;
0361 result_t l = this->left().parse(scan);
0362 std::swap(scan.first, save);
0363 result_t r = this->right().parse(scan);
0364
0365 if (l || r)
0366 {
0367 if ((l.length() < r.length() && l) || !r)
0368 {
0369 scan.first = save;
0370 return l;
0371 }
0372 return r;
0373 }
0374
0375 return scan.no_match();
0376 }
0377 };
0378
0379 struct shortest_parser_gen
0380 {
0381 template <typename A, typename B>
0382 struct result {
0383
0384 typedef typename
0385 impl::to_shortest_alternative<alternative<A, B> >::result_t
0386 type;
0387 };
0388
0389 template <typename A, typename B>
0390 static typename
0391 impl::to_shortest_alternative<alternative<A, B> >::result_t
0392 generate(alternative<A, B> const& alt)
0393 {
0394 return impl::to_shortest_alternative<alternative<A, B> >::
0395 convert(alt);
0396 }
0397
0398
0399 template <typename A, typename B>
0400 static
0401 shortest_alternative<A, B>
0402 generate(A const &left, B const &right)
0403 {
0404 return shortest_alternative<A, B>(left, right);
0405 }
0406
0407 template <typename A, typename B>
0408 typename impl::to_shortest_alternative<alternative<A, B> >::result_t
0409 operator[](alternative<A, B> const& alt) const
0410 {
0411 return impl::to_shortest_alternative<alternative<A, B> >::
0412 convert(alt);
0413 }
0414 };
0415
0416 const shortest_parser_gen shortest_d = shortest_parser_gen();
0417
0418
0419
0420
0421
0422
0423 template <typename BoundsT>
0424 struct min_bounded_gen;
0425
0426 template <typename ParserT, typename BoundsT>
0427 struct min_bounded
0428 : public unary<ParserT, parser<min_bounded<ParserT, BoundsT> > >
0429 {
0430 typedef min_bounded<ParserT, BoundsT> self_t;
0431 typedef unary_parser_category parser_category_t;
0432 typedef min_bounded_gen<BoundsT> parser_generator_t;
0433 typedef unary<ParserT, parser<self_t> > base_t;
0434
0435 template <typename ScannerT>
0436 struct result
0437 {
0438 typedef typename parser_result<ParserT, ScannerT>::type type;
0439 };
0440
0441 min_bounded(ParserT const& p, BoundsT const& min__)
0442 : base_t(p)
0443 , min_(min__) {}
0444
0445 template <typename ScannerT>
0446 typename parser_result<self_t, ScannerT>::type
0447 parse(ScannerT const& scan) const
0448 {
0449 typedef typename parser_result<self_t, ScannerT>::type result_t;
0450 result_t hit = this->subject().parse(scan);
0451 if (hit.has_valid_attribute() && hit.value() < min_)
0452 return scan.no_match();
0453 return hit;
0454 }
0455
0456 BoundsT min_;
0457 };
0458
0459 template <typename BoundsT>
0460 struct min_bounded_gen
0461 {
0462 min_bounded_gen(BoundsT const& min__)
0463 : min_(min__) {}
0464
0465 template <typename DerivedT>
0466 min_bounded<DerivedT, BoundsT>
0467 operator[](parser<DerivedT> const& p) const
0468 { return min_bounded<DerivedT, BoundsT>(p.derived(), min_); }
0469
0470 BoundsT min_;
0471 };
0472
0473 template <typename BoundsT>
0474 inline min_bounded_gen<BoundsT>
0475 min_limit_d(BoundsT const& min_)
0476 { return min_bounded_gen<BoundsT>(min_); }
0477
0478
0479
0480
0481
0482
0483 template <typename BoundsT>
0484 struct max_bounded_gen;
0485
0486 template <typename ParserT, typename BoundsT>
0487 struct max_bounded
0488 : public unary<ParserT, parser<max_bounded<ParserT, BoundsT> > >
0489 {
0490 typedef max_bounded<ParserT, BoundsT> self_t;
0491 typedef unary_parser_category parser_category_t;
0492 typedef max_bounded_gen<BoundsT> parser_generator_t;
0493 typedef unary<ParserT, parser<self_t> > base_t;
0494
0495 template <typename ScannerT>
0496 struct result
0497 {
0498 typedef typename parser_result<ParserT, ScannerT>::type type;
0499 };
0500
0501 max_bounded(ParserT const& p, BoundsT const& max__)
0502 : base_t(p)
0503 , max_(max__) {}
0504
0505 template <typename ScannerT>
0506 typename parser_result<self_t, ScannerT>::type
0507 parse(ScannerT const& scan) const
0508 {
0509 typedef typename parser_result<self_t, ScannerT>::type result_t;
0510 result_t hit = this->subject().parse(scan);
0511 if (hit.has_valid_attribute() && hit.value() > max_)
0512 return scan.no_match();
0513 return hit;
0514 }
0515
0516 BoundsT max_;
0517 };
0518
0519 template <typename BoundsT>
0520 struct max_bounded_gen
0521 {
0522 max_bounded_gen(BoundsT const& max__)
0523 : max_(max__) {}
0524
0525 template <typename DerivedT>
0526 max_bounded<DerivedT, BoundsT>
0527 operator[](parser<DerivedT> const& p) const
0528 { return max_bounded<DerivedT, BoundsT>(p.derived(), max_); }
0529
0530 BoundsT max_;
0531 };
0532
0533
0534 template <typename BoundsT>
0535 inline max_bounded_gen<BoundsT>
0536 max_limit_d(BoundsT const& max_)
0537 { return max_bounded_gen<BoundsT>(max_); }
0538
0539
0540
0541
0542
0543
0544 template <typename BoundsT>
0545 struct bounded_gen;
0546
0547 template <typename ParserT, typename BoundsT>
0548 struct bounded
0549 : public unary<ParserT, parser<bounded<ParserT, BoundsT> > >
0550 {
0551 typedef bounded<ParserT, BoundsT> self_t;
0552 typedef unary_parser_category parser_category_t;
0553 typedef bounded_gen<BoundsT> parser_generator_t;
0554 typedef unary<ParserT, parser<self_t> > base_t;
0555
0556 template <typename ScannerT>
0557 struct result
0558 {
0559 typedef typename parser_result<ParserT, ScannerT>::type type;
0560 };
0561
0562 bounded(ParserT const& p, BoundsT const& min__, BoundsT const& max__)
0563 : base_t(p)
0564 , min_(min__)
0565 , max_(max__) {}
0566
0567 template <typename ScannerT>
0568 typename parser_result<self_t, ScannerT>::type
0569 parse(ScannerT const& scan) const
0570 {
0571 typedef typename parser_result<self_t, ScannerT>::type result_t;
0572 result_t hit = this->subject().parse(scan);
0573 if (hit.has_valid_attribute() &&
0574 (hit.value() < min_ || hit.value() > max_))
0575 return scan.no_match();
0576 return hit;
0577 }
0578
0579 BoundsT min_, max_;
0580 };
0581
0582 template <typename BoundsT>
0583 struct bounded_gen
0584 {
0585 bounded_gen(BoundsT const& min__, BoundsT const& max__)
0586 : min_(min__)
0587 , max_(max__) {}
0588
0589 template <typename DerivedT>
0590 bounded<DerivedT, BoundsT>
0591 operator[](parser<DerivedT> const& p) const
0592 { return bounded<DerivedT, BoundsT>(p.derived(), min_, max_); }
0593
0594 BoundsT min_, max_;
0595 };
0596
0597 template <typename BoundsT>
0598 inline bounded_gen<BoundsT>
0599 limit_d(BoundsT const& min_, BoundsT const& max_)
0600 { return bounded_gen<BoundsT>(min_, max_); }
0601
0602 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0603
0604 }}
0605
0606 #endif
0607