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/config/warning_disable.hpp>
12 #include <boost/detail/lightweight_test.hpp>
14 #include <boost/spirit/include/support_multi_pass.hpp>
15 #include <boost/spirit/include/classic_position_iterator.hpp>
16 #include <boost/spirit/include/lex_lexertl.hpp>
18 namespace spirit
= boost::spirit
;
19 namespace lex
= spirit::lex
;
21 typedef spirit::classic::position_iterator2
<
22 spirit::multi_pass
<std::istreambuf_iterator
<char> >
26 make_file_iterator(std::istream
& input
, const std::string
& filename
)
29 spirit::make_default_multi_pass(
30 std::istreambuf_iterator
<char>(input
)),
31 spirit::multi_pass
<std::istreambuf_iterator
<char> >(),
35 typedef lex::lexertl::token
<file_iterator
> token_type
;
38 : lex::lexer
<lex::lexertl::actor_lexer
<token_type
> >
40 lexer() : word("^[a-zA-Z0-9]+$", 1)
45 | lex::token_def
<>("!.*$") [
47 , lex::_pass
= lex::pass_flags::pass_ignore
49 | lex::token_def
<>('\n', 2) [
55 lex::token_def
<>(".") [
56 lex::_state
= "INITIAL"
57 , lex::_pass
= lex::pass_flags::pass_fail
62 lex::token_def
<> word
;
65 typedef lexer::iterator_type token_iterator
;
70 ss
<< "!foo\nbar\n!baz";
72 file_iterator begin
= make_file_iterator(ss
, "SS");
76 token_iterator begin2
= l
.begin(begin
, end
);
77 token_iterator end2
= l
.end();
79 std::size_t test_data
[] = { 2, 1, 2 };
80 std::size_t const test_data_size
= sizeof(test_data
)/sizeof(test_data
[0]);
82 token_iterator it
= begin2
;
84 for (/**/; it
!= end2
&& i
< test_data_size
; ++it
, ++i
)
86 BOOST_TEST(it
->id() == test_data
[i
]);
88 BOOST_TEST(it
== end2
);
89 BOOST_TEST(i
== test_data_size
);
91 return boost::report_errors();