From 5963a39561cb48198a339c1256c1c67ada1262df Mon Sep 17 00:00:00 2001 From: Hartmut Kaiser Date: Thu, 30 Apr 2009 17:13:24 +0000 Subject: [PATCH] Spirit: Started to add repository of reusable Spirit components, added repository::karma::confix and some related tests [SVN r52686] --- include/boost/spirit/repository/karma.hpp | 17 +++ .../boost/spirit/repository/karma/confix.hpp | 128 ++++++++++++++++++ .../spirit/repository/support/confix.hpp | 22 +++ 3 files changed, 167 insertions(+) create mode 100644 include/boost/spirit/repository/karma.hpp create mode 100644 include/boost/spirit/repository/karma/confix.hpp create mode 100644 include/boost/spirit/repository/support/confix.hpp diff --git a/include/boost/spirit/repository/karma.hpp b/include/boost/spirit/repository/karma.hpp new file mode 100644 index 000000000..be5f0d07e --- /dev/null +++ b/include/boost/spirit/repository/karma.hpp @@ -0,0 +1,17 @@ +// Copyright (c) 2001-2009 Hartmut Kaiser +// Copyright (c) 2001-2009 Joel de Guzman +// +// 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(SPIRIT_REPOSITORY_KARMA_APR_28_2009_1259PM) +#define SPIRIT_REPOSITORY_KARMA_APR_28_2009_1259PM + +#if defined(_MSC_VER) +#pragma once +#endif + +#include + +#endif + diff --git a/include/boost/spirit/repository/karma/confix.hpp b/include/boost/spirit/repository/karma/confix.hpp new file mode 100644 index 000000000..b8776eba4 --- /dev/null +++ b/include/boost/spirit/repository/karma/confix.hpp @@ -0,0 +1,128 @@ +// Copyright (c) 2001-2009 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_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM) +#define BOOST_SPIRIT_REPOSITORY_KARMA_CONFIX_AUG_19_2008_1041AM + +#if defined(_MSC_VER) +#pragma once +#endif + +#include +#include +#include +#include +#include +#include + +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace boost { namespace spirit +{ + /////////////////////////////////////////////////////////////////////////// + // Enablers + /////////////////////////////////////////////////////////////////////////// + + // enables confix(..., ...)[] + template + struct use_directive > > + : mpl::true_ {}; + + // enables *lazy* confix(..., ...)[g] + template <> + struct use_lazy_directive + : mpl::true_ {}; + +}} + +/////////////////////////////////////////////////////////////////////////////// +namespace boost { namespace spirit { namespace repository { namespace karma +{ + using repository::confix_type; + using repository::confix; + + /////////////////////////////////////////////////////////////////////////// + // the director for a confix() generated generator + template + struct confix_generator + { + typedef Subject subject_type; + + template + struct attribute + { + typedef typename + traits::attribute_of::type + type; + }; + + confix_generator(Subject const& subject, Prefix const& prefix + , Suffix const& suffix) + : subject(subject), prefix(prefix), suffix(suffix) {} + + /////////////////////////////////////////////////////////////////////// + template + bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d + , Attribute const& attr) const + { + // generate the prefix, the embedded item and the suffix + return prefix.generate(sink, ctx, d, unused) && + subject.generate(sink, ctx, d, attr) && + suffix.generate(sink, ctx, d, unused); + } + + template + info what(Context const& ctx) const + { + return info("confix", subject.what(ctx)); + } + + Subject subject; + Prefix prefix; + Suffix suffix; + }; + +}}}} + +/////////////////////////////////////////////////////////////////////////////// +namespace boost { namespace spirit { namespace karma +{ + /////////////////////////////////////////////////////////////////////////// + // Generator generators: make_xxx function (objects) + /////////////////////////////////////////////////////////////////////////// + + // creates confix(..., ...)[] directive generator + template + struct make_directive< + terminal_ex > + , Subject, Modifiers> + { + typedef typename + result_of::compile::type + prefix_type; + typedef typename + result_of::compile::type + suffix_type; + + typedef repository::karma::confix_generator< + Subject, prefix_type, suffix_type> result_type; + + template + result_type operator()(Terminal const& term, Subject const& subject + , unused_type) const + { + return result_type(subject + , compile(fusion::at_c<0>(term.args)) + , compile(fusion::at_c<1>(term.args))); + } + }; + +}}} + +#endif diff --git a/include/boost/spirit/repository/support/confix.hpp b/include/boost/spirit/repository/support/confix.hpp new file mode 100644 index 000000000..e10e099c7 --- /dev/null +++ b/include/boost/spirit/repository/support/confix.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2001-2009 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_REPOSITORY_SUPPORT_CONFIX_APR_28_2009_0110PM) +#define BOOST_SPIRIT_REPOSITORY_SUPPORT_CONFIX_APR_28_2009_0110PM + +#if defined(_MSC_VER) +#pragma once +#endif + +#include + +namespace boost { namespace spirit { namespace repository +{ + // The confix extended terminal + BOOST_SPIRIT_DEFINE_TERMINALS_EX(( confix )) + +}}} + +#endif