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 #include <boost/config/warning_disable.hpp>
8 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/spirit/include/support_multi_pass.hpp>
11 #include <boost/spirit/include/classic_position_iterator.hpp>
12 #include <boost/spirit/include/lex_lexertl.hpp>
14 namespace spirit
= boost::spirit
;
15 namespace lex
= spirit::lex
;
17 typedef spirit::classic::position_iterator2
<
18 spirit::multi_pass
<std::istreambuf_iterator
<char> >
22 make_file_iterator(std::istream
& input
, const std::string
& filename
)
25 spirit::make_default_multi_pass(
26 std::istreambuf_iterator
<char>(input
)),
27 spirit::multi_pass
<std::istreambuf_iterator
<char> >(),
33 ID_WORD
= lex::min_token_id
+ 1,
37 typedef lex::lexertl::token
<
38 file_iterator
, boost::mpl::vector
<>, boost::mpl::true_
, token_id
42 : lex::lexer
<lex::lexertl::actor_lexer
<token_type
> >
44 lexer() : word("^[a-zA-Z0-9]+$", ID_WORD
)
46 typedef lex::token_def
<lex::unused_type
, char, token_id
> toked_def
;
48 self("INITIAL", "O") =
51 lex::_pass
= lex::pass_flags::pass_ignore
53 | toked_def('\n', ID_EOL
)
56 self("O", "INITIAL") =
58 lex::_pass
= lex::pass_flags::pass_fail
63 lex::token_def
<lex::unused_type
, char, token_id
> 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 token_id test_data
[] = { ID_EOL
, ID_WORD
, ID_EOL
};
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();