source: NonGTP/Boost/boost/spirit/attribute/parametric.hpp @ 857

Revision 857, 4.5 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*=============================================================================
2    Copyright (c) 2001-2003 Joel de Guzman
3    http://spirit.sourceforge.net/
4
5    Use, modification and distribution is subject to the Boost Software
6    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7    http://www.boost.org/LICENSE_1_0.txt)
8=============================================================================*/
9#ifndef BOOST_SPIRIT_PARAMETRIC_HPP
10#define BOOST_SPIRIT_PARAMETRIC_HPP
11
12///////////////////////////////////////////////////////////////////////////////
13#include <boost/spirit/core/parser.hpp>
14#include <boost/spirit/core/composite/composite.hpp>
15#include <boost/spirit/core/primitives/primitives.hpp>
16
17namespace boost { namespace spirit {
18
19    ///////////////////////////////////////////////////////////////////////////
20    //
21    //  f_chlit class [ functional version of chlit ]
22    //
23    ///////////////////////////////////////////////////////////////////////////
24    template <typename ChGenT>
25    struct f_chlit : public char_parser<f_chlit<ChGenT> >
26    {
27        f_chlit(ChGenT chgen_)
28        : chgen(chgen_) {}
29
30        template <typename T>
31        bool test(T ch) const
32        { return ch == chgen(); }
33
34        ChGenT   chgen;
35    };
36
37    template <typename ChGenT>
38    inline f_chlit<ChGenT>
39    f_ch_p(ChGenT chgen)
40    { return f_chlit<ChGenT>(chgen); }
41
42    ///////////////////////////////////////////////////////////////////////////
43    //
44    //  f_range class [ functional version of range ]
45    //
46    ///////////////////////////////////////////////////////////////////////////
47    template <typename ChGenAT, typename ChGenBT>
48    struct f_range : public char_parser<f_range<ChGenAT, ChGenBT> >
49    {
50        f_range(ChGenAT first_, ChGenBT last_)
51        : first(first_), last(last_)
52        {}
53
54        template <typename T>
55        bool test(T ch) const
56        {
57            BOOST_SPIRIT_ASSERT(first() <= last());
58            return (ch >= first()) && (ch <= last());
59        }
60
61        ChGenAT first;
62        ChGenBT last;
63    };
64
65    template <typename ChGenAT, typename ChGenBT>
66    inline f_range<ChGenAT, ChGenBT>
67    f_range_p(ChGenAT first, ChGenBT last)
68    { return f_range<ChGenAT, ChGenBT>(first, last); }
69
70    ///////////////////////////////////////////////////////////////////////////
71    //
72    //  f_chseq class [ functional version of chseq ]
73    //
74    ///////////////////////////////////////////////////////////////////////////
75    template <typename IterGenAT, typename IterGenBT>
76    class f_chseq : public parser<f_chseq<IterGenAT, IterGenBT> >
77    {
78    public:
79
80        typedef f_chseq<IterGenAT, IterGenBT> self_t;
81
82        f_chseq(IterGenAT first_, IterGenBT last_)
83        : first(first_), last(last_) {}
84
85        template <typename ScannerT>
86        typename parser_result<self_t, ScannerT>::type
87        parse(ScannerT const& scan) const
88        {
89            typedef typename parser_result<self_t, ScannerT>::type result_t;
90            return impl::string_parser_parse<result_t>(first(), last(), scan);
91        }
92
93    private:
94
95        IterGenAT first;
96        IterGenBT last;
97    };
98
99    template <typename IterGenAT, typename IterGenBT>
100    inline f_chseq<IterGenAT, IterGenBT>
101    f_chseq_p(IterGenAT first, IterGenBT last)
102    { return f_chseq<IterGenAT, IterGenBT>(first, last); }
103
104    ///////////////////////////////////////////////////////////////////////////
105    //
106    //  f_strlit class [ functional version of strlit ]
107    //
108    ///////////////////////////////////////////////////////////////////////////
109    template <typename IterGenAT, typename IterGenBT>
110    class f_strlit : public parser<f_strlit<IterGenAT, IterGenBT> >
111    {
112    public:
113
114        typedef f_strlit<IterGenAT, IterGenBT> self_t;
115
116        f_strlit(IterGenAT first, IterGenBT last)
117        : seq(first, last) {}
118
119        template <typename ScannerT>
120        typename parser_result<self_t, ScannerT>::type
121        parse(ScannerT const& scan) const
122        {
123            typedef typename parser_result<self_t, ScannerT>::type result_t;
124            return impl::contiguous_parser_parse<result_t>
125                (seq, scan, scan);
126        }
127
128    private:
129
130        f_chseq<IterGenAT, IterGenBT> seq;
131    };
132
133    template <typename IterGenAT, typename IterGenBT>
134    inline f_strlit<IterGenAT, IterGenBT>
135    f_str_p(IterGenAT first, IterGenBT last)
136    { return f_strlit<IterGenAT, IterGenBT>(first, last); }
137
138}} // namespace boost::spirit
139
140#endif
Note: See TracBrowser for help on using the repository browser.