]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2003 Giovanni Bajo | |
3 | Copyright (c) 2003 Joel de Guzman | |
4 | Copyright (c) 2003 Vaclav Vesely | |
5 | http://spirit.sourceforge.net/ | |
6 | ||
7 | Use, modification and distribution is subject to the Boost Software | |
8 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
9 | http://www.boost.org/LICENSE_1_0.txt) | |
10 | =============================================================================*/ | |
7c673cae FG |
11 | #include <boost/spirit/include/classic_core.hpp> |
12 | #include <boost/spirit/include/classic_assign_actor.hpp> | |
13 | ||
1e59de90 TL |
14 | #include <boost/core/lightweight_test.hpp> |
15 | ||
16 | #ifdef _MSC_VER | |
17 | // bogus https://developercommunity.visualstudio.com/t/buggy-warning-c4709/471956 | |
18 | # pragma warning(disable: 4709) // comma operator within array index expression | |
19 | #endif | |
20 | ||
7c673cae FG |
21 | using namespace boost; |
22 | using namespace BOOST_SPIRIT_CLASSIC_NS; | |
7c673cae FG |
23 | |
24 | /////////////////////////////////////////////////////////////////////////////// | |
25 | // | |
26 | // bug_001 | |
27 | // | |
28 | // access_node_d[] and access_match_d[] iterator bug | |
29 | // http://sf.net/mailarchive/forum.php?thread_id=1963157&forum_id=1595 | |
30 | // http://sf.net/mailarchive/forum.php?thread_id=1966224&forum_id=1595 | |
31 | // | |
32 | /////////////////////////////////////////////////////////////////////////////// | |
33 | #include <boost/spirit/include/classic_ast.hpp> | |
34 | ||
35 | struct my_action | |
36 | { | |
37 | template <typename TreeT, typename IterT> | |
38 | void operator()(TreeT& /*t*/, IterT begin, IterT end) const | |
39 | { | |
40 | BOOST_TEST(*begin == '1'); | |
41 | BOOST_TEST(*end == '2'); | |
42 | } | |
43 | }; | |
44 | ||
45 | void bug_001() | |
46 | { | |
47 | const char* text = "123"; | |
48 | ||
49 | ast_parse(text, text+3, access_node_d[chlit<>('1')][my_action()]); | |
50 | ast_parse(text, text+3, access_match_d[chlit<>('1')][my_action()]); | |
51 | } | |
52 | ||
53 | /////////////////////////////////////////////////////////////////////////////// | |
54 | // | |
55 | // bug_001 | |
56 | // | |
57 | // mismatch closure return type bug | |
58 | // http://article.gmane.org/gmane.comp.parsers.spirit.general/3678 | |
59 | // | |
60 | /////////////////////////////////////////////////////////////////////////////// | |
61 | #include <boost/spirit/include/classic_attribute.hpp> | |
62 | #include <string> | |
63 | ||
64 | typedef std::string member_type; | |
65 | ||
66 | struct my_closure: closure<my_closure, member_type> | |
67 | { | |
68 | member1 val; | |
69 | }; | |
70 | ||
71 | void bug_002() | |
72 | { | |
73 | rule<scanner<char const*>, my_closure::context_t> my_rule = real_p; | |
74 | BOOST_TEST(parse("1", my_rule).full); | |
75 | } | |
76 | ||
77 | /////////////////////////////////////////////////////////////////////////////// | |
78 | // | |
79 | // bug_003 | |
80 | // | |
81 | // impl::detach_clear bug | |
82 | // http://sourceforge.net/mailarchive/forum.php?thread_id=2008510&forum_id=25901 | |
83 | // | |
84 | /////////////////////////////////////////////////////////////////////////////// | |
85 | #include <boost/spirit/include/classic_chset.hpp> | |
86 | ||
87 | void bug_003() | |
88 | { | |
89 | chset<> set; | |
90 | set = 'a'; | |
91 | } | |
92 | ||
93 | /////////////////////////////////////////////////////////////////////////////// | |
94 | // | |
95 | // bug_004 | |
96 | // | |
97 | // chset<>::operator~(range<>) bug | |
98 | // operator&(chset<>, range<>) bug | |
99 | // operator&(range<>, chset<>) bug | |
100 | // | |
101 | /////////////////////////////////////////////////////////////////////////////// | |
102 | #include <boost/limits.hpp> | |
103 | #include <boost/spirit/include/classic_chset.hpp> | |
104 | ||
105 | void bug_004() | |
106 | { | |
11fdf7f2 TL |
107 | const char min = (std::numeric_limits<char>::min)(); |
108 | const char max = (std::numeric_limits<char>::max)(); | |
7c673cae FG |
109 | |
110 | { | |
111 | chset<> set(~range<>(min, max)); | |
112 | BOOST_TEST(set.test(min) == false); | |
113 | BOOST_TEST(set.test(min) == false); | |
114 | } | |
115 | ||
116 | { | |
117 | chset<> set(chset<>(anychar_p) & range<>(min, max)); | |
118 | BOOST_TEST(set.test(min) == true); | |
119 | BOOST_TEST(set.test(min) == true); | |
120 | } | |
121 | ||
122 | { | |
123 | chset<> set(range<>(min, max) & chset<>(anychar_p)); | |
124 | BOOST_TEST(set.test(min) == true); | |
125 | BOOST_TEST(set.test(min) == true); | |
126 | } | |
127 | } | |
128 | ||
129 | /////////////////////////////////////////////////////////////////////////////// | |
130 | // | |
131 | // bug_005 | |
132 | // | |
133 | // Most trailing space bug | |
134 | // http://article.gmane.org/gmane.comp.parsers.spirit.general/4029 | |
135 | // JDG: Oct 18, 2005. We shall revert to the previous behavior where | |
136 | // Post skips are not allowed. The reason is that | |
137 | // there is a valid use case where input is obtained | |
138 | // from cin and multi_pass which results in an infinite | |
139 | // loop while the post skipper waits for a whitespace. | |
140 | // For examples like below, the grammar must explicitly | |
141 | // include the post whitespace. One possible way is to | |
142 | // place an end_p at the end of the grammar. The end_p | |
143 | // will trigger the post-skip. | |
144 | // | |
145 | /////////////////////////////////////////////////////////////////////////////// | |
146 | #include <boost/spirit/include/classic_core.hpp> | |
147 | ||
7c673cae FG |
148 | using namespace boost; |
149 | using namespace spirit; | |
150 | ||
151 | void bug_005() | |
152 | { | |
153 | BOOST_TEST( | |
154 | parse(" aaaaaaaaa ", *ch_p('a') >> end_p, space_p).full | |
155 | ); | |
156 | ||
157 | BOOST_TEST( | |
158 | parse(" aaaaaaaaa ", lexeme_d[*ch_p('a')] >> end_p, space_p).full | |
159 | ); | |
160 | ||
161 | #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) | |
162 | // not sure why Code Warrior 9.5 does not recognize ch_p(' ') as the | |
163 | // same as space_p (see above) when the inputs are spaces. The | |
164 | // tests below are redundant anyway. | |
165 | #else | |
166 | ||
167 | BOOST_TEST( | |
168 | parse(" aaaaaaaaa ", *ch_p('a') >> end_p, ch_p(' ')).full | |
169 | ); | |
170 | ||
171 | BOOST_TEST( | |
172 | parse(" aaaaaaaaa ", lexeme_d[*ch_p('a')] >> end_p, ch_p(' ')).full | |
173 | ); | |
174 | ||
175 | #endif | |
176 | } | |
177 | ||
178 | /////////////////////////////////////////////////////////////////////////////// | |
179 | // | |
180 | // bug_006 | |
181 | // | |
182 | // confix bug | |
183 | // | |
184 | /////////////////////////////////////////////////////////////////////////////// | |
185 | #include <boost/limits.hpp> | |
186 | #include <boost/spirit/include/classic_confix.hpp> | |
187 | ||
188 | void bug_006() | |
189 | { | |
190 | BOOST_TEST(parse("#some comment", comment_p('#')).full); | |
191 | } | |
192 | ||
193 | /////////////////////////////////////////////////////////////////////////////// | |
194 | // | |
195 | // bug_007 | |
196 | // | |
197 | // handling of trailing whitespace bug (ast_parse/pt_parse related) | |
198 | // JDG: Oct 18, 2005. We shall revert to the previous behavior where | |
199 | // Post skips are not allowed. The reason is that | |
200 | // there is a valid use case where input is obtained | |
201 | // from cin and multi_pass which results in an infinite | |
202 | // loop while the post skipper waits for a whitespace. | |
203 | // For examples like below, the grammar must explicitly | |
204 | // include the post whitespace. One possible way is to | |
205 | // place an end_p at the end of the grammar. The end_p | |
206 | // will trigger the post-skip. | |
207 | // | |
208 | /////////////////////////////////////////////////////////////////////////////// | |
209 | #include <boost/spirit/include/classic_ast.hpp> | |
210 | #include <boost/spirit/include/classic_parse_tree.hpp> | |
211 | ||
212 | void bug_007() | |
213 | { | |
214 | BOOST_TEST(parse("test ", str_p("test") >> end_p, space_p).full); | |
215 | BOOST_TEST(pt_parse("test ", str_p("test") >> end_p, space_p).full); | |
216 | BOOST_TEST(ast_parse("test ", str_p("test") >> end_p, space_p).full); | |
217 | } | |
218 | ||
219 | /////////////////////////////////////////////////////////////////////////////// | |
220 | // | |
221 | // sf_bug_718903 | |
222 | // | |
223 | // see https://sourceforge.net/tracker/index.php | |
224 | // ?func=detail&aid=718903&group_id=28447&atid=393386 | |
225 | // | |
226 | /////////////////////////////////////////////////////////////////////////////// | |
227 | #include <boost/cstdlib.hpp> | |
228 | #include <boost/spirit/include/classic_chset.hpp> | |
229 | ||
230 | void sf_bug_718903() | |
231 | { | |
232 | empty_match_parser<chset<char> > | |
233 | e(epsilon_p(chset_p("abc"))); | |
234 | } | |
235 | ||
236 | /////////////////////////////////////////////////////////////////////////////// | |
237 | // | |
238 | // sf_bug_719322 | |
239 | // range_run bug | |
240 | // | |
241 | // see http://sourceforge.net/tracker/index.php | |
242 | // ?func=detail&aid=719322&group_id=28447&atid=393386 | |
243 | // | |
244 | /////////////////////////////////////////////////////////////////////////////// | |
245 | #include <boost/spirit/include/classic_basic_chset.hpp> | |
246 | ||
247 | void sf_bug_719322() | |
248 | { | |
249 | basic_chset<int> s; | |
250 | s.set(3, 3); | |
251 | s.set(1, 5); | |
252 | BOOST_TEST(s.test(5)); | |
253 | } | |
254 | ||
255 | /////////////////////////////////////////////////////////////////////////////// | |
256 | // | |
257 | // sf_bug_742038 | |
258 | // | |
259 | // see http://sf.net/tracker/ | |
260 | // ?func=detail&atid=393386&aid=742038&group_id=28447 | |
261 | // | |
262 | /////////////////////////////////////////////////////////////////////////////// | |
263 | #include <boost/spirit/include/classic_position_iterator.hpp> | |
264 | #include <boost/spirit/include/classic_file_iterator.hpp> | |
265 | #include <string> | |
266 | #include <fstream> | |
267 | #include <iostream> | |
1e59de90 | 268 | #include <boost/core/lightweight_test.hpp> |
7c673cae FG |
269 | #include <stdio.h> |
270 | ||
271 | template <typename IterT> | |
272 | void test_assign(IterT b, IterT e) | |
273 | { | |
274 | typedef scanner<IterT> scanner_t; | |
275 | ||
276 | #if (defined(__GNUC__) && defined(__MINGW32__)) \ | |
277 | || (defined(__GNUC__) && (__GNUC_MINOR__ < 20)) | |
278 | ||
279 | // There's a bug in g++3.x on MinGW that makes basic_string assert | |
280 | // when assigning from IterT [f, l) where IterT is a position_iterator. | |
281 | // This issue is discussed here: | |
282 | // | |
283 | // http://gcc.gnu.org/ml/libstdc++/2002-03/msg00196.html | |
284 | // | |
285 | // Aparently, this bug is only present on MinGW. I'm clueless as | |
286 | // to why this is so. Regressions on linux seem to be OK! :( | |
287 | // | |
288 | // With, g++3.1, assigning to basic_string from IterT [f, l) is a | |
289 | // compile error (a g++3.1 bug). | |
290 | // | |
291 | // In both cases above, we use a vector instead of a string. | |
292 | ||
293 | typedef std::vector<char> store; | |
294 | #else | |
295 | typedef std::string store; | |
296 | #endif | |
297 | ||
298 | store dst; | |
299 | rule<scanner_t> r = (*alpha_p)[assign_a(dst)]; | |
300 | ||
301 | parse(b, e, r); | |
302 | ||
303 | store::iterator d = dst.begin(); | |
304 | ||
305 | while (b != e) | |
306 | { | |
307 | if (*d != *b) | |
308 | BOOST_TEST(*d == *b); | |
309 | ++b; | |
310 | ++d; | |
311 | } | |
312 | } | |
313 | ||
314 | void sf_bug_742038() | |
315 | { | |
316 | std::string src = "abcdef"; | |
317 | const char* tmpfilename = "sf_bug_742038.tmp"; | |
318 | ||
319 | test_assign(src.begin(), src.end()); | |
320 | ||
321 | position_iterator<std::string::iterator> b(src.begin(), src.end(), ""); | |
322 | position_iterator<std::string::iterator> e; | |
323 | test_assign(b, e); | |
324 | ||
11fdf7f2 TL |
325 | { |
326 | std::fstream f(tmpfilename, std::ios::out); | |
327 | f << src; | |
328 | f.close(); | |
7c673cae | 329 | |
11fdf7f2 TL |
330 | file_iterator<> b1(tmpfilename); |
331 | file_iterator<> e1(b1.make_end()); | |
332 | test_assign(b1, e1); | |
333 | } | |
7c673cae | 334 | |
11fdf7f2 | 335 | std::remove(tmpfilename); |
7c673cae FG |
336 | } |
337 | ||
338 | /////////////////////////////////////////////////////////////////////////////// | |
339 | // | |
340 | // bug_009 | |
341 | // | |
342 | // limit_d bug | |
343 | // http://article.gmane.org/gmane.comp.parsers.spirit.devel/1891/ | |
344 | // | |
345 | /////////////////////////////////////////////////////////////////////////////// | |
346 | void | |
347 | bug_009() | |
348 | { | |
349 | parse( | |
350 | "test" | |
351 | , limit_d(1U, 10U)[uint_p] | str_p("test")); | |
352 | } | |
353 | ||
354 | int | |
355 | main() | |
356 | { | |
357 | bug_001(); | |
358 | bug_002(); | |
359 | bug_003(); | |
360 | bug_004(); | |
361 | bug_005(); | |
362 | bug_006(); | |
363 | bug_007(); | |
364 | bug_009(); | |
365 | ||
366 | sf_bug_718903(); | |
367 | sf_bug_719322(); | |
368 | sf_bug_742038(); | |
369 | ||
370 | return boost::report_errors(); | |
371 | } |