1 /*=============================================================================
2 Copyright (c) 2001-2015 Joel de Guzman
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)
8 This test addresses the usage of boost::optional<foo> as an ast node.
9 =============================================================================*/
10 #include <boost/detail/lightweight_test.hpp>
11 #include <boost/spirit/home/x3.hpp>
12 #include <boost/fusion/adapted/struct.hpp>
13 #include <boost/fusion/include/vector.hpp>
28 boost::optional<twoints> b;
32 BOOST_FUSION_ADAPT_STRUCT(twoints, a, b)
33 BOOST_FUSION_ADAPT_STRUCT(adata, a, b, c)
39 // Duzy Chan: This case addresses the usage of boost::optional<foo>
40 // as an ast node. Which should actually test the ability of
41 // boost::spirit::x3::traits::move_to to handle with optional source
43 boost::spirit::x3::rule<class twoints, adata> top = "top";
44 boost::spirit::x3::rule<class twoints, boost::optional<twoints>>
47 using boost::spirit::x3::int_;
48 auto const top_def = twoints >> ',' >> -twoints >> ',' >> twoints;
49 auto const twoints_def = int_ >> int_;
51 BOOST_SPIRIT_DEFINE(top, twoints);
54 BOOST_TEST((test_attr("1 2,3 4,5 6", top, a)));
55 BOOST_TEST((a.a.a == 1 && a.a.b == 2));
56 BOOST_TEST((a.b && a.b->a == 3 && a.b->b == 4));
57 BOOST_TEST((a.c.a == 5 && a.c.b == 6));
59 BOOST_TEST((test_attr("1 2,,5 6", top), b));
60 BOOST_TEST((b.a.a == 1 && b.a.b == 2));
62 BOOST_TEST((b.c.a == 5 && b.c.b == 6));
65 return boost::report_errors();