]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/lex/regression_file_iterator4.cpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / libs / spirit / test / lex / regression_file_iterator4.cpp
1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 // Copyright (c) 2010 Mathias Gaunard
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 // This test makes sure that the BOL state (begin of line) is properly reset
8 // if a token matched at the beginning of a line is discarded using
9 // lex::pass_fail.
10
11 #include <boost/spirit/include/support_multi_pass.hpp>
12 #include <boost/spirit/include/classic_position_iterator.hpp>
13 #include <boost/spirit/include/lex_lexertl.hpp>
14
15 #include <boost/core/lightweight_test.hpp>
16 #include <boost/phoenix/operator/self.hpp>
17 #include <boost/phoenix/statement/sequence.hpp>
18
19 namespace spirit = boost::spirit;
20 namespace lex = spirit::lex;
21
22 typedef spirit::classic::position_iterator2<
23 spirit::multi_pass<std::istreambuf_iterator<char> >
24 > file_iterator;
25
26 inline file_iterator
27 make_file_iterator(std::istream& input, const std::string& filename)
28 {
29 return file_iterator(
30 spirit::make_default_multi_pass(
31 std::istreambuf_iterator<char>(input)),
32 spirit::multi_pass<std::istreambuf_iterator<char> >(),
33 filename);
34 }
35
36 typedef lex::lexertl::token<file_iterator> token_type;
37
38 struct lexer
39 : lex::lexer<lex::lexertl::actor_lexer<token_type> >
40 {
41 lexer() : word("^[a-zA-Z0-9]+$", 1)
42 {
43 self = word [
44 lex::_state = "O"
45 ]
46 | lex::token_def<>("!.*$") [(
47 lex::_state = "O"
48 , lex::_pass = lex::pass_flags::pass_ignore
49 )]
50 | lex::token_def<>('\n', 2) [
51 lex::_state = "O"
52 ]
53 ;
54
55 self("O") =
56 lex::token_def<>(".") [(
57 lex::_state = "INITIAL"
58 , lex::_pass = lex::pass_flags::pass_fail
59 )]
60 ;
61 }
62
63 lex::token_def<> word;
64 };
65
66 typedef lexer::iterator_type token_iterator;
67
68 int main()
69 {
70 std::stringstream ss;
71 ss << "!foo\nbar\n!baz";
72
73 file_iterator begin = make_file_iterator(ss, "SS");
74 file_iterator end;
75
76 lexer l;
77 token_iterator begin2 = l.begin(begin, end);
78 token_iterator end2 = l.end();
79
80 std::size_t test_data[] = { 2, 1, 2 };
81 std::size_t const test_data_size = sizeof(test_data)/sizeof(test_data[0]);
82
83 token_iterator it = begin2;
84 std::size_t i = 0;
85 for (/**/; it != end2 && i < test_data_size; ++it, ++i)
86 {
87 BOOST_TEST(it->id() == test_data[i]);
88 }
89 BOOST_TEST(it == end2);
90 BOOST_TEST(i == test_data_size);
91
92 return boost::report_errors();
93 }