Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*=============================================================================
0002     Copyright (c) 1998-2002 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_SCANNER_HPP)
0009 #define BOOST_SPIRIT_SCANNER_HPP
0010 
0011 #include <iterator>
0012 #include <boost/config.hpp>
0013 #include <boost/spirit/home/classic/namespace.hpp>
0014 #include <boost/spirit/home/classic/core/match.hpp>
0015 #include <boost/spirit/home/classic/core/non_terminal/parser_id.hpp>
0016 
0017 #include <boost/spirit/home/classic/core/scanner/scanner_fwd.hpp>
0018 
0019 namespace boost { namespace spirit {
0020 
0021 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
0022 
0023     ///////////////////////////////////////////////////////////////////////////
0024     //
0025     //  iteration_policy class
0026     //
0027     ///////////////////////////////////////////////////////////////////////////
0028     struct iteration_policy
0029     {
0030         template <typename ScannerT>
0031         void
0032         advance(ScannerT const& scan) const
0033         {
0034             ++scan.first;
0035         }
0036 
0037         template <typename ScannerT>
0038         bool at_end(ScannerT const& scan) const
0039         {
0040             return scan.first == scan.last;
0041         }
0042 
0043         template <typename T>
0044         T filter(T ch) const
0045         {
0046             return ch;
0047         }
0048 
0049         template <typename ScannerT>
0050         typename ScannerT::ref_t
0051         get(ScannerT const& scan) const
0052         {
0053             return *scan.first;
0054         }
0055     };
0056 
0057     ///////////////////////////////////////////////////////////////////////////
0058     //
0059     //  match_policy class
0060     //
0061     ///////////////////////////////////////////////////////////////////////////
0062     struct match_policy
0063     {
0064         template <typename T>
0065         struct result { typedef match<T> type; };
0066 
0067         const match<nil_t>
0068         no_match() const
0069         {
0070             return match<nil_t>();
0071         }
0072 
0073         const match<nil_t>
0074         empty_match() const
0075         {
0076             return match<nil_t>(0, nil_t());
0077         }
0078 
0079         template <typename AttrT, typename IteratorT>
0080         match<AttrT>
0081         create_match(
0082             std::size_t         length,
0083             AttrT const&        val,
0084             IteratorT const&    /*first*/,
0085             IteratorT const&    /*last*/) const
0086         {
0087             return match<AttrT>(length, val);
0088         }
0089 
0090         template <typename MatchT, typename IteratorT>
0091         void group_match(
0092             MatchT&             /*m*/,
0093             parser_id const&    /*id*/,
0094             IteratorT const&    /*first*/,
0095             IteratorT const&    /*last*/) const {}
0096 
0097         template <typename Match1T, typename Match2T>
0098         void concat_match(Match1T& l, Match2T const& r) const
0099         {
0100             l.concat(r);
0101         }
0102     };
0103 
0104     ///////////////////////////////////////////////////////////////////////////
0105     //
0106     //  match_result class
0107     //
0108     ///////////////////////////////////////////////////////////////////////////
0109     template <typename MatchPolicyT, typename T>
0110     struct match_result
0111     {
0112         typedef typename MatchPolicyT::template result<T>::type type;
0113     };
0114 
0115     ///////////////////////////////////////////////////////////////////////////
0116     //
0117     //  action_policy class
0118     //
0119     ///////////////////////////////////////////////////////////////////////////
0120     template <typename AttrT>
0121     struct attributed_action_policy
0122     {
0123         template <typename ActorT, typename IteratorT>
0124         static void
0125         call(
0126             ActorT const& actor,
0127             AttrT& val,
0128             IteratorT const&,
0129             IteratorT const&)
0130         {
0131             actor(val);
0132         }
0133     };
0134 
0135     //////////////////////////////////
0136     template <>
0137     struct attributed_action_policy<nil_t>
0138     {
0139         template <typename ActorT, typename IteratorT>
0140         static void
0141         call(
0142             ActorT const& actor,
0143             nil_t,
0144             IteratorT const& first,
0145             IteratorT const& last)
0146         {
0147             actor(first, last);
0148         }
0149     };
0150 
0151     //////////////////////////////////
0152     struct action_policy
0153     {
0154         template <typename ActorT, typename AttrT, typename IteratorT>
0155         void
0156         do_action(
0157             ActorT const&       actor,
0158             AttrT&              val,
0159             IteratorT const&    first,
0160             IteratorT const&    last) const
0161         {
0162             attributed_action_policy<AttrT>::call(actor, val, first, last);
0163         }
0164     };
0165 
0166     ///////////////////////////////////////////////////////////////////////////
0167     //
0168     //  scanner_policies class
0169     //
0170     ///////////////////////////////////////////////////////////////////////////
0171     template <
0172         typename IterationPolicyT,
0173         typename MatchPolicyT,
0174         typename ActionPolicyT>
0175     struct scanner_policies :
0176         public IterationPolicyT,
0177         public MatchPolicyT,
0178         public ActionPolicyT
0179     {
0180         typedef IterationPolicyT    iteration_policy_t;
0181         typedef MatchPolicyT        match_policy_t;
0182         typedef ActionPolicyT       action_policy_t;
0183 
0184         scanner_policies(
0185             IterationPolicyT const& i_policy = IterationPolicyT(),
0186             MatchPolicyT const&     m_policy = MatchPolicyT(),
0187             ActionPolicyT const&    a_policy = ActionPolicyT())
0188         : IterationPolicyT(i_policy)
0189         , MatchPolicyT(m_policy)
0190         , ActionPolicyT(a_policy) {}
0191 
0192         template <typename ScannerPoliciesT>
0193         scanner_policies(ScannerPoliciesT const& policies)
0194         : IterationPolicyT(policies)
0195         , MatchPolicyT(policies)
0196         , ActionPolicyT(policies) {}
0197     };
0198 
0199     ///////////////////////////////////////////////////////////////////////////
0200     //
0201     //  scanner_policies_base class: the base class of all scanners
0202     //
0203     ///////////////////////////////////////////////////////////////////////////
0204     struct scanner_base {};
0205 
0206     ///////////////////////////////////////////////////////////////////////////
0207     //
0208     //  scanner class
0209     //
0210     ///////////////////////////////////////////////////////////////////////////
0211     template <
0212         typename IteratorT,
0213         typename PoliciesT>
0214     class scanner : public PoliciesT, public scanner_base
0215     {
0216     public:
0217 
0218         typedef IteratorT iterator_t;
0219         typedef PoliciesT policies_t;
0220 
0221         typedef typename std::
0222             iterator_traits<IteratorT>::value_type value_t;
0223         typedef typename std::
0224             iterator_traits<IteratorT>::reference ref_t;
0225         typedef typename boost::
0226             call_traits<IteratorT>::param_type iter_param_t;
0227 
0228         scanner(
0229             IteratorT&          first_,
0230             iter_param_t        last_,
0231             PoliciesT const&    policies = PoliciesT())
0232         : PoliciesT(policies), first(first_), last(last_)
0233         {
0234             at_end();
0235         }
0236 
0237         scanner(scanner const& other)
0238         : PoliciesT(other), first(other.first), last(other.last) {}
0239 
0240         scanner(scanner const& other, IteratorT& first_)
0241         : PoliciesT(other), first(first_), last(other.last) {}
0242 
0243         template <typename PoliciesT1>
0244         scanner(scanner<IteratorT, PoliciesT1> const& other)
0245         : PoliciesT(other), first(other.first), last(other.last) {}
0246 
0247         bool
0248         at_end() const
0249         {
0250             typedef typename PoliciesT::iteration_policy_t iteration_policy_type;
0251             return iteration_policy_type::at_end(*this);
0252         }
0253 
0254         value_t
0255         operator*() const
0256         {
0257             typedef typename PoliciesT::iteration_policy_t iteration_policy_type;
0258             return iteration_policy_type::filter(iteration_policy_type::get(*this));
0259         }
0260 
0261         scanner const&
0262         operator++() const
0263         {
0264             typedef typename PoliciesT::iteration_policy_t iteration_policy_type;
0265             iteration_policy_type::advance(*this);
0266             return *this;
0267         }
0268 
0269         template <typename PoliciesT2>
0270         struct rebind_policies
0271         {
0272             typedef scanner<IteratorT, PoliciesT2> type;
0273         };
0274 
0275         template <typename PoliciesT2>
0276         scanner<IteratorT, PoliciesT2>
0277         change_policies(PoliciesT2 const& policies) const
0278         {
0279             return scanner<IteratorT, PoliciesT2>(first, last, policies);
0280         }
0281 
0282         template <typename IteratorT2>
0283         struct rebind_iterator
0284         {
0285             typedef scanner<IteratorT2, PoliciesT> type;
0286         };
0287 
0288         template <typename IteratorT2>
0289         scanner<IteratorT2, PoliciesT>
0290         change_iterator(IteratorT2 const& first_, IteratorT2 const &last_) const
0291         {
0292             return scanner<IteratorT2, PoliciesT>(first_, last_, *this);
0293         }
0294 
0295         IteratorT& first;
0296         IteratorT const last;
0297 
0298     private:
0299 
0300         scanner&
0301         operator=(scanner const& other);
0302     };
0303 
0304     ///////////////////////////////////////////////////////////////////////////
0305     //
0306     //  rebind_scanner_policies class
0307     //
0308     ///////////////////////////////////////////////////////////////////////////
0309     template <typename ScannerT, typename PoliciesT>
0310     struct rebind_scanner_policies
0311     {
0312         typedef typename ScannerT::template
0313             rebind_policies<PoliciesT>::type type;
0314     };
0315 
0316     //////////////////////////////////
0317     template <typename ScannerT, typename IteratorT>
0318     struct rebind_scanner_iterator
0319     {
0320         typedef typename ScannerT::template
0321             rebind_iterator<IteratorT>::type type;
0322     };
0323 
0324 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
0325 
0326 }}
0327 
0328 #endif