]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/lex/regression_wide.cpp
1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 // Copyright (c) 2010 Sergey "GooRoo" Olendarenko
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/detail/lightweight_test.hpp>
8 #include <boost/config/warning_disable.hpp>
15 #include <boost/spirit/include/lex_lexertl.hpp>
16 #include <boost/spirit/include/phoenix_object.hpp>
17 #include <boost/spirit/include/phoenix_operator.hpp>
18 #include <boost/spirit/include/phoenix_statement.hpp>
19 #include <boost/spirit/include/phoenix_container.hpp>
21 namespace lex
= boost::spirit::lex
;
22 namespace phoenix
= boost::phoenix
;
24 typedef std::basic_string
<wchar_t> wstring_type
;
26 ///////////////////////////////////////////////////////////////////////////////
35 ///////////////////////////////////////////////////////////////////////////////
42 // alpha+x1*(2.836-x2[i])
45 { ID_IDENT
, L
"alpha" },
46 { ID_OPERATION
, L
"+" },
48 { ID_OPERATION
, L
"*" },
50 { ID_CONSTANT
, L
"2.836" },
51 { ID_OPERATION
, L
"-" },
59 ///////////////////////////////////////////////////////////////////////////////
62 typedef void result_type
;
63 template <typename TokenId
, typename Value
>
64 struct result
{ typedef void type
; };
66 template <typename TokenId
, typename Value
>
67 void operator()(TokenId
const& tokenid
, Value
const& val
) const
69 BOOST_TEST(sequence_counter
< sizeof(data
)/sizeof(data
[0]));
70 BOOST_TEST(data
[sequence_counter
].tokenid
== tokenid
);
71 BOOST_TEST(0 == val
.which());
73 typedef boost::iterator_range
<wstring_type::iterator
> iterator_range
;
74 iterator_range r
= boost::get
<iterator_range
>(val
);
75 BOOST_TEST(data
[sequence_counter
].value
==
76 wstring_type(r
.begin(), r
.end()));
81 static std::size_t sequence_counter
;
83 std::size_t test_impl::sequence_counter
= 0;
85 phoenix::function
<test_impl
> const test
= test_impl();
87 ///////////////////////////////////////////////////////////////////////////////
88 template <typename Lexer
>
89 struct mega_tokens
: lex::lexer
<Lexer
>
92 : identifier(L
"[a-zA-Z_][a-zA-Z0-9_]*", ID_IDENT
)
93 , constant (L
"[0-9]+(\\.[0-9]+)?", ID_CONSTANT
)
94 , operation (L
"[\\+\\-\\*/]", ID_OPERATION
)
95 , bracket (L
"[\\(\\)\\[\\]]", ID_BRACKET
)
101 = operation
[ test(_tokenid
, _val
) ]
102 | identifier
[ test(_tokenid
, _val
) ]
103 | constant
[ test(_tokenid
, _val
) ]
104 | bracket
[ test(_tokenid
, _val
) ]
108 lex::token_def
<wstring_type
, wchar_t, tokenids
> identifier
;
109 lex::token_def
<double, wchar_t, tokenids
> constant
;
110 lex::token_def
<wchar_t, wchar_t, tokenids
> operation
;
111 lex::token_def
<wchar_t, wchar_t, tokenids
> bracket
;
114 ///////////////////////////////////////////////////////////////////////////////
117 typedef wstring_type::iterator base_iterator
;
118 typedef lex::lexertl::token
<
119 base_iterator
, boost::mpl::vector
<wchar_t, wstring_type
, double>
120 , boost::mpl::true_
, tokenids
122 typedef lex::lexertl::actor_lexer
<token_type
> lexer_type
;
124 mega_tokens
<lexer_type
> mega_lexer
;
126 wstring_type exampleStr
= L
"alpha+x1*(2.836-x2[i])";
127 base_iterator first
= exampleStr
.begin();
129 BOOST_TEST(lex::tokenize(first
, exampleStr
.end(), mega_lexer
));
130 BOOST_TEST(test_impl::sequence_counter
== sizeof(data
)/sizeof(data
[0]));
132 return boost::report_errors();