no_delimit.hpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. #if !defined(BOOST_SPIRIT_KARMA_NO_DELIMIT_JAN_19_2010_0920AM)
  6. #define BOOST_SPIRIT_KARMA_NO_DELIMIT_JAN_19_2010_0920AM
  7. #if defined(_MSC_VER)
  8. #pragma once
  9. #endif
  10. #include <boost/spirit/home/karma/meta_compiler.hpp>
  11. #include <boost/spirit/home/karma/generator.hpp>
  12. #include <boost/spirit/home/karma/domain.hpp>
  13. #include <boost/spirit/home/karma/detail/unused_delimiter.hpp>
  14. #include <boost/spirit/home/karma/auxiliary/lazy.hpp>
  15. #include <boost/spirit/home/support/unused.hpp>
  16. #include <boost/spirit/home/support/common_terminals.hpp>
  17. #include <boost/spirit/home/support/has_semantic_action.hpp>
  18. #include <boost/spirit/home/support/handles_container.hpp>
  19. #include <boost/spirit/home/karma/detail/attributes.hpp>
  20. #include <boost/spirit/home/support/info.hpp>
  21. namespace boost { namespace spirit
  22. {
  23. ///////////////////////////////////////////////////////////////////////////
  24. // Enablers
  25. ///////////////////////////////////////////////////////////////////////////
  26. template <>
  27. struct use_directive<karma::domain, tag::no_delimit> // enables no_delimit[]
  28. : mpl::true_ {};
  29. }}
  30. namespace boost { namespace spirit { namespace karma
  31. {
  32. #ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
  33. using spirit::no_delimit;
  34. #endif
  35. using spirit::no_delimit_type;
  36. ///////////////////////////////////////////////////////////////////////////
  37. // The no_delimit generator is used for no_delimit[...] directives.
  38. ///////////////////////////////////////////////////////////////////////////
  39. template <typename Subject>
  40. struct no_delimit_generator
  41. : unary_generator<no_delimit_generator<Subject> >
  42. {
  43. typedef Subject subject_type;
  44. typedef typename subject_type::properties properties;
  45. template <typename Context, typename Iterator>
  46. struct attribute
  47. : traits::attribute_of<subject_type, Context, Iterator>
  48. {};
  49. no_delimit_generator(Subject const& subject)
  50. : subject(subject) {}
  51. template <typename OutputIterator, typename Context, typename Delimiter
  52. , typename Attribute>
  53. bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
  54. , Attribute const& attr) const
  55. {
  56. // the no_delimit generator simply dispatches to the embedded
  57. // generator while supplying unused_delimiter as the new delimiter
  58. // to avoid delimiting down the generator stream
  59. typedef detail::unused_delimiter<Delimiter> unused_delimiter;
  60. // the difference to verbatim[] is that this does not post-delimit
  61. return subject.generate(sink, ctx, unused_delimiter(d), attr);
  62. }
  63. template <typename Context>
  64. info what(Context& context) const
  65. {
  66. return info("no_delimit", subject.what(context));
  67. }
  68. Subject subject;
  69. };
  70. ///////////////////////////////////////////////////////////////////////////
  71. // Generator generators: make_xxx function (objects)
  72. ///////////////////////////////////////////////////////////////////////////
  73. template <typename Subject, typename Modifiers>
  74. struct make_directive<tag::no_delimit, Subject, Modifiers>
  75. {
  76. typedef no_delimit_generator<Subject> result_type;
  77. result_type
  78. operator()(unused_type, Subject const& subject, unused_type) const
  79. {
  80. return result_type(subject);
  81. }
  82. };
  83. }}}
  84. namespace boost { namespace spirit { namespace traits
  85. {
  86. ///////////////////////////////////////////////////////////////////////////
  87. template <typename Subject>
  88. struct has_semantic_action<karma::no_delimit_generator<Subject> >
  89. : unary_has_semantic_action<Subject> {};
  90. ///////////////////////////////////////////////////////////////////////////
  91. template <typename Subject, typename Attribute, typename Context
  92. , typename Iterator>
  93. struct handles_container<karma::no_delimit_generator<Subject>, Attribute
  94. , Context, Iterator>
  95. : unary_handles_container<Subject, Attribute, Context, Iterator> {};
  96. }}}
  97. #endif