Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:01:55

0001 /*=============================================================================
0002     Copyright (c) 1998-2003 Joel de Guzman
0003     http://spirit.sourceforge.net/
0004 
0005   Distributed under the Boost Software License, Version 1.0. (See accompanying
0006   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 =============================================================================*/
0008 #if !defined(BOOST_SPIRIT_SKIPPER_HPP)
0009 #define BOOST_SPIRIT_SKIPPER_HPP
0010 
0011 ///////////////////////////////////////////////////////////////////////////////
0012 #include <cctype>
0013 
0014 #include <boost/spirit/home/classic/namespace.hpp>
0015 #include <boost/spirit/home/classic/core/scanner/scanner.hpp>
0016 #include <boost/spirit/home/classic/core/primitives/impl/primitives.ipp>
0017 
0018 #include <boost/spirit/home/classic/core/scanner/skipper_fwd.hpp>
0019 
0020 namespace boost { namespace spirit {
0021 
0022 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0023 
0024     ///////////////////////////////////////////////////////////////////////////
0025     //
0026     //  skipper_iteration_policy class
0027     //
0028     ///////////////////////////////////////////////////////////////////////////
0029     template <typename BaseT>
0030     struct skipper_iteration_policy : public BaseT
0031     {
0032         typedef BaseT base_t;
0033     
0034         skipper_iteration_policy()
0035         : BaseT() {}
0036     
0037         template <typename PolicyT>
0038         skipper_iteration_policy(PolicyT const& other)
0039         : BaseT(other) {}
0040     
0041         template <typename ScannerT>
0042         void
0043         advance(ScannerT const& scan) const
0044         {
0045             BaseT::advance(scan);
0046             scan.skip(scan);
0047         }
0048     
0049         template <typename ScannerT>
0050         bool
0051         at_end(ScannerT const& scan) const
0052         {
0053             scan.skip(scan);
0054             return BaseT::at_end(scan);
0055         }
0056     
0057         template <typename ScannerT>
0058         void
0059         skip(ScannerT const& scan) const
0060         {
0061             while (!BaseT::at_end(scan) && impl::isspace_(BaseT::get(scan)))
0062                 BaseT::advance(scan);
0063         }
0064     };
0065     
0066     ///////////////////////////////////////////////////////////////////////////
0067     //
0068     //  no_skipper_iteration_policy class
0069     //
0070     ///////////////////////////////////////////////////////////////////////////
0071     template <typename BaseT>
0072     struct no_skipper_iteration_policy : public BaseT
0073     {
0074         typedef BaseT base_t;
0075 
0076         no_skipper_iteration_policy()
0077         : BaseT() {}
0078 
0079         template <typename PolicyT>
0080         no_skipper_iteration_policy(PolicyT const& other)
0081         : BaseT(other) {}
0082 
0083         template <typename ScannerT>
0084         void
0085         skip(ScannerT const& /*scan*/) const {}
0086     };
0087 
0088     ///////////////////////////////////////////////////////////////////////////
0089     //
0090     //  skip_parser_iteration_policy class
0091     //
0092     ///////////////////////////////////////////////////////////////////////////
0093     namespace impl
0094     {
0095         template <typename ST, typename ScannerT, typename BaseT>
0096         void
0097         skipper_skip(
0098             ST const& s,
0099             ScannerT const& scan,
0100             skipper_iteration_policy<BaseT> const&);
0101 
0102         template <typename ST, typename ScannerT, typename BaseT>
0103         void
0104         skipper_skip(
0105             ST const& s,
0106             ScannerT const& scan,
0107             no_skipper_iteration_policy<BaseT> const&);
0108 
0109         template <typename ST, typename ScannerT>
0110         void
0111         skipper_skip(
0112             ST const& s,
0113             ScannerT const& scan,
0114             iteration_policy const&);
0115     }
0116 
0117     template <typename ParserT, typename BaseT>
0118     class skip_parser_iteration_policy : public skipper_iteration_policy<BaseT>
0119     {
0120     public:
0121     
0122         typedef skipper_iteration_policy<BaseT> base_t;
0123     
0124         skip_parser_iteration_policy(
0125             ParserT const& skip_parser,
0126             base_t const& base = base_t())
0127         : base_t(base), subject(skip_parser) {}
0128     
0129         template <typename PolicyT>
0130         skip_parser_iteration_policy(PolicyT const& other)
0131         : base_t(other), subject(other.skipper()) {}
0132     
0133         template <typename ScannerT>
0134         void
0135         skip(ScannerT const& scan) const
0136         {
0137             impl::skipper_skip(subject, scan, scan);
0138         }
0139     
0140         ParserT const&
0141         skipper() const
0142         { 
0143             return subject; 
0144         }
0145     
0146     private:
0147     
0148         ParserT const& subject;
0149     };
0150     
0151     ///////////////////////////////////////////////////////////////////////////////
0152     //
0153     //  Free parse functions using the skippers
0154     //
0155     ///////////////////////////////////////////////////////////////////////////////
0156     template <typename IteratorT, typename ParserT, typename SkipT>
0157     parse_info<IteratorT>
0158     parse(
0159         IteratorT const&        first,
0160         IteratorT const&        last,
0161         parser<ParserT> const&  p,
0162         parser<SkipT> const&    skip);
0163     
0164     ///////////////////////////////////////////////////////////////////////////////
0165     //
0166     //  Parse function for null terminated strings using the skippers
0167     //
0168     ///////////////////////////////////////////////////////////////////////////////
0169     template <typename CharT, typename ParserT, typename SkipT>
0170     parse_info<CharT const*>
0171     parse(
0172         CharT const*            str,
0173         parser<ParserT> const&  p,
0174         parser<SkipT> const&    skip);
0175     
0176     ///////////////////////////////////////////////////////////////////////////////
0177     //
0178     //  phrase_scanner_t and wide_phrase_scanner_t
0179     //
0180     //      The most common scanners. Use these typedefs when you need
0181     //      a scanner that skips white spaces.
0182     //
0183     ///////////////////////////////////////////////////////////////////////////////
0184     typedef skipper_iteration_policy<>                  iter_policy_t;
0185     typedef scanner_policies<iter_policy_t>             scanner_policies_t;
0186     typedef scanner<char const*, scanner_policies_t>    phrase_scanner_t;
0187     typedef scanner<wchar_t const*, scanner_policies_t> wide_phrase_scanner_t;
0188     
0189     ///////////////////////////////////////////////////////////////////////////////
0190 
0191 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0192 
0193 }} // namespace BOOST_SPIRIT_CLASSIC_NS
0194 
0195 #include <boost/spirit/home/classic/core/scanner/impl/skipper.ipp>
0196 #endif
0197