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