1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 // Copyright (c) 2010 Mathias Gaunard
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)
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
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>
15 #include <boost/core/lightweight_test.hpp>
16 #include <boost/phoenix/operator/self.hpp>
17 #include <boost/phoenix/statement/sequence.hpp>
19 namespace spirit
= boost::spirit
;
20 namespace lex
= spirit::lex
;
22 typedef spirit::classic::position_iterator2
<
23 spirit::multi_pass
<std::istreambuf_iterator
<char> >
27 make_file_iterator(std::istream
& input
, const std::string
& filename
)
30 spirit::make_default_multi_pass(
31 std::istreambuf_iterator
<char>(input
)),
32 spirit::multi_pass
<std::istreambuf_iterator
<char> >(),
36 typedef lex::lexertl::token
<file_iterator
> token_type
;
39 : lex::lexer
<lex::lexertl::actor_lexer
<token_type
> >
41 lexer() : word("^[a-zA-Z0-9]+$", 1)
46 | lex::token_def
<>("!.*$") [(
48 , lex::_pass
= lex::pass_flags::pass_ignore
50 | lex::token_def
<>('\n', 2) [
56 lex::token_def
<>(".") [(
57 lex::_state
= "INITIAL"
58 , lex::_pass
= lex::pass_flags::pass_fail
63 lex::token_def
<> word
;
66 typedef lexer::iterator_type token_iterator
;
71 ss
<< "!foo\nbar\n!baz";
73 file_iterator begin
= make_file_iterator(ss
, "SS");
77 token_iterator begin2
= l
.begin(begin
, end
);
78 token_iterator end2
= l
.end();
80 std::size_t test_data
[] = { 2, 1, 2 };
81 std::size_t const test_data_size
= sizeof(test_data
)/sizeof(test_data
[0]);
83 token_iterator it
= begin2
;
85 for (/**/; it
!= end2
&& i
< test_data_size
; ++it
, ++i
)
87 BOOST_TEST(it
->id() == test_data
[i
]);
89 BOOST_TEST(it
== end2
);
90 BOOST_TEST(i
== test_data_size
);
92 return boost::report_errors();