sl@0: /*=============================================================================
sl@0:     Copyright (c) 2001-2003 Joel de Guzman
sl@0:     http://spirit.sourceforge.net/
sl@0: 
sl@0:     Use, modification and distribution is subject to the Boost Software
sl@0:     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
sl@0:     http://www.boost.org/LICENSE_1_0.txt)
sl@0: =============================================================================*/
sl@0: #ifndef BOOST_SPIRIT_PARAMETRIC_HPP
sl@0: #define BOOST_SPIRIT_PARAMETRIC_HPP
sl@0: 
sl@0: ///////////////////////////////////////////////////////////////////////////////
sl@0: #include <boost/spirit/core/parser.hpp>
sl@0: #include <boost/spirit/core/composite/composite.hpp>
sl@0: #include <boost/spirit/core/primitives/primitives.hpp>
sl@0: 
sl@0: namespace boost { namespace spirit {
sl@0: 
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     //
sl@0:     //  f_chlit class [ functional version of chlit ]
sl@0:     //
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     template <typename ChGenT>
sl@0:     struct f_chlit : public char_parser<f_chlit<ChGenT> >
sl@0:     {
sl@0:         f_chlit(ChGenT chgen_)
sl@0:         : chgen(chgen_) {}
sl@0: 
sl@0:         template <typename T>
sl@0:         bool test(T ch) const
sl@0:         { return ch == chgen(); }
sl@0: 
sl@0:         ChGenT   chgen;
sl@0:     };
sl@0: 
sl@0:     template <typename ChGenT>
sl@0:     inline f_chlit<ChGenT>
sl@0:     f_ch_p(ChGenT chgen)
sl@0:     { return f_chlit<ChGenT>(chgen); }
sl@0: 
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     //
sl@0:     //  f_range class [ functional version of range ]
sl@0:     //
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     template <typename ChGenAT, typename ChGenBT>
sl@0:     struct f_range : public char_parser<f_range<ChGenAT, ChGenBT> >
sl@0:     {
sl@0:         f_range(ChGenAT first_, ChGenBT last_)
sl@0:         : first(first_), last(last_)
sl@0:         {}
sl@0: 
sl@0:         template <typename T>
sl@0:         bool test(T ch) const
sl@0:         {
sl@0:             BOOST_SPIRIT_ASSERT(first() <= last());
sl@0:             return (ch >= first()) && (ch <= last());
sl@0:         }
sl@0: 
sl@0:         ChGenAT first;
sl@0:         ChGenBT last;
sl@0:     };
sl@0: 
sl@0:     template <typename ChGenAT, typename ChGenBT>
sl@0:     inline f_range<ChGenAT, ChGenBT>
sl@0:     f_range_p(ChGenAT first, ChGenBT last)
sl@0:     { return f_range<ChGenAT, ChGenBT>(first, last); }
sl@0: 
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     //
sl@0:     //  f_chseq class [ functional version of chseq ]
sl@0:     //
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     template <typename IterGenAT, typename IterGenBT>
sl@0:     class f_chseq : public parser<f_chseq<IterGenAT, IterGenBT> >
sl@0:     {
sl@0:     public:
sl@0: 
sl@0:         typedef f_chseq<IterGenAT, IterGenBT> self_t;
sl@0: 
sl@0:         f_chseq(IterGenAT first_, IterGenBT last_)
sl@0:         : first(first_), last(last_) {}
sl@0: 
sl@0:         template <typename ScannerT>
sl@0:         typename parser_result<self_t, ScannerT>::type
sl@0:         parse(ScannerT const& scan) const
sl@0:         {
sl@0:             typedef typename parser_result<self_t, ScannerT>::type result_t;
sl@0:             return impl::string_parser_parse<result_t>(first(), last(), scan);
sl@0:         }
sl@0: 
sl@0:     private:
sl@0: 
sl@0:         IterGenAT first;
sl@0:         IterGenBT last;
sl@0:     };
sl@0: 
sl@0:     template <typename IterGenAT, typename IterGenBT>
sl@0:     inline f_chseq<IterGenAT, IterGenBT>
sl@0:     f_chseq_p(IterGenAT first, IterGenBT last)
sl@0:     { return f_chseq<IterGenAT, IterGenBT>(first, last); }
sl@0: 
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     //
sl@0:     //  f_strlit class [ functional version of strlit ]
sl@0:     //
sl@0:     ///////////////////////////////////////////////////////////////////////////
sl@0:     template <typename IterGenAT, typename IterGenBT>
sl@0:     class f_strlit : public parser<f_strlit<IterGenAT, IterGenBT> >
sl@0:     {
sl@0:     public:
sl@0: 
sl@0:         typedef f_strlit<IterGenAT, IterGenBT> self_t;
sl@0: 
sl@0:         f_strlit(IterGenAT first, IterGenBT last)
sl@0:         : seq(first, last) {}
sl@0: 
sl@0:         template <typename ScannerT>
sl@0:         typename parser_result<self_t, ScannerT>::type
sl@0:         parse(ScannerT const& scan) const
sl@0:         {
sl@0:             typedef typename parser_result<self_t, ScannerT>::type result_t;
sl@0:             return impl::contiguous_parser_parse<result_t>
sl@0:                 (seq, scan, scan);
sl@0:         }
sl@0: 
sl@0:     private:
sl@0: 
sl@0:         f_chseq<IterGenAT, IterGenBT> seq;
sl@0:     };
sl@0: 
sl@0:     template <typename IterGenAT, typename IterGenBT>
sl@0:     inline f_strlit<IterGenAT, IterGenBT>
sl@0:     f_str_p(IterGenAT first, IterGenBT last)
sl@0:     { return f_strlit<IterGenAT, IterGenBT>(first, last); }
sl@0: 
sl@0: }} // namespace boost::spirit
sl@0: 
sl@0: #endif