1 // Copyright (c) 2001-2011 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 // #define BOOST_SPIRIT_LEXERTL_DEBUG
9 #include <boost/config/warning_disable.hpp>
10 #include <boost/detail/lightweight_test.hpp>
12 #include <boost/spirit/include/support_multi_pass.hpp>
13 #include <boost/spirit/include/classic_position_iterator.hpp>
14 #include <boost/spirit/include/lex_lexertl.hpp>
16 #include <boost/spirit/include/phoenix.hpp>
18 namespace spirit
= boost::spirit
;
19 namespace lex
= spirit::lex
;
20 namespace phoenix
= boost::phoenix
;
22 typedef spirit::classic::position_iterator2
<
23 spirit::multi_pass
<std::istreambuf_iterator
<char> >
26 typedef boost::iterator_range
<file_iterator
> file_range
;
29 make_file_iterator(std::istream
& input
, const std::string
& filename
)
32 spirit::make_default_multi_pass(
33 std::istreambuf_iterator
<char>(input
)),
34 spirit::multi_pass
<std::istreambuf_iterator
<char> >(),
40 identifier(file_iterator
, file_iterator
)
47 string_literal(file_iterator
, file_iterator
)
52 typedef lex::lexertl::token
<
53 file_iterator
, boost::mpl::vector
<identifier
, string_literal
>
57 : lex::lexer
<lex::lexertl::actor_lexer
<token_type
> >
60 : id("[a-zA-Z0-9]+", 1)
64 st
[ lex::_state
= "INITIAL" ]
68 id
[ lex::_state
= "ST" ]
69 | lex::token_def
<>(".", 3) [ lex::_state
= "ST" ]
73 lex::token_def
<identifier
> id
;
74 lex::token_def
<string_literal
> st
;
77 typedef lexer::iterator_type token_iterator
;
84 file_iterator begin
= make_file_iterator(ss
, "SS");
88 token_iterator begin2
= l
.begin(begin
, end
, "ST");
89 token_iterator end2
= l
.end();
91 std::size_t test_data
[] = { 1, 3, 2 };
92 std::size_t const test_data_size
= sizeof(test_data
)/sizeof(test_data
[0]);
94 token_iterator it
= begin2
;
96 for (/**/; it
!= end2
&& i
< test_data_size
; ++it
, ++i
)
98 BOOST_TEST(it
->id() == test_data
[i
]);
100 BOOST_TEST(it
== end2
);
101 BOOST_TEST(i
== test_data_size
);
103 return boost::report_errors();