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_DEBUG 1 // required for token streaming
8 // #define BOOST_SPIRIT_LEXERTL_DEBUG 1
10 #include <boost/config/warning_disable.hpp>
11 #include <boost/detail/lightweight_test.hpp>
13 #include <boost/spirit/include/support_multi_pass.hpp>
14 #include <boost/spirit/include/classic_position_iterator.hpp>
15 #include <boost/spirit/include/lex_lexertl.hpp>
17 #include <boost/spirit/include/phoenix_core.hpp>
18 #include <boost/spirit/include/phoenix_operator.hpp>
19 #include <boost/spirit/include/phoenix_statement.hpp>
20 #include <boost/spirit/include/phoenix_object.hpp>
21 #include <boost/spirit/include/phoenix_stl.hpp>
25 namespace spirit
= boost::spirit
;
26 namespace lex
= spirit::lex
;
27 namespace phoenix
= boost::phoenix
;
29 typedef spirit::classic::position_iterator2
<
30 spirit::multi_pass
<std::istreambuf_iterator
<char> >
33 typedef boost::iterator_range
<file_iterator
> file_range
;
36 make_file_iterator(std::istream
& input
, const std::string
& filename
)
39 spirit::make_default_multi_pass(
40 std::istreambuf_iterator
<char>(input
)),
41 spirit::multi_pass
<std::istreambuf_iterator
<char> >(),
47 string_literal(file_iterator
, file_iterator
)
52 typedef lex::lexertl::token
<
53 file_iterator
, boost::mpl::vector
<string_literal
>
57 : lex::lexer
<lex::lexertl::actor_lexer
<token_type
> >
59 lexer() : st("'[^'\\n]*'", 1)
61 lex::token_def
<> string_lookahead('\'');
62 self("LA") = string_lookahead
;
64 // make sure lookahead is implicitly evaluated using the lexer state
65 // the token_def has been associated with
67 phoenix::if_(lex::lookahead(string_lookahead
)) [ lex::more() ]
72 lex::token_def
<string_literal
> st
;
75 typedef lexer::iterator_type token_iterator
;
82 file_iterator begin
= make_file_iterator(ss
, "SS");
86 token_iterator begin2
= l
.begin(begin
, end
);
87 token_iterator end2
= l
.end();
89 char const* test_data
[] = { "1,'foo'", "1,'foo''bar'" };
90 std::size_t const test_data_size
= sizeof(test_data
)/sizeof(test_data
[0]);
92 token_iterator it
= begin2
;
94 for (/**/; it
!= end2
&& i
< test_data_size
; ++it
, ++i
)
97 ss
<< it
->id() << "," << *it
;
98 BOOST_TEST(ss
.str() == test_data
[i
]);
100 BOOST_TEST(it
== end2
);
101 BOOST_TEST(i
== test_data_size
);
103 return boost::report_errors();