1 | // Copyright (c) 2001-2010 Hartmut Kaiser |
---|---|
2 | // Copyright (c) 2009 Carl Barron |
3 | // |
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) |
6 | |
7 | #include <boost/spirit/include/lex_static_lexertl.hpp> |
8 | |
9 | #include <boost/core/lightweight_test.hpp> |
10 | #include <iostream> |
11 | #include <string> |
12 | #include <vector> |
13 | #include <exception> |
14 | |
15 | #include "matlib_static.h" |
16 | #include "matlib.h" |
17 | |
18 | void test_matrix(std::vector<std::vector<double> > const& x) |
19 | { |
20 | BOOST_TEST(x.size() == 3); |
21 | BOOST_TEST(x[0].size() == 2 && x[0][0] == 1 && x[0][1] == 2); |
22 | BOOST_TEST(x[1].size() == 1 && x[1][0] == 3); |
23 | BOOST_TEST(x[2].size() == 3 && x[2][0] == 4 && x[2][1] == 5 && x[2][2] == 6); |
24 | } |
25 | |
26 | int main() |
27 | { |
28 | std::string input("[[1,2][3][4,5,6]]"); |
29 | std::vector<std::vector<double> > results; |
30 | |
31 | typedef std::string::iterator iter; |
32 | typedef boost::spirit::lex::lexertl::static_actor_lexer< |
33 | boost::spirit::lex::lexertl::token<iter>, |
34 | boost::spirit::lex::lexertl::static_::lexer_matlib |
35 | > lexer_type; |
36 | |
37 | typedef matlib_tokens<lexer_type> matlib_type; |
38 | matlib_type matrix(results); |
39 | iter first = input.begin(); |
40 | |
41 | try { |
42 | BOOST_TEST(boost::spirit::lex::tokenize(first, input.end(), matrix)); |
43 | test_matrix(x: results); |
44 | } |
45 | catch (std::runtime_error const& e) { |
46 | std::cerr << e.what() << '\n'; |
47 | BOOST_TEST(false); |
48 | } |
49 | return boost::report_errors(); |
50 | } |
51 |