mirror of
https://github.com/boostorg/spirit.git
synced 2026-01-19 04:42:11 +00:00
It is better to manage warnings on our side to know what warnings we need to fix or suppress, and the only thing that header does is disabling deprecation warnings on MSVC and ICC which we would prefer to not show to users.
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
// Copyright (c) 2010 Olaf Peter
|
|
// Copyright (c) 2001-2010 Hartmut Kaiser
|
|
//
|
|
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
#include <boost/spirit/include/karma.hpp>
|
|
|
|
#include <boost/core/lightweight_test.hpp>
|
|
|
|
namespace client
|
|
{
|
|
namespace karma = boost::spirit::karma;
|
|
|
|
template <typename OutputIterator>
|
|
struct grammar
|
|
: karma::grammar<OutputIterator, boost::optional<double>()>
|
|
{
|
|
grammar()
|
|
: grammar::base_type(start)
|
|
{
|
|
using karma::double_;
|
|
|
|
u = double_ << "U";
|
|
start = ( !double_ << "NA" ) | u;
|
|
|
|
start.name("start");
|
|
u.name("u");
|
|
}
|
|
|
|
karma::rule<OutputIterator, double()> u;
|
|
karma::rule<OutputIterator, boost::optional<double>()> start;
|
|
};
|
|
}
|
|
|
|
int main()
|
|
{
|
|
namespace karma = boost::spirit::karma;
|
|
|
|
typedef std::back_insert_iterator<std::string> sink_type;
|
|
|
|
boost::optional<double> d1, d2;
|
|
d2 = 1.0;
|
|
|
|
std::string generated1, generated2;
|
|
client::grammar<sink_type> g;
|
|
|
|
BOOST_TEST(karma::generate(sink_type(generated1), g, d1) && generated1 == "NA");
|
|
BOOST_TEST(karma::generate(sink_type(generated2), g, d2) && generated2 == "1.0U");
|
|
|
|
return boost::report_errors();
|
|
}
|