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/spirit/include/support_multi_pass.hpp>
8 #include <boost/spirit/include/classic_position_iterator.hpp>
9 #include <boost/spirit/include/lex_lexertl.hpp>
11 #include <boost/core/lightweight_test.hpp>
12 #include <boost/phoenix/operator/self.hpp>
13 #include <boost/phoenix/statement/sequence.hpp>
15 namespace spirit
= boost::spirit
;
16 namespace lex
= spirit::lex
;
18 typedef spirit::classic::position_iterator2
<
19 spirit::multi_pass
<std::istreambuf_iterator
<char> >
23 make_file_iterator(std::istream
& input
, const std::string
& filename
)
26 spirit::make_default_multi_pass(
27 std::istreambuf_iterator
<char>(input
)),
28 spirit::multi_pass
<std::istreambuf_iterator
<char> >(),
34 identifier(file_iterator
, file_iterator
)
41 string_literal(file_iterator
, file_iterator
)
46 typedef lex::lexertl::token
<
47 file_iterator
, boost::mpl::vector
<identifier
, string_literal
>
51 : lex::lexer
<lex::lexertl::actor_lexer
<token_type
> >
54 : id("[a-zA-Z0-9]+", 1)
60 | lex::token_def
<>(".", 3) [
67 lex::_state
= "INITIAL"
69 | lex::token_def
<>(".", 4) [(
70 lex::_state
= "INITIAL"
71 , lex::_pass
= lex::pass_flags::pass_fail
76 lex::token_def
<identifier
> id
;
77 lex::token_def
<string_literal
> st
;
80 typedef lexer::iterator_type token_iterator
;
87 file_iterator begin
= make_file_iterator(ss
, "SS");
91 token_iterator begin2
= l
.begin(begin
, end
, "ST");
92 token_iterator end2
= l
.end();
94 std::size_t test_data
[] = { 1, 3, 2 };
95 std::size_t const test_data_size
= sizeof(test_data
)/sizeof(test_data
[0]);
97 token_iterator it
= begin2
;
99 for (/**/; it
!= end2
&& i
< test_data_size
; ++it
, ++i
)
101 BOOST_TEST(it
->id() == test_data
[i
]);
103 BOOST_TEST(it
== end2
);
104 BOOST_TEST(i
== test_data_size
);
106 return boost::report_errors();