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 sl@0: #include sl@0: #include 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 sl@0: struct f_chlit : public char_parser > sl@0: { sl@0: f_chlit(ChGenT chgen_) sl@0: : chgen(chgen_) {} sl@0: sl@0: template 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 sl@0: inline f_chlit sl@0: f_ch_p(ChGenT chgen) sl@0: { return f_chlit(chgen); } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////// sl@0: // sl@0: // f_range class [ functional version of range ] sl@0: // sl@0: /////////////////////////////////////////////////////////////////////////// sl@0: template sl@0: struct f_range : public char_parser > sl@0: { sl@0: f_range(ChGenAT first_, ChGenBT last_) sl@0: : first(first_), last(last_) sl@0: {} sl@0: sl@0: template 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 sl@0: inline f_range sl@0: f_range_p(ChGenAT first, ChGenBT last) sl@0: { return f_range(first, last); } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////// sl@0: // sl@0: // f_chseq class [ functional version of chseq ] sl@0: // sl@0: /////////////////////////////////////////////////////////////////////////// sl@0: template sl@0: class f_chseq : public parser > sl@0: { sl@0: public: sl@0: sl@0: typedef f_chseq self_t; sl@0: sl@0: f_chseq(IterGenAT first_, IterGenBT last_) sl@0: : first(first_), last(last_) {} sl@0: sl@0: template sl@0: typename parser_result::type sl@0: parse(ScannerT const& scan) const sl@0: { sl@0: typedef typename parser_result::type result_t; sl@0: return impl::string_parser_parse(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 sl@0: inline f_chseq sl@0: f_chseq_p(IterGenAT first, IterGenBT last) sl@0: { return f_chseq(first, last); } sl@0: sl@0: /////////////////////////////////////////////////////////////////////////// sl@0: // sl@0: // f_strlit class [ functional version of strlit ] sl@0: // sl@0: /////////////////////////////////////////////////////////////////////////// sl@0: template sl@0: class f_strlit : public parser > sl@0: { sl@0: public: sl@0: sl@0: typedef f_strlit self_t; sl@0: sl@0: f_strlit(IterGenAT first, IterGenBT last) sl@0: : seq(first, last) {} sl@0: sl@0: template sl@0: typename parser_result::type sl@0: parse(ScannerT const& scan) const sl@0: { sl@0: typedef typename parser_result::type result_t; sl@0: return impl::contiguous_parser_parse sl@0: (seq, scan, scan); sl@0: } sl@0: sl@0: private: sl@0: sl@0: f_chseq seq; sl@0: }; sl@0: sl@0: template sl@0: inline f_strlit sl@0: f_str_p(IterGenAT first, IterGenBT last) sl@0: { return f_strlit(first, last); } sl@0: sl@0: }} // namespace boost::spirit sl@0: sl@0: #endif