Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55516 - in trunk/boost/spirit: home/karma home/karma/char home/karma/detail home/support include
From: hartmut.kaiser_at_[hidden]
Date: 2009-08-10 20:55:22


Author: hkaiser
Date: 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
New Revision: 55516
URL: http://svn.boost.org/trac/boost/changeset/55516

Log:
Spirit: added Karma character class generators
Added:
   trunk/boost/spirit/home/karma/char/char_class.hpp (contents, props changed)
   trunk/boost/spirit/include/karma_char_class.hpp (contents, props changed)
Removed:
   trunk/boost/spirit/home/karma/char/space.hpp
Text files modified:
   trunk/boost/spirit/home/karma/char.hpp | 2 +-
   trunk/boost/spirit/home/karma/char/char.hpp | 3 +--
   trunk/boost/spirit/home/karma/detail/string_compare.hpp | 4 ++--
   trunk/boost/spirit/home/support/char_class.hpp | 28 ++++++++++++++++++++++++++++
   trunk/boost/spirit/home/support/common_terminals.hpp | 8 +++++---
   5 files changed, 37 insertions(+), 8 deletions(-)

Modified: trunk/boost/spirit/home/karma/char.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/char.hpp (original)
+++ trunk/boost/spirit/home/karma/char.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
@@ -11,6 +11,6 @@
 #endif
 
 #include <boost/spirit/home/karma/char/char.hpp>
-#include <boost/spirit/home/karma/char/space.hpp>
+#include <boost/spirit/home/karma/char/char_class.hpp>
 
 #endif

Modified: trunk/boost/spirit/home/karma/char/char.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/char/char.hpp (original)
+++ trunk/boost/spirit/home/karma/char/char.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
@@ -165,8 +165,7 @@
           , Attribute const& attr) const
         {
             // fail if attribute isn't matched my immediate literal
- typedef spirit::char_class::convert<char_encoding> convert_type;
- if (convert_type::to(Tag(), attr) != ch)
+ if (attr != ch)
                 return false;
 
             return karma::detail::generate_to(sink, ch) &&

Added: trunk/boost/spirit/home/karma/char/char_class.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/karma/char/char_class.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
@@ -0,0 +1,207 @@
+// 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_KARMA_CHAR_CLASS_AUG_10_2009_0720AM)
+#define BOOST_SPIRIT_KARMA_CHAR_CLASS_AUG_10_2009_0720AM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/support/common_terminals.hpp>
+#include <boost/spirit/home/support/string_traits.hpp>
+#include <boost/spirit/home/support/info.hpp>
+#include <boost/spirit/home/support/char_class.hpp>
+#include <boost/spirit/home/support/detail/get_encoding.hpp>
+#include <boost/spirit/home/karma/domain.hpp>
+#include <boost/spirit/home/karma/meta_compiler.hpp>
+#include <boost/spirit/home/karma/delimit_out.hpp>
+#include <boost/spirit/home/karma/auxiliary/lazy.hpp>
+#include <boost/spirit/home/karma/detail/get_casetag.hpp>
+#include <boost/spirit/home/karma/detail/generate_to.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+namespace boost { namespace spirit
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // Enablers
+ ///////////////////////////////////////////////////////////////////////////
+ // enables alnum, alpha, graph, etc.
+ template <typename CharClass, typename CharEncoding>
+ struct use_terminal<karma::domain
+ , tag::char_code<CharClass, CharEncoding> >
+ : mpl::true_ {};
+
+}}
+
+///////////////////////////////////////////////////////////////////////////////
+namespace boost { namespace spirit { namespace karma
+{
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // char_class
+ // generates a single character if it matches the given character
+ // class
+ //
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Tag>
+ struct char_class
+ : primitive_generator<char_class<Tag> >
+ {
+ typedef typename Tag::char_encoding char_encoding;
+ typedef typename char_encoding::char_type char_type;
+ typedef typename Tag::char_class classification;
+
+ template <typename Context, typename Unused>
+ struct attribute
+ {
+ typedef char_type type;
+ };
+
+ // char_class needs an attached attribute
+ template <
+ typename OutputIterator, typename Context, typename Delimiter
+ , typename Attribute>
+ static bool generate(OutputIterator& sink, Context&, Delimiter const& d
+ , Attribute const& attr)
+ {
+ using spirit::char_class::classify;
+ if (!classify<char_encoding>::is(classification(), attr))
+ return false; // allow proper character class only
+
+ return karma::detail::generate_to(sink, attr) &&
+ karma::delimit_out(sink, d); // always do post-delimiting
+ }
+
+ // char_class shouldn't be used without any associated attribute
+ template <typename OutputIterator, typename Context, typename Delimiter>
+ static bool generate(OutputIterator& sink, Context&, Delimiter const& d,
+ unused_type const&)
+ {
+ BOOST_SPIRIT_ASSERT_MSG(false
+ , char_class_not_usable_without_attribute, ());
+ return false;
+ }
+
+ template <typename Context>
+ static info what(Context const& ctx)
+ {
+ typedef spirit::char_class::what<char_encoding> what_;
+ return info(what_::is(classification()));
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ //
+ // space
+ // generates a single character from the associated parameter
+ //
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename CharEncoding>
+ struct any_space
+ : primitive_generator<any_space<CharEncoding> >
+ {
+ typedef typename CharEncoding::char_type char_type;
+ typedef CharEncoding char_encoding;
+
+ template <typename Context, typename Unused>
+ struct attribute
+ {
+ typedef char_type type;
+ };
+
+ // any_space has an attached parameter
+ template <
+ typename OutputIterator, typename Context, typename Delimiter
+ , typename Attribute>
+ static bool generate(OutputIterator& sink, Context&, Delimiter const& d
+ , Attribute const& attr)
+ {
+ using spirit::char_class::classify;
+ if (!classify<char_encoding>::is(tag::space(), attr))
+ return false; // allow whitespace only
+
+ return karma::detail::generate_to(sink, attr) &&
+ karma::delimit_out(sink, d); // always do post-delimiting
+ }
+
+ // any_space has no attribute attached, use single space character
+ template <typename OutputIterator, typename Context, typename Delimiter>
+ static bool generate(OutputIterator& sink, Context&, Delimiter const& d,
+ unused_type const&)
+ {
+ return karma::detail::generate_to(sink, ' ') &&
+ karma::delimit_out(sink, d); // always do post-delimiting
+ }
+
+ template <typename Context>
+ static info what(Context const& ctx)
+ {
+ return info("space");
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Generator generators: make_xxx function (objects)
+ ///////////////////////////////////////////////////////////////////////////
+
+ namespace detail
+ {
+ template <typename Tag, bool lower = false, bool upper = false>
+ struct make_char_class : mpl::identity<Tag> {};
+
+ template <>
+ struct make_char_class<tag::alpha, true, false>
+ : mpl::identity<tag::lower> {};
+
+ template <>
+ struct make_char_class<tag::alpha, false, true>
+ : mpl::identity<tag::upper> {};
+
+ template <>
+ struct make_char_class<tag::alnum, true, false>
+ : mpl::identity<tag::lowernum> {};
+
+ template <>
+ struct make_char_class<tag::alnum, false, true>
+ : mpl::identity<tag::uppernum> {};
+ }
+
+ // enables alnum, alpha, graph, etc.
+ template <typename CharClass, typename CharEncoding, typename Modifiers>
+ struct make_primitive<tag::char_code<CharClass, CharEncoding>, Modifiers>
+ {
+ static bool const lower =
+ has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
+ static bool const upper =
+ has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
+
+ typedef tag::char_code<
+ typename detail::make_char_class<CharClass, lower, upper>::type
+ , CharEncoding>
+ tag_type;
+
+ typedef char_class<tag_type> result_type;
+ result_type operator()(unused_type, unused_type) const
+ {
+ return result_type();
+ }
+ };
+
+ // space is special
+ template <typename CharEncoding, typename Modifiers>
+ struct make_primitive<tag::char_code<tag::space, CharEncoding>, Modifiers>
+ {
+ typedef any_space<CharEncoding> result_type;
+
+ result_type operator()(unused_type, unused_type) const
+ {
+ return result_type();
+ }
+ };
+
+}}} // namespace boost::spirit::karma
+
+#endif // !defined(BOOST_SPIRIT_KARMA_CHAR_FEB_21_2007_0543PM)

Deleted: trunk/boost/spirit/home/karma/char/space.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/char/space.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
+++ (empty file)
@@ -1,109 +0,0 @@
-// 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_KARMA_SPACE_MAR_06_2007_0934PM)
-#define BOOST_SPIRIT_KARMA_SPACE_MAR_06_2007_0934PM
-
-#if defined(_MSC_VER)
-#pragma once
-#endif
-
-#include <boost/spirit/home/support/common_terminals.hpp>
-#include <boost/spirit/home/support/string_traits.hpp>
-#include <boost/spirit/home/support/info.hpp>
-#include <boost/spirit/home/support/char_class.hpp>
-#include <boost/spirit/home/support/detail/get_encoding.hpp>
-#include <boost/spirit/home/karma/domain.hpp>
-#include <boost/spirit/home/karma/meta_compiler.hpp>
-#include <boost/spirit/home/karma/delimit_out.hpp>
-#include <boost/spirit/home/karma/auxiliary/lazy.hpp>
-#include <boost/spirit/home/karma/detail/get_casetag.hpp>
-#include <boost/spirit/home/karma/detail/generate_to.hpp>
-
-///////////////////////////////////////////////////////////////////////////////
-namespace boost { namespace spirit
-{
- ///////////////////////////////////////////////////////////////////////////
- // Enablers
- ///////////////////////////////////////////////////////////////////////////
- template <typename CharEncoding>
- struct use_terminal<karma::domain
- , tag::char_code<tag::space, CharEncoding> // enables space
- > : mpl::true_ {};
-
-}}
-
-///////////////////////////////////////////////////////////////////////////////
-namespace boost { namespace spirit { namespace karma
-{
- ///////////////////////////////////////////////////////////////////////////
- //
- // space
- // generates a single character from the associated parameter
- //
- ///////////////////////////////////////////////////////////////////////////
- template <typename CharEncoding>
- struct any_space
- : primitive_generator<any_space<CharEncoding> >
- {
- typedef typename CharEncoding::char_type char_type;
- typedef CharEncoding char_encoding;
-
- template <typename Context, typename Unused>
- struct attribute
- {
- typedef char_type type;
- };
-
- // any_space has an attached parameter
- template <
- typename OutputIterator, typename Context, typename Delimiter
- , typename Attribute>
- static bool generate(OutputIterator& sink, Context&, Delimiter const& d
- , Attribute const& attr)
- {
- if (!spirit::char_class::classify<char_encoding>::is(tag::space(), attr))
- return false; // allow whitespace only
-
- return
- karma::detail::generate_to(sink, attr) &&
- karma::delimit_out(sink, d); // always do post-delimiting
- }
-
- // any_space has no attribute attached, use single space character
- template <typename OutputIterator, typename Context, typename Delimiter>
- static bool generate(OutputIterator& sink, Context&, Delimiter const& d,
- unused_type const&)
- {
- return
- karma::detail::generate_to(sink, ' ') &&
- karma::delimit_out(sink, d); // always do post-delimiting
- }
-
- template <typename Context>
- static info what(Context const& ctx)
- {
- return info("space");
- }
- };
-
- ///////////////////////////////////////////////////////////////////////////
- // Generator generators: make_xxx function (objects)
- ///////////////////////////////////////////////////////////////////////////
- // space
- template <typename CharEncoding, typename Modifiers>
- struct make_primitive<tag::char_code<tag::space, CharEncoding>, Modifiers>
- {
- typedef any_space<CharEncoding> result_type;
-
- result_type operator()(unused_type, unused_type) const
- {
- return result_type();
- }
- };
-
-}}} // namespace boost::spirit::karma
-
-#endif // !defined(BOOST_SPIRIT_KARMA_CHAR_FEB_21_2007_0543PM)

Modified: trunk/boost/spirit/home/karma/detail/string_compare.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/detail/string_compare.hpp (original)
+++ trunk/boost/spirit/home/karma/detail/string_compare.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
@@ -50,7 +50,7 @@
     template <typename Char, typename CharEncoding, typename Tag>
     bool string_compare(Char const* attr, Char const* lit, CharEncoding ce, Tag tag)
     {
- Char ch_attr = spirit::char_class::convert<CharEncoding>::to(Tag(), *attr);
+ Char ch_attr = *attr;
         Char ch_lit = spirit::char_class::convert<CharEncoding>::to(Tag(), *lit);
 
         while (!!ch_lit && !!ch_attr)
@@ -58,7 +58,7 @@
             if (ch_attr != ch_lit)
                 return false;
 
- ch_attr = spirit::char_class::convert<CharEncoding>::to(Tag(), *++attr);
+ ch_attr = *++attr;
             ch_lit = spirit::char_class::convert<CharEncoding>::to(Tag(), *++lit);
         }
 

Modified: trunk/boost/spirit/home/support/char_class.hpp
==============================================================================
--- trunk/boost/spirit/home/support/char_class.hpp (original)
+++ trunk/boost/spirit/home/support/char_class.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
@@ -46,6 +46,8 @@
     struct no_case {};
     struct lower {};
     struct upper {};
+ struct lowernum {};
+ struct uppernum {};
     struct ucs4 {};
 
     ///////////////////////////////////////////////////////////////////////////
@@ -132,6 +134,14 @@
 
         template <typename Char>
         static bool
+ is(tag::lowernum, Char ch)
+ {
+ return CharEncoding::islower(char_type(ch)) ||
+ CharEncoding::isdigit(char_type(ch));
+ }
+
+ template <typename Char>
+ static bool
         is(tag::print, Char ch)
         {
             return CharEncoding::isprint(char_type(ch));
@@ -165,6 +175,14 @@
         {
             return CharEncoding::isupper(char_type(ch));
         }
+
+ template <typename Char>
+ static bool
+ is(tag::uppernum, Char ch)
+ {
+ return CharEncoding::isupper(char_type(ch)) ||
+ CharEncoding::isdigit(char_type(ch));
+ }
     };
 
     ///////////////////////////////////////////////////////////////////////////
@@ -248,6 +266,11 @@
             return "lower";
         }
 
+ static char const* is(tag::lowernum)
+ {
+ return "lowernum";
+ }
+
         static char const* is(tag::print)
         {
             return "print";
@@ -273,6 +296,11 @@
             return "upper";
         }
 
+ static char const* is(tag::uppernum)
+ {
+ return "uppernum";
+ }
+
         static char const* is(tag::ucs4)
         {
             return "ucs4";

Modified: trunk/boost/spirit/home/support/common_terminals.hpp
==============================================================================
--- trunk/boost/spirit/home/support/common_terminals.hpp (original)
+++ trunk/boost/spirit/home/support/common_terminals.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
@@ -95,12 +95,12 @@
     typedef spirit::terminal<tag::charset::char_> char_type; \
     char_type const char_ = char_type(); \
                                                                                 \
- inline void silence_unused_warnings__##char_() { (void) char_; } \
+ inline void silence_unused_warnings_##char_() { (void) char_; } \
                                                                                 \
     typedef spirit::terminal<tag::charset::string> string_type; \
     string_type const string = string_type(); \
                                                                                 \
- inline void silence_unused_warnings__##string() { (void) string; } \
+ inline void silence_unused_warnings_##string() { (void) string; } \
     /***/
 
 #define BOOST_SPIRIT_CHAR_CODE(name, charset) \
@@ -108,7 +108,7 @@
         name##_type; \
     name##_type const name = name##_type(); \
                                                                                 \
- inline void silence_unused_warnings__##name() { (void) name; } \
+ inline void silence_unused_warnings_##name() { (void) name; } \
     /***/
 
 #define BOOST_SPIRIT_DEFINE_CHAR_CODES(charset) \
@@ -134,6 +134,8 @@
         BOOST_SPIRIT_CHAR_CODE(no_case, spirit::char_encoding::charset) \
         BOOST_SPIRIT_CHAR_CODE(lower, spirit::char_encoding::charset) \
         BOOST_SPIRIT_CHAR_CODE(upper, spirit::char_encoding::charset) \
+ BOOST_SPIRIT_CHAR_CODE(lowernum, spirit::char_encoding::charset) \
+ BOOST_SPIRIT_CHAR_CODE(uppernum, spirit::char_encoding::charset) \
     }}} \
     /***/
 

Added: trunk/boost/spirit/include/karma_char_class.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/include/karma_char_class.hpp 2009-08-10 20:55:21 EDT (Mon, 10 Aug 2009)
@@ -0,0 +1,18 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 Hartmut Kaiser
+ http://spirit.sourceforge.net/
+
+ 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)
+=============================================================================*/
+#ifndef BOOST_SPIRIT_INCLUDE_KARMA_CHAR_CLASS
+#define BOOST_SPIRIT_INCLUDE_KARMA_CHAR_CLASS
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/karma/char/char_class.hpp>
+
+#endif


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