|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56100 - in trunk/boost/spirit/home: karma/char karma/detail qi/char
From: hartmut.kaiser_at_[hidden]
Date: 2009-09-07 22:16:32
Author: hkaiser
Date: 2009-09-07 22:16:31 EDT (Mon, 07 Sep 2009)
New Revision: 56100
URL: http://svn.boost.org/trac/boost/changeset/56100
Log:
Spirit: Added character generator negation (unary '~' for character generators)
Text files modified:
trunk/boost/spirit/home/karma/char/char.hpp | 97 +++++++++++++--------------------------
trunk/boost/spirit/home/karma/char/char_class.hpp | 60 +++++++++++-------------
trunk/boost/spirit/home/karma/detail/get_casetag.hpp | 4 -
trunk/boost/spirit/home/qi/char/char_parser.hpp | 2
4 files changed, 63 insertions(+), 100 deletions(-)
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-09-07 22:16:31 EDT (Mon, 07 Sep 2009)
@@ -19,6 +19,7 @@
#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/char/char_generator.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>
@@ -97,11 +98,8 @@
///////////////////////////////////////////////////////////////////////////
template <typename CharEncoding, typename Tag>
struct any_char
- : primitive_generator<any_char<CharEncoding, Tag> >
+ : char_generator<any_char<CharEncoding, Tag>, CharEncoding, Tag>
{
- typedef typename CharEncoding::char_type char_type;
- typedef CharEncoding char_encoding;
-
template <typename Context, typename Unused>
struct attribute
{
@@ -109,21 +107,17 @@
};
// any_char 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)
+ template <typename Attribute, typename CharParam, typename Context>
+ bool test(Attribute const& attr, CharParam& ch, Context&) const
{
- return karma::detail::generate_to(sink, attr, char_encoding(), Tag()) &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ ch = attr;
+ return true;
}
// any_char has no attribute attached, it needs to have been
// initialized from a direct literal
- template <typename OutputIterator, typename Context, typename Delimiter>
- static bool generate(OutputIterator&, Context&, Delimiter const&,
- unused_type const&)
+ template <typename CharParam, typename Context>
+ bool test(unused_type, CharParam&, Context&) const
{
// It is not possible (doesn't make sense) to use char_ without
// providing any attribute, as the generator doesn't 'know' what
@@ -149,7 +143,8 @@
///////////////////////////////////////////////////////////////////////////
template <typename CharEncoding, typename Tag, bool no_attribute>
struct literal_char
- : primitive_generator<literal_char<CharEncoding, Tag, no_attribute> >
+ : char_generator<literal_char<CharEncoding, Tag, no_attribute>
+ , CharEncoding, Tag>
{
typedef typename CharEncoding::char_type char_type;
typedef CharEncoding char_encoding;
@@ -166,28 +161,22 @@
// A char_('x') which additionally has an associated attribute emits
// its immediate literal only if it matches the attribute, otherwise
// it fails.
- template <
- typename OutputIterator, typename Context, typename Delimiter
- , typename Attribute>
- bool generate(OutputIterator& sink, Context&, Delimiter const& d
- , Attribute const& attr) const
+ // any_char has an attached parameter
+ template <typename Attribute, typename CharParam, typename Context>
+ bool test(Attribute const& attr, CharParam& ch_, Context&) const
{
// fail if attribute isn't matched my immediate literal
- if (attr != ch)
- return false;
-
- return karma::detail::generate_to(sink, ch) &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ ch_ = attr;
+ return attr == ch;
}
// A char_('x') without any associated attribute just emits its
// immediate literal
- template <typename OutputIterator, typename Context, typename Delimiter>
- bool generate(OutputIterator& sink, Context&, Delimiter const& d
- , unused_type) const
+ template <typename CharParam, typename Context>
+ bool test(unused_type, CharParam& ch_, Context&) const
{
- return karma::detail::generate_to(sink, ch) &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ ch_ = ch;
+ return true;
}
template <typename Context>
@@ -203,7 +192,7 @@
// char range generator
template <typename CharEncoding, typename Tag>
struct char_range
- : primitive_generator<char_range<CharEncoding, Tag> >
+ : char_generator<char_range<CharEncoding, Tag>, CharEncoding, Tag>
{
typedef typename CharEncoding::char_type char_type;
typedef CharEncoding char_encoding;
@@ -215,36 +204,23 @@
// A char_('a', 'z') which has an associated attribute emits it only if
// it matches the character range, otherwise it fails.
- template <
- typename OutputIterator, typename Context, typename Delimiter
- , typename Attribute>
- bool generate(OutputIterator& sink, Context&, Delimiter const& d
- , Attribute const& attr) const
+ template <typename Attribute, typename CharParam, typename Context>
+ bool test(Attribute const& attr, CharParam& ch, Context&) const
{
// fail if attribute doesn't belong to character range
- if ((char_type(attr) < from) || (to < char_type(attr)))
- return false;
-
- return karma::detail::generate_to(sink, attr) &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ ch = attr;
+ return (from <= char_type(attr)) && (char_type(attr) <= to);
}
// A char_('a', 'z') without any associated attribute fails compiling
- template <typename OutputIterator, typename Context, typename Delimiter>
- bool generate(OutputIterator&, Context&, Delimiter const&
- , unused_type) const
+ template <typename CharParam, typename Context>
+ bool test(unused_type, CharParam&, Context&) const
{
BOOST_SPIRIT_ASSERT_MSG(false
, char_range_not_usable_without_attribute, ());
return false;
}
- template <typename CharParam, typename Context>
- bool test(CharParam ch, Context&) const
- {
- return !(char_type(ch) < from) && !(to < char_type(ch));
- }
-
template <typename Context>
info what(Context& /*context*/) const
{
@@ -261,7 +237,7 @@
// character set generator
template <typename CharEncoding, typename Tag>
struct char_set
- : primitive_generator<char_set<CharEncoding, Tag> >
+ : char_generator<char_set<CharEncoding, Tag>, CharEncoding, Tag>
{
typedef typename CharEncoding::char_type char_type;
typedef CharEncoding char_encoding;
@@ -304,24 +280,17 @@
// A char_("a-z") which has an associated attribute emits it only if
// it matches the character set, otherwise it fails.
- template <
- typename OutputIterator, typename Context, typename Delimiter
- , typename Attribute>
- bool generate(OutputIterator& sink, Context&, Delimiter const& d
- , Attribute const& attr) const
+ template <typename Attribute, typename CharParam, typename Context>
+ bool test(Attribute const& attr, CharParam& ch, Context&) const
{
// fail if attribute doesn't belong to character set
- if (!chset.test(char_type(attr)))
- return false;
-
- return karma::detail::generate_to(sink, attr) &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ ch = attr;
+ return chset.test(char_type(attr));
}
// A char_("a-z") without any associated attribute fails compiling
- template <typename OutputIterator, typename Context, typename Delimiter>
- bool generate(OutputIterator&, Context&, Delimiter const&
- , unused_type) const
+ template <typename CharParam, typename Context>
+ bool test(unused_type, CharParam&, Context&) const
{
BOOST_SPIRIT_ASSERT_MSG(false
, char_set_not_usable_without_attribute, ());
Modified: trunk/boost/spirit/home/karma/char/char_class.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/char/char_class.hpp (original)
+++ trunk/boost/spirit/home/karma/char/char_class.hpp 2009-09-07 22:16:31 EDT (Mon, 07 Sep 2009)
@@ -46,9 +46,11 @@
// class
//
///////////////////////////////////////////////////////////////////////////
- template <typename Tag>
+ template <typename Tag, typename CharEncoding, typename CharClass>
struct char_class
- : primitive_generator<char_class<Tag> >
+ : char_generator<
+ char_class<Tag, CharEncoding, CharClass>
+ , CharEncoding, CharClass>
{
typedef typename Tag::char_encoding char_encoding;
typedef typename char_encoding::char_type char_type;
@@ -61,24 +63,18 @@
};
// 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)
+ template <typename Attribute, typename CharParam, typename Context>
+ bool test(Attribute const& attr, CharParam& ch, Context&) const
{
- using spirit::char_class::classify;
- if (!classify<char_encoding>::is(classification(), attr))
- return false; // allow proper character class only
+ ch = attr;
- return karma::detail::generate_to(sink, attr) &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ using spirit::char_class::classify;
+ return classify<char_encoding>::is(classification(), attr);
}
// char_class shouldn't be used without any associated attribute
- template <typename OutputIterator, typename Context, typename Delimiter>
- static bool generate(OutputIterator&, Context&, Delimiter const&
- , unused_type const&)
+ template <typename CharParam, typename Context>
+ bool test(unused_type, CharParam& ch, Context&) const
{
BOOST_SPIRIT_ASSERT_MSG(false
, char_class_not_usable_without_attribute, ());
@@ -101,7 +97,7 @@
///////////////////////////////////////////////////////////////////////////
template <typename CharEncoding>
struct any_space
- : primitive_generator<any_space<CharEncoding> >
+ : char_generator<any_space<CharEncoding>, CharEncoding, tag::space>
{
typedef typename CharEncoding::char_type char_type;
typedef CharEncoding char_encoding;
@@ -113,27 +109,21 @@
};
// 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)
+ template <typename Attribute, typename CharParam, typename Context>
+ bool test(Attribute const& attr, CharParam& ch, Context&) const
{
- using spirit::char_class::classify;
- if (!classify<char_encoding>::is(tag::space(), attr))
- return false; // allow whitespace only
+ ch = attr;
- return karma::detail::generate_to(sink, attr) &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ using spirit::char_class::classify;
+ return classify<char_encoding>::is(tag::space(), attr);
}
// 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&)
+ template <typename CharParam, typename Context>
+ bool test(unused_type, CharParam& ch, Context&) const
{
- return karma::detail::generate_to(sink, ' ') &&
- karma::delimit_out(sink, d); // always do post-delimiting
+ ch = ' ';
+ return true;
}
template <typename Context>
@@ -183,7 +173,13 @@
, CharEncoding>
tag_type;
- typedef char_class<tag_type> result_type;
+ typedef char_class<
+ tag_type
+ , typename spirit::detail::get_encoding<
+ Modifiers, CharEncoding, lower || upper>::type
+ , typename detail::get_casetag<Modifiers, lower || upper>::type
+ > result_type;
+
result_type operator()(unused_type, unused_type) const
{
return result_type();
Modified: trunk/boost/spirit/home/karma/detail/get_casetag.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/detail/get_casetag.hpp (original)
+++ trunk/boost/spirit/home/karma/detail/get_casetag.hpp 2009-09-07 22:16:31 EDT (Mon, 07 Sep 2009)
@@ -21,9 +21,7 @@
template <typename Modifiers>
struct get_casetag<Modifiers, true>
: mpl::if_<has_modifier<Modifiers, tag::char_code_base<tag::lower> >
- , tag::lower
- , tag::upper
- > {};
+ , tag::lower, tag::upper> {};
}}}}
Modified: trunk/boost/spirit/home/qi/char/char_parser.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/char/char_parser.hpp (original)
+++ trunk/boost/spirit/home/qi/char/char_parser.hpp 2009-09-07 22:16:31 EDT (Mon, 07 Sep 2009)
@@ -51,7 +51,7 @@
typedef Char char_type;
struct char_parser_id;
- // if Char is unused_type, Derived must supply its own attribute
+ // if Attr is unused_type, Derived must supply its own attribute
// metafunction
template <typename Context, typename Iterator>
struct attribute
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