|
Boost-Commit : |
From: hartmut.kaiser_at_[hidden]
Date: 2008-07-08 11:21:30
Author: hkaiser
Date: 2008-07-08 11:21:30 EDT (Tue, 08 Jul 2008)
New Revision: 47226
URL: http://svn.boost.org/trac/boost/changeset/47226
Log:
Spirit: Added karma::eol generator
Added:
trunk/boost/spirit/home/karma/auxiliary/eol.hpp (contents, props changed)
trunk/libs/spirit/test/karma/eol.cpp (contents, props changed)
Text files modified:
trunk/boost/spirit/home/karma/auxiliary.hpp | 1 +
trunk/boost/spirit/home/karma/auxiliary/meta_grammar.hpp | 3 +++
2 files changed, 4 insertions(+), 0 deletions(-)
Modified: trunk/boost/spirit/home/karma/auxiliary.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/auxiliary.hpp (original)
+++ trunk/boost/spirit/home/karma/auxiliary.hpp 2008-07-08 11:21:30 EDT (Tue, 08 Jul 2008)
@@ -8,6 +8,7 @@
#include <boost/spirit/home/karma/auxiliary/none.hpp>
#include <boost/spirit/home/karma/auxiliary/eps.hpp>
+#include <boost/spirit/home/karma/auxiliary/eol.hpp>
#include <boost/spirit/home/karma/auxiliary/lazy.hpp>
#include <boost/spirit/home/karma/auxiliary/functor.hpp>
#include <boost/spirit/home/karma/auxiliary/functor_director.hpp>
Added: trunk/boost/spirit/home/karma/auxiliary/eol.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/karma/auxiliary/eol.hpp 2008-07-08 11:21:30 EDT (Tue, 08 Jul 2008)
@@ -0,0 +1,43 @@
+// Copyright (c) 2001-2008 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)
+
+#if !defined(BOOST_SPIRIT_KARMA_EOL_JUL_08_2008_1014AM)
+#define BOOST_SPIRIT_KARMA_EOL_JUL_08_2008_1014AM
+
+#include <boost/spirit/home/karma/domain.hpp>
+#include <boost/spirit/home/karma/delimit.hpp>
+#include <boost/spirit/home/support/unused.hpp>
+
+namespace boost { namespace spirit { namespace karma
+{
+ struct eol_generator
+ {
+ template <typename Component, typename Context, typename Unused>
+ struct attribute
+ {
+ typedef unused_type type;
+ };
+
+ template <typename Component, typename OutputIterator,
+ typename Context, typename Delimiter, typename Parameter>
+ static bool
+ generate(Component const& /*component*/, OutputIterator& sink,
+ Context& /*ctx*/, Delimiter const& d, Parameter const& /*param*/)
+ {
+ detail::generate_to(sink, '\n');
+ karma::delimit(sink, d); // always do post-delimiting
+ return true;
+ }
+
+ template <typename Component>
+ static std::string what(Component const&)
+ {
+ return "eol";
+ }
+ };
+
+}}}
+
+#endif
Modified: trunk/boost/spirit/home/karma/auxiliary/meta_grammar.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/auxiliary/meta_grammar.hpp (original)
+++ trunk/boost/spirit/home/karma/auxiliary/meta_grammar.hpp 2008-07-08 11:21:30 EDT (Tue, 08 Jul 2008)
@@ -24,6 +24,7 @@
///////////////////////////////////////////////////////////////////////////
struct none;
struct eps_generator;
+ struct eol_generator;
struct semantic_predicate;
struct lazy_generator;
struct functor_director;
@@ -45,6 +46,8 @@
karma::domain, tag::none, none>,
meta_grammar::empty_terminal_rule<
karma::domain, tag::eps, eps_generator>,
+ meta_grammar::empty_terminal_rule<
+ karma::domain, tag::eol, eol_generator>,
meta_grammar::function1_rule<
karma::domain, tag::eps, semantic_predicate>,
meta_grammar::function1_rule<
Added: trunk/libs/spirit/test/karma/eol.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/eol.cpp 2008-07-08 11:21:30 EDT (Tue, 08 Jul 2008)
@@ -0,0 +1,33 @@
+// Copyright (c) 2001-2008 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/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/karma_auxiliary.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+
+#include <iostream>
+#include "test.hpp"
+
+int
+main()
+{
+ using namespace spirit_test;
+ using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
+
+ {
+ BOOST_TEST((test("\n", eol)));
+ BOOST_TEST((test("\n", eol)));
+ }
+
+ {
+ BOOST_TEST((test_delimited("\n ", eol, space)));
+ BOOST_TEST((test_delimited("\n ", eol, space)));
+ }
+
+ return boost::report_errors();
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk