Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r67508 - in trunk: boost/spirit/home/qi/numeric libs/spirit/doc/advanced libs/spirit/example/qi libs/spirit/test libs/spirit/test/qi
From: admin_at_[hidden]
Date: 2010-12-30 16:55:49


Author: wash
Date: 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
New Revision: 67508
URL: http://svn.boost.org/trac/boost/changeset/67508

Log:
Added support for integral literals to Qi.

Added:
   trunk/libs/spirit/test/qi/int.hpp (contents, props changed)
   trunk/libs/spirit/test/qi/int1.cpp
      - copied, changed from r67493, /trunk/libs/spirit/test/qi/int.cpp
   trunk/libs/spirit/test/qi/int2.cpp (contents, props changed)
   trunk/libs/spirit/test/qi/uint.hpp (contents, props changed)
   trunk/libs/spirit/test/qi/uint1.cpp
      - copied, changed from r67493, /trunk/libs/spirit/test/qi/uint.cpp
   trunk/libs/spirit/test/qi/uint2.cpp (contents, props changed)
Removed:
   trunk/libs/spirit/test/qi/int.cpp
   trunk/libs/spirit/test/qi/uint.cpp
Text files modified:
   trunk/boost/spirit/home/qi/numeric/int.hpp | 206 +++++++++++++++++++++++++++---------
   trunk/boost/spirit/home/qi/numeric/uint.hpp | 222 +++++++++++++++++++++++++++------------
   trunk/libs/spirit/doc/advanced/indepth.qbk | 10 -
   trunk/libs/spirit/example/qi/reference.cpp | 3
   trunk/libs/spirit/test/Jamfile | 6
   trunk/libs/spirit/test/qi/int1.cpp | 70 -----------
   trunk/libs/spirit/test/qi/uint1.cpp | 53 --------
   7 files changed, 325 insertions(+), 245 deletions(-)

Modified: trunk/boost/spirit/home/qi/numeric/int.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric/int.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric/int.hpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -1,5 +1,6 @@
 /*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2011 Bryce Lelbach
 
     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)
@@ -11,6 +12,7 @@
 #pragma once
 #endif
 
+#include <boost/type_traits/is_arithmetic.hpp>
 #include <boost/spirit/home/qi/skip_over.hpp>
 #include <boost/spirit/home/qi/numeric/numeric_utils.hpp>
 #include <boost/spirit/home/qi/meta_compiler.hpp>
@@ -18,37 +20,41 @@
 #include <boost/spirit/home/support/common_terminals.hpp>
 #include <boost/spirit/home/support/info.hpp>
 #include <boost/mpl/assert.hpp>
+#include <boost/preprocessor/seq.hpp>
 
 namespace boost { namespace spirit
 {
     ///////////////////////////////////////////////////////////////////////////
     // Enablers
     ///////////////////////////////////////////////////////////////////////////
- //[primitive_parsers_enable_short_
- template <>
- struct use_terminal<qi::domain, tag::short_> // enables short_
- : mpl::true_ {};
+ //[primitive_parsers_enable_int
+ #define BOOST_SPIRIT_ENABLE_INTEGER(r, data, name) \
+ template <> \
+ struct use_terminal<qi::domain, tag::name> \
+ : mpl::true_ {}; \
+ \
+ template <typename A0> \
+ struct use_terminal<qi::domain \
+ , terminal_ex<tag::name, fusion::vector1<A0> > > \
+ : is_arithmetic<A0> {}; \
+ \
+ template <> \
+ struct use_lazy_terminal<qi::domain, tag::name, 1> : mpl::true_ {}; \
+ /***/
+
+ #define BOOST_SPIRIT_ENABLE_INTEGERS(names) \
+ BOOST_PP_SEQ_FOR_EACH(BOOST_SPIRIT_ENABLE_INTEGER, _, names) \
+ /***/
+
+ BOOST_SPIRIT_ENABLE_INTEGERS(
+ (short_)
+ (int_)
+ (long_)
+ #ifdef BOOST_HAS_LONG_LONG
+ (long_long)
+ #endif
+ )
     //]
-
- //[primitive_parsers_enable_int_
- template <>
- struct use_terminal<qi::domain, tag::int_> // enables int_
- : mpl::true_ {};
- //]
-
- //[primitive_parsers_enable_long_
- template <>
- struct use_terminal<qi::domain, tag::long_> // enables long_
- : mpl::true_ {};
- //]
-
-#ifdef BOOST_HAS_LONG_LONG
- //[primitive_parsers_enable_long_long_
- template <>
- struct use_terminal<qi::domain, tag::long_long> // enables long_long
- : mpl::true_ {};
- //]
-#endif
 }}
 
 namespace boost { namespace spirit { namespace qi
@@ -72,9 +78,21 @@
         typename T
       , unsigned Radix = 10
       , unsigned MinDigits = 1
- , int MaxDigits = -1>
+ , int MaxDigits = -1
+ , bool no_attribute = true
+ , typename Enable = void>
+ struct int_parser_impl;
+
+ template <
+ typename T
+ , unsigned Radix
+ , unsigned MinDigits
+ , int MaxDigits
+ , bool no_attribute
+ , typename Enable>
     struct int_parser_impl
- : primitive_parser<int_parser_impl<T, Radix, MinDigits, MaxDigits> >
+ : primitive_parser<int_parser_impl<T, Radix, MinDigits, MaxDigits
+ , no_attribute, Enable> >
     {
         // check template parameter 'Radix' for validity
         BOOST_SPIRIT_ASSERT_MSG(
@@ -93,9 +111,9 @@
           , Context& /*context*/, Skipper const& skipper
           , Attribute& attr) const
         {
+ typedef extract_int<T, Radix, MinDigits, MaxDigits> extract;
             qi::skip_over(first, last, skipper);
- return extract_int<T, Radix, MinDigits, MaxDigits>
- ::call(first, last, attr);
+ return extract::call(first, last, attr);
         }
 
         template <typename Context>
@@ -104,11 +122,67 @@
             return info("integer");
         }
     };
+
+ template <
+ typename T
+ , unsigned Radix
+ , unsigned MinDigits
+ , int MaxDigits>
+ struct int_parser_impl<T, Radix, MinDigits, MaxDigits, false, typename
+ enable_if<is_arithmetic<T> >::type>
+ : primitive_parser<int_parser_impl<T, Radix, MinDigits, MaxDigits
+ , false> >
+ {
+ // check template parameter 'Radix' for validity
+ BOOST_SPIRIT_ASSERT_MSG(
+ Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,
+ not_supported_radix, ());
+
+ T n;
+
+ template <typename Value>
+ int_parser_impl(Value const& v) : n(v) { }
+
+ template <typename Context, typename Iterator>
+ struct attribute
+ {
+ typedef unused_type type;
+ };
+
+ template <typename Iterator, typename Context
+ , typename Skipper, typename Attribute>
+ bool parse(Iterator& first, Iterator const& last
+ , Context& /*context*/, Skipper const& skipper
+ , Attribute& attr) const
+ {
+ typedef extract_int<T, Radix, MinDigits, MaxDigits> extract;
+ qi::skip_over(first, last, skipper);
+
+ T attr_;
+
+ if (extract::call(first, last, attr_) && (attr_ == n))
+ {
+ traits::assign_to(attr_, attr);
+ return true;
+ }
+
+ return false;
+ }
+
+ template <typename Context>
+ info what(Context& /*context*/) const
+ {
+ return info("literal-integer");
+ }
+ };
     //]
 
     ///////////////////////////////////////////////////////////////////////////
- // This one is the class that the user can instantiate directly
+ // This is the class that the user can instantiate directly
     ///////////////////////////////////////////////////////////////////////////
+
+ // FIXME: how can we allow user instantiated numeric parsers to be used as
+ // literal numeric parsers?
     template <
         typename T
       , unsigned Radix = 10
@@ -123,40 +197,64 @@
     // Parser generators: make_xxx function (objects)
     ///////////////////////////////////////////////////////////////////////////
     //[primitive_parsers_make_int
- template <typename T>
+ template <
+ typename T
+ , unsigned Radix = 10
+ , unsigned MinDigits = 1
+ , int MaxDigits = -1>
     struct make_int
     {
- typedef int_parser_impl<T> result_type;
+ typedef int_parser_impl<T, Radix, MinDigits, MaxDigits, true>
+ result_type;
         result_type operator()(unused_type, unused_type) const
         {
             return result_type();
         }
     };
+
+ template <
+ typename T
+ , unsigned Radix = 10
+ , unsigned MinDigits = 1
+ , int MaxDigits = -1>
+ struct make_literal_int
+ {
+ typedef int_parser_impl<T, Radix, MinDigits, MaxDigits, false>
+ result_type;
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ return result_type(fusion::at_c<0>(term.args));
+ }
+ };
     //]
 
- //[primitive_parsers_short_
- template <typename Modifiers>
- struct make_primitive<tag::short_, Modifiers> : make_int<short> {};
- //]
-
- //[primitive_parsers_int_
- template <typename Modifiers>
- struct make_primitive<tag::int_, Modifiers> : make_int<int> {};
- //]
-
- //[primitive_parsers_long_
- template <typename Modifiers>
- struct make_primitive<tag::long_, Modifiers> : make_int<long> {};
- //]
-
-#ifdef BOOST_HAS_LONG_LONG
- //[primitive_parsers_long_long_
- template <typename Modifiers>
- struct make_primitive<tag::long_long, Modifiers>
- : make_int<boost::long_long_type> {};
+ //[primitive_parsers_make_primitives
+ #define BOOST_SPIRIT_MAKE_INTEGER_PRIMITIVE(r, data, elem) \
+ template <typename Modifiers> \
+ struct make_primitive<tag::BOOST_PP_SEQ_ELEM(0, elem), Modifiers> \
+ : make_int<BOOST_PP_SEQ_ELEM(1, elem)> {}; \
+ \
+ template <typename Modifiers, typename A0> \
+ struct make_primitive< \
+ terminal_ex<tag::BOOST_PP_SEQ_ELEM(0, elem) \
+ , fusion::vector1<A0> > , Modifiers> \
+ : make_literal_int<BOOST_PP_SEQ_ELEM(1, elem)> {}; \
+ /***/
+
+ #define BOOST_SPIRIT_MAKE_INTEGER_PRIMITIVES(names) \
+ BOOST_PP_SEQ_FOR_EACH(BOOST_SPIRIT_MAKE_INTEGER_PRIMITIVE, _, names) \
+ /***/
+
+ BOOST_SPIRIT_MAKE_INTEGER_PRIMITIVES(
+ ((short_) (short))
+ ((int_) (int))
+ ((long_) (long))
+ #ifdef BOOST_HAS_LONG_LONG
+ ((long_long) (boost::long_long_type))
+ #endif
+ )
     //]
-#endif
-
 }}}
 
 #endif

Modified: trunk/boost/spirit/home/qi/numeric/uint.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric/uint.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric/uint.hpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -1,5 +1,6 @@
 /*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2011 Bryce Lelbach
 
     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)
@@ -11,6 +12,7 @@
 #pragma once
 #endif
 
+#include <boost/type_traits/is_arithmetic.hpp>
 #include <boost/spirit/home/qi/skip_over.hpp>
 #include <boost/spirit/home/qi/numeric/numeric_utils.hpp>
 #include <boost/spirit/home/qi/meta_compiler.hpp>
@@ -18,41 +20,42 @@
 #include <boost/spirit/home/support/common_terminals.hpp>
 #include <boost/spirit/home/support/info.hpp>
 #include <boost/mpl/assert.hpp>
+#include <boost/preprocessor/seq.hpp>
 
 namespace boost { namespace spirit
 {
     ///////////////////////////////////////////////////////////////////////////
     // Enablers
     ///////////////////////////////////////////////////////////////////////////
- template <>
- struct use_terminal<qi::domain, tag::bin> // enables bin
- : mpl::true_ {};
-
- template <>
- struct use_terminal<qi::domain, tag::oct> // enables oct
- : mpl::true_ {};
-
- template <>
- struct use_terminal<qi::domain, tag::hex> // enables hex
- : mpl::true_ {};
-
- template <>
- struct use_terminal<qi::domain, tag::ushort_> // enables ushort_
- : mpl::true_ {};
-
- template <>
- struct use_terminal<qi::domain, tag::ulong_> // enables ulong_
- : mpl::true_ {};
-
- template <>
- struct use_terminal<qi::domain, tag::uint_> // enables uint_
- : mpl::true_ {};
-
-#ifdef BOOST_HAS_LONG_LONG
- template <>
- struct use_terminal<qi::domain, tag::ulong_long> // enables ulong_long
- : mpl::true_ {};
-#endif
+ #define BOOST_SPIRIT_ENABLE_UINTEGER(r, data, name) \
+ template <> \
+ struct use_terminal<qi::domain, tag::name> \
+ : mpl::true_ {}; \
+ \
+ template <typename A0> \
+ struct use_terminal<qi::domain \
+ , terminal_ex<tag::name, fusion::vector1<A0> > > \
+ : is_arithmetic<A0> {}; \
+ \
+ template <> \
+ struct use_lazy_terminal<qi::domain, tag::name, 1> : mpl::true_ {}; \
+ /***/
+
+ #define BOOST_SPIRIT_ENABLE_UINTEGERS(names) \
+ BOOST_PP_SEQ_FOR_EACH(BOOST_SPIRIT_ENABLE_UINTEGER, _, names) \
+ /***/
+
+ BOOST_SPIRIT_ENABLE_UINTEGERS(
+ (bin)
+ (oct)
+ (hex)
+ (ushort_)
+ (uint_)
+ (ulong_)
+ #ifdef BOOST_HAS_LONG_LONG
+ (ulong_long)
+ #endif
+ )
 }}
 
 namespace boost { namespace spirit { namespace qi
@@ -75,15 +78,27 @@
 #endif
 
     ///////////////////////////////////////////////////////////////////////////
- // This actual unsigned int parser
+ // This is actual unsigned int parser
     ///////////////////////////////////////////////////////////////////////////
     template <
         typename T
       , unsigned Radix = 10
       , unsigned MinDigits = 1
- , int MaxDigits = -1>
+ , int MaxDigits = -1
+ , bool no_attribute = true
+ , typename Enable = void>
+ struct uint_parser_impl;
+
+ template <
+ typename T
+ , unsigned Radix
+ , unsigned MinDigits
+ , int MaxDigits
+ , bool no_attribute
+ , typename Enable>
     struct uint_parser_impl
- : primitive_parser<uint_parser_impl<T, Radix, MinDigits, MaxDigits> >
+ : primitive_parser<uint_parser_impl<T, Radix, MinDigits, MaxDigits
+ , no_attribute, Enable> >
     {
         // check template parameter 'Radix' for validity
         BOOST_SPIRIT_ASSERT_MSG(
@@ -102,9 +117,9 @@
           , Context& /*context*/, Skipper const& skipper
           , Attribute& attr) const
         {
+ typedef extract_uint<T, Radix, MinDigits, MaxDigits> extract;
             qi::skip_over(first, last, skipper);
- return extract_uint<T, Radix, MinDigits, MaxDigits>
- ::call(first, last, attr);
+ return extract::call(first, last, attr);
         }
 
         template <typename Context>
@@ -114,9 +129,65 @@
         }
     };
 
+ template <
+ typename T
+ , unsigned Radix
+ , unsigned MinDigits
+ , int MaxDigits>
+ struct uint_parser_impl<T, Radix, MinDigits, MaxDigits, false, typename
+ enable_if<is_arithmetic<T> >::type>
+ : primitive_parser<uint_parser_impl<T, Radix, MinDigits, MaxDigits
+ , false> >
+ {
+ // check template parameter 'Radix' for validity
+ BOOST_SPIRIT_ASSERT_MSG(
+ Radix == 2 || Radix == 8 || Radix == 10 || Radix == 16,
+ not_supported_radix, ());
+
+ T n;
+
+ template <typename Value>
+ uint_parser_impl(Value const& v) : n(v) { }
+
+ template <typename Context, typename Iterator>
+ struct attribute
+ {
+ typedef unused_type type;
+ };
+
+ template <typename Iterator, typename Context
+ , typename Skipper, typename Attribute>
+ bool parse(Iterator& first, Iterator const& last
+ , Context& /*context*/, Skipper const& skipper
+ , Attribute& attr) const
+ {
+ typedef extract_uint<T, Radix, MinDigits, MaxDigits> extract;
+ qi::skip_over(first, last, skipper);
+
+ T attr_;
+
+ if (extract::call(first, last, attr_) && (attr_ == n))
+ {
+ traits::assign_to(attr_, attr);
+ return true;
+ }
+
+ return false;
+ }
+
+ template <typename Context>
+ info what(Context& /*context*/) const
+ {
+ return info("literal-unsigned-integer");
+ }
+ };
+
     ///////////////////////////////////////////////////////////////////////////
- // uint_parser is the class that the user can instantiate directly
+ // This is the class that the user can instantiate directly
     ///////////////////////////////////////////////////////////////////////////
+
+ // FIXME: how can we allow user instantiated numeric parsers to be used as
+ // literal numeric parsers?
     template <
         typename T
       , unsigned Radix = 10
@@ -137,42 +208,59 @@
       , int MaxDigits = -1>
     struct make_uint
     {
- typedef uint_parser_impl<T, Radix, MinDigits, MaxDigits> result_type;
+ typedef uint_parser_impl<T, Radix, MinDigits, MaxDigits, true>
+ result_type;
         result_type operator()(unused_type, unused_type) const
         {
             return result_type();
         }
     };
-
- template <typename Modifiers>
- struct make_primitive<tag::bin, Modifiers>
- : make_uint<unsigned, 2, 1, -1> {};
-
- template <typename Modifiers>
- struct make_primitive<tag::oct, Modifiers>
- : make_uint<unsigned, 8, 1, -1> {};
-
- template <typename Modifiers>
- struct make_primitive<tag::hex, Modifiers>
- : make_uint<unsigned, 16, 1, -1> {};
-
- template <typename Modifiers>
- struct make_primitive<tag::ushort_, Modifiers>
- : make_uint<unsigned short> {};
-
- template <typename Modifiers>
- struct make_primitive<tag::ulong_, Modifiers>
- : make_uint<unsigned long> {};
-
- template <typename Modifiers>
- struct make_primitive<tag::uint_, Modifiers>
- : make_uint<unsigned int> {};
-
-#ifdef BOOST_HAS_LONG_LONG
- template <typename Modifiers>
- struct make_primitive<tag::ulong_long, Modifiers>
- : make_uint<boost::ulong_long_type> {};
-#endif
+
+ template <
+ typename T
+ , unsigned Radix = 10
+ , unsigned MinDigits = 1
+ , int MaxDigits = -1>
+ struct make_literal_uint
+ {
+ typedef uint_parser_impl<T, Radix, MinDigits, MaxDigits, false>
+ result_type;
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ return result_type(fusion::at_c<0>(term.args));
+ }
+ };
+
+ #define BOOST_SPIRIT_MAKE_UINTEGER_PRIMITIVE(r, data, elem) \
+ template <typename Modifiers> \
+ struct make_primitive<tag::BOOST_PP_SEQ_ELEM(0, elem), Modifiers> \
+ : make_uint<BOOST_PP_SEQ_ELEM(1, elem) \
+ , BOOST_PP_SEQ_ELEM(2, elem)> {}; \
+ \
+ template <typename Modifiers, typename A0> \
+ struct make_primitive< \
+ terminal_ex<tag::BOOST_PP_SEQ_ELEM(0, elem) \
+ , fusion::vector1<A0> > , Modifiers> \
+ : make_literal_uint<BOOST_PP_SEQ_ELEM(1, elem) \
+ , BOOST_PP_SEQ_ELEM(2, elem)> {}; \
+ /***/
+
+ #define BOOST_SPIRIT_MAKE_UINTEGER_PRIMITIVES(names) \
+ BOOST_PP_SEQ_FOR_EACH(BOOST_SPIRIT_MAKE_UINTEGER_PRIMITIVE, _, names) \
+ /***/
+
+ BOOST_SPIRIT_MAKE_UINTEGER_PRIMITIVES(
+ ((bin) (unsigned) (2))
+ ((oct) (unsigned) (8))
+ ((hex) (unsigned) (16))
+ ((ushort_) (unsigned short) (10))
+ ((uint_) (unsigned int) (10))
+ ((ulong_) (unsigned long) (10))
+ #ifdef BOOST_HAS_LONG_LONG
+ ((ulong_long) (boost::ulong_long_type) (10))
+ #endif
+ )
 }}}
 
 #endif

Modified: trunk/libs/spirit/doc/advanced/indepth.qbk
==============================================================================
--- trunk/libs/spirit/doc/advanced/indepth.qbk (original)
+++ trunk/libs/spirit/doc/advanced/indepth.qbk 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -120,10 +120,7 @@
 `int_parser` to some placeholders for `short_`, `int_`, `long_` and `long_long`
 types. But, first, we enable these placeholders in namespace boost::spirit:
 
-[primitive_parsers_enable_short_]
-[primitive_parsers_enable_int_]
-[primitive_parsers_enable_long_]
-[primitive_parsers_enable_long_long_]
+[primitive_parsers_enable_int]
 
 Notice that `int_parser` is placed in the namespace boost::spirit::qi
 while these /enablers/ are in namespace boost::spirit. The reason is
@@ -151,10 +148,7 @@
 
 Now:
 
-[primitive_parsers_short_]
-[primitive_parsers_int_]
-[primitive_parsers_long_]
-[primitive_parsers_long_long_]
+[primitive_parsers_make_primitives]
 
 These, specialize `qi:make_primitive` for specific tags. They all
 inherit from `make_int` which does the actual work.

Modified: trunk/libs/spirit/example/qi/reference.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/reference.cpp (original)
+++ trunk/libs/spirit/example/qi/reference.cpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -748,6 +748,7 @@
 
         //[reference_uint
         test_parser("12345", uint_);
+ test_parser("12345", uint_(12345));
         //]
         
         //[reference_thousand_separated
@@ -767,6 +768,8 @@
         //[reference_int
         test_parser("+12345", int_);
         test_parser("-12345", int_);
+ test_parser("+12345", int_(12345));
+ test_parser("-12345", int_(-12345));
         //]
     }
 

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -43,7 +43,8 @@
      [ run qi/eps.cpp : : : : qi_eps ]
      [ run qi/expect.cpp : : : : qi_expect ]
      [ run qi/grammar.cpp : : : : qi_grammar ]
- [ run qi/int.cpp : : : : qi_int ]
+ [ run qi/int1.cpp : : : : qi_int1 ]
+ [ run qi/int2.cpp : : : : qi_int2 ]
      [ run qi/kleene.cpp : : : : qi_kleene ]
      [ run qi/lazy.cpp : : : : qi_lazy ]
      [ run qi/lexeme.cpp : : : : qi_lexeme ]
@@ -80,7 +81,8 @@
      [ run qi/symbols2.cpp : : : : qi_symbols2 ]
      [ run qi/terminal_ex.cpp : : : : qi_terminal_ex ]
      [ run qi/tst.cpp : : : : qi_tst ]
- [ run qi/uint.cpp : : : : qi_uint ]
+ [ run qi/uint1.cpp : : : : qi_uint1 ]
+ [ run qi/uint2.cpp : : : : qi_uint2 ]
      [ run qi/utree1.cpp : : : : qi_utree1 ]
      [ run qi/utree2.cpp : : : : qi_utree2 ]
      [ run qi/utree3.cpp : : : : qi_utree3 ]

Deleted: trunk/libs/spirit/test/qi/int.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/int.cpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
+++ (empty file)
@@ -1,235 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
- Copyright (c) 2001-2010 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 <climits>
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/qi_numeric.hpp>
-#include <boost/spirit/include/qi_char.hpp>
-#include <boost/spirit/include/qi_action.hpp>
-#include <boost/spirit/include/support_argument.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include "test.hpp"
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// *** BEWARE PLATFORM DEPENDENT!!! ***
-// *** The following assumes 32 bit or 64 bit integers and 64 bit long longs.
-// *** Modify these constant strings when appropriate.
-//
-///////////////////////////////////////////////////////////////////////////////
-#ifdef BOOST_HAS_LONG_LONG
-// Some compilers have long long, but don't define the
-// LONG_LONG_MIN and LONG_LONG_MAX macros in limits.h. This
-// assumes that long long is 64 bits.
-
-BOOST_STATIC_ASSERT(sizeof(boost::long_long_type) == 8);
-
-#if !defined(LONG_LONG_MIN) && !defined(LONG_LONG_MAX)
-# define LONG_LONG_MAX 0x7fffffffffffffffLL
-# define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
-#endif
-
-#endif // BOOST_HAS_LONG_LONG
-
-#if INT_MAX != LLONG_MAX
- BOOST_STATIC_ASSERT(sizeof(int) == 4);
- char const* max_int = "2147483647";
- char const* int_overflow = "2147483648";
- char const* min_int = "-2147483648";
- char const* int_underflow = "-2147483649";
-#else
- BOOST_STATIC_ASSERT(sizeof(int) == 8);
- char const* max_int = "9223372036854775807";
- char const* int_overflow = "9223372036854775808";
- char const* min_int = "-9223372036854775808";
- char const* int_underflow = "-9223372036854775809";
-#endif
-
-#ifdef BOOST_HAS_LONG_LONG
- char const* max_long_long = "9223372036854775807";
- char const* long_long_overflow = "9223372036854775808";
- char const* min_long_long = "-9223372036854775808";
- char const* long_long_underflow = "-9223372036854775809";
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// A custom int type
-struct custom_int
-{
- int n;
- custom_int() : n(0) {}
- explicit custom_int(int n_) : n(n_) {}
- custom_int& operator=(int n_) { n = n_; return *this; }
- friend custom_int operator*(custom_int a, custom_int b) { return custom_int(a.n * b.n); }
- friend custom_int operator+(custom_int a, custom_int b) { return custom_int(a.n + b.n); }
- friend custom_int operator-(custom_int a, custom_int b) { return custom_int(a.n - b.n); }
-};
-
-int
-main()
-{
- using spirit_test::test;
- using spirit_test::test_attr;
-
- ///////////////////////////////////////////////////////////////////////////
- // signed integer tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::int_;
- int i;
-
- BOOST_TEST(test("123456", int_));
- BOOST_TEST(test_attr("123456", int_, i));
- BOOST_TEST(i == 123456);
-
- BOOST_TEST(test("+123456", int_));
- BOOST_TEST(test_attr("+123456", int_, i));
- BOOST_TEST(i == 123456);
-
- BOOST_TEST(test("-123456", int_));
- BOOST_TEST(test_attr("-123456", int_, i));
- BOOST_TEST(i == -123456);
-
- BOOST_TEST(test(max_int, int_));
- BOOST_TEST(test_attr(max_int, int_, i));
- BOOST_TEST(i == INT_MAX);
-
- BOOST_TEST(test(min_int, int_));
- BOOST_TEST(test_attr(min_int, int_, i));
- BOOST_TEST(i == INT_MIN);
-
- BOOST_TEST(!test(int_overflow, int_));
- BOOST_TEST(!test_attr(int_overflow, int_, i));
- BOOST_TEST(!test(int_underflow, int_));
- BOOST_TEST(!test_attr(int_underflow, int_, i));
-
- BOOST_TEST(!test("-", int_));
- BOOST_TEST(!test_attr("-", int_, i));
-
- BOOST_TEST(!test("+", int_));
- BOOST_TEST(!test_attr("+", int_, i));
-
- // Bug report from Steve Nutt
- BOOST_TEST(!test_attr("5368709120", int_, i));
-
- // with leading zeros
- BOOST_TEST(test("0000000000123456", int_));
- BOOST_TEST(test_attr("0000000000123456", int_, i));
- BOOST_TEST(i == 123456);
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // long long tests
- ///////////////////////////////////////////////////////////////////////////
-#ifdef BOOST_HAS_LONG_LONG
- {
- using boost::spirit::long_long;
- boost::long_long_type ll;
-
- BOOST_TEST(test("1234567890123456789", long_long));
- BOOST_TEST(test_attr("1234567890123456789", long_long, ll));
- BOOST_TEST(ll == 1234567890123456789LL);
-
- BOOST_TEST(test("-1234567890123456789", long_long));
- BOOST_TEST(test_attr("-1234567890123456789", long_long, ll));
- BOOST_TEST(ll == -1234567890123456789LL);
-
- BOOST_TEST(test(max_long_long, long_long));
- BOOST_TEST(test_attr(max_long_long, long_long, ll));
- BOOST_TEST(ll == LONG_LONG_MAX);
-
- BOOST_TEST(test(min_long_long, long_long));
- BOOST_TEST(test_attr(min_long_long, long_long, ll));
- BOOST_TEST(ll == LONG_LONG_MIN);
-
- BOOST_TEST(!test(long_long_overflow, long_long));
- BOOST_TEST(!test_attr(long_long_overflow, long_long, ll));
- BOOST_TEST(!test(long_long_underflow, long_long));
- BOOST_TEST(!test_attr(long_long_underflow, long_long, ll));
- }
-#endif
-
- ///////////////////////////////////////////////////////////////////////////
- // short_ and long_ tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::short_;
- using boost::spirit::long_;
- int i;
-
- BOOST_TEST(test("12345", short_));
- BOOST_TEST(test_attr("12345", short_, i));
- BOOST_TEST(i == 12345);
-
- BOOST_TEST(test("1234567890", long_));
- BOOST_TEST(test_attr("1234567890", long_, i));
- BOOST_TEST(i == 1234567890);
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Check overflow is parse error
- ///////////////////////////////////////////////////////////////////////////
- {
- boost::spirit::qi::int_parser<boost::int8_t> int8_;
- char c;
-
- BOOST_TEST(!test_attr("999", int8_, c));
-
- int i;
- using boost::spirit::short_;
- BOOST_TEST(!test_attr("32769", short_, i, false));
- BOOST_TEST(!test_attr("41234", short_, i, false));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // int_parser<unused_type> tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::int_parser;
- using boost::spirit::unused_type;
- int_parser<unused_type> any_int;
-
- BOOST_TEST(test("123456", any_int));
- BOOST_TEST(test("-123456", any_int));
- BOOST_TEST(test("-1234567890123456789", any_int));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // action tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::phoenix::ref;
- using boost::spirit::_1;
- using boost::spirit::ascii::space;
- using boost::spirit::int_;
- int n, m;
-
- BOOST_TEST(test("123", int_[ref(n) = _1]));
- BOOST_TEST(n == 123);
- BOOST_TEST(test_attr("789", int_[ref(n) = _1], m));
- BOOST_TEST(n == 789 && m == 789);
- BOOST_TEST(test(" 456", int_[ref(n) = _1], space));
- BOOST_TEST(n == 456);
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // custom int tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::int_;
- using boost::spirit::qi::int_parser;
- custom_int i;
-
- BOOST_TEST(test_attr("-123456", int_, i));
- int_parser<custom_int, 10, 1, 2> int2;
- BOOST_TEST(test_attr("-12", int2, i));
- }
-
- return boost::report_errors();
-}

Added: trunk/libs/spirit/test/qi/int.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/int.hpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -0,0 +1,79 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Bryce Lelbach
+
+ 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_TEST_QI_INT_HPP)
+#define BOOST_SPIRIT_TEST_QI_INT_HPP
+
+#include <climits>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include "test.hpp"
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// *** BEWARE PLATFORM DEPENDENT!!! ***
+// *** The following assumes 32 bit or 64 bit integers and 64 bit long longs.
+// *** Modify these constant strings when appropriate.
+//
+///////////////////////////////////////////////////////////////////////////////
+#ifdef BOOST_HAS_LONG_LONG
+// Some compilers have long long, but don't define the
+// LONG_LONG_MIN and LONG_LONG_MAX macros in limits.h. This
+// assumes that long long is 64 bits.
+
+BOOST_STATIC_ASSERT(sizeof(boost::long_long_type) == 8);
+
+#if !defined(LONG_LONG_MIN) && !defined(LONG_LONG_MAX)
+# define LONG_LONG_MAX 0x7fffffffffffffffLL
+# define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
+#endif
+
+#endif // BOOST_HAS_LONG_LONG
+
+#if INT_MAX != LLONG_MAX
+ BOOST_STATIC_ASSERT(sizeof(int) == 4);
+ char const* max_int = "2147483647";
+ char const* int_overflow = "2147483648";
+ char const* min_int = "-2147483648";
+ char const* int_underflow = "-2147483649";
+#else
+ BOOST_STATIC_ASSERT(sizeof(int) == 8);
+ char const* max_int = "9223372036854775807";
+ char const* int_overflow = "9223372036854775808";
+ char const* min_int = "-9223372036854775808";
+ char const* int_underflow = "-9223372036854775809";
+#endif
+
+#ifdef BOOST_HAS_LONG_LONG
+ char const* max_long_long = "9223372036854775807";
+ char const* long_long_overflow = "9223372036854775808";
+ char const* min_long_long = "-9223372036854775808";
+ char const* long_long_underflow = "-9223372036854775809";
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+// A custom int type
+struct custom_int
+{
+ int n;
+ custom_int() : n(0) {}
+ explicit custom_int(int n_) : n(n_) {}
+ custom_int& operator=(int n_) { n = n_; return *this; }
+ friend bool operator==(custom_int a, custom_int b) { return a.n == b.n; }
+ friend custom_int operator*(custom_int a, custom_int b) { return custom_int(a.n * b.n); }
+ friend custom_int operator+(custom_int a, custom_int b) { return custom_int(a.n + b.n); }
+ friend custom_int operator-(custom_int a, custom_int b) { return custom_int(a.n - b.n); }
+};
+
+#endif

Copied: trunk/libs/spirit/test/qi/int1.cpp (from r67493, /trunk/libs/spirit/test/qi/int.cpp)
==============================================================================
--- /trunk/libs/spirit/test/qi/int.cpp (original)
+++ trunk/libs/spirit/test/qi/int1.cpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -1,75 +1,13 @@
 /*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
- Copyright (c) 2001-2010 Hartmut Kaiser
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Bryce Lelbach
 
     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 <climits>
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/qi_numeric.hpp>
-#include <boost/spirit/include/qi_char.hpp>
-#include <boost/spirit/include/qi_action.hpp>
-#include <boost/spirit/include/support_argument.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include "test.hpp"
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// *** BEWARE PLATFORM DEPENDENT!!! ***
-// *** The following assumes 32 bit or 64 bit integers and 64 bit long longs.
-// *** Modify these constant strings when appropriate.
-//
-///////////////////////////////////////////////////////////////////////////////
-#ifdef BOOST_HAS_LONG_LONG
-// Some compilers have long long, but don't define the
-// LONG_LONG_MIN and LONG_LONG_MAX macros in limits.h. This
-// assumes that long long is 64 bits.
-
-BOOST_STATIC_ASSERT(sizeof(boost::long_long_type) == 8);
-
-#if !defined(LONG_LONG_MIN) && !defined(LONG_LONG_MAX)
-# define LONG_LONG_MAX 0x7fffffffffffffffLL
-# define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
-#endif
-
-#endif // BOOST_HAS_LONG_LONG
-
-#if INT_MAX != LLONG_MAX
- BOOST_STATIC_ASSERT(sizeof(int) == 4);
- char const* max_int = "2147483647";
- char const* int_overflow = "2147483648";
- char const* min_int = "-2147483648";
- char const* int_underflow = "-2147483649";
-#else
- BOOST_STATIC_ASSERT(sizeof(int) == 8);
- char const* max_int = "9223372036854775807";
- char const* int_overflow = "9223372036854775808";
- char const* min_int = "-9223372036854775808";
- char const* int_underflow = "-9223372036854775809";
-#endif
 
-#ifdef BOOST_HAS_LONG_LONG
- char const* max_long_long = "9223372036854775807";
- char const* long_long_overflow = "9223372036854775808";
- char const* min_long_long = "-9223372036854775808";
- char const* long_long_underflow = "-9223372036854775809";
-#endif
-
-///////////////////////////////////////////////////////////////////////////////
-// A custom int type
-struct custom_int
-{
- int n;
- custom_int() : n(0) {}
- explicit custom_int(int n_) : n(n_) {}
- custom_int& operator=(int n_) { n = n_; return *this; }
- friend custom_int operator*(custom_int a, custom_int b) { return custom_int(a.n * b.n); }
- friend custom_int operator+(custom_int a, custom_int b) { return custom_int(a.n + b.n); }
- friend custom_int operator-(custom_int a, custom_int b) { return custom_int(a.n - b.n); }
-};
+#include "int.hpp"
 
 int
 main()

Added: trunk/libs/spirit/test/qi/int2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/int2.cpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -0,0 +1,107 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Bryce Lelbach
+
+ 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 "int.hpp"
+
+int
+main()
+{
+ using spirit_test::test;
+ using spirit_test::test_attr;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // signed integer literal tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::int_;
+
+ int i = 123456;
+
+ BOOST_TEST( test("123456", int_(123456)));
+ BOOST_TEST(!test("123456", int_(0)));
+
+ BOOST_TEST( test("123456", int_(i)));
+ BOOST_TEST(!test("123456", int_(-i)));
+
+ BOOST_TEST( test("+425", int_(425)));
+ BOOST_TEST(!test("+425", int_(17)));
+
+ BOOST_TEST( test("-2000", int_(-2000)));
+ BOOST_TEST(!test("-2000", int_(2000)));
+
+ BOOST_TEST( test(max_int, int_(INT_MAX)));
+ BOOST_TEST(!test(max_int, int_(INT_MIN)));
+
+ BOOST_TEST( test(min_int, int_(INT_MIN)));
+ BOOST_TEST(!test(min_int, int_(INT_MAX)));
+
+ BOOST_TEST(!test("-", int_(8451)));
+ BOOST_TEST(!test("+", int_(8451)));
+
+ // with leading zeros
+ BOOST_TEST(test("000000000098765", int_(98765)));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // long long literal tests
+ ///////////////////////////////////////////////////////////////////////////
+#ifdef BOOST_HAS_LONG_LONG
+ {
+ using boost::spirit::long_long;
+ boost::long_long_type ll = 1234567890123456789LL;
+
+ BOOST_TEST( test("1234567890123456789", long_long(1234567890123456789LL)));
+ BOOST_TEST(!test("1234567890123456789", long_long(-19LL)));
+
+ BOOST_TEST( test("1234567890123456789", long_long(ll)));
+ BOOST_TEST(!test("1234567890123456789", long_long(-ll)));
+
+ BOOST_TEST( test("-100000000000000", long_long(-100000000000000LL)));
+ BOOST_TEST(!test("-100000000000000", long_long(3243515525263LL)));
+
+ BOOST_TEST( test(max_long_long, long_long(LONG_LONG_MAX)));
+ BOOST_TEST(!test(max_long_long, long_long(LONG_LONG_MIN)));
+
+ BOOST_TEST( test(min_long_long, long_long(LONG_LONG_MIN)));
+ BOOST_TEST(!test(min_long_long, long_long(LONG_LONG_MAX)));
+ }
+#endif
+
+ ///////////////////////////////////////////////////////////////////////////
+ // short_ and long_ literal tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::short_;
+ using boost::spirit::long_;
+ short s = 12345;
+ long l = 1234567890L;
+
+ BOOST_TEST( test("12345", short_(12345)));
+ BOOST_TEST(!test("12345", short_(-12345)));
+ BOOST_TEST( test("12345", short_(s)));
+ BOOST_TEST(!test("12345", short_(-s)));
+
+ BOOST_TEST( test("-12345", short_(-12345)));
+ BOOST_TEST(!test("-12345", short_(12345)));
+ BOOST_TEST( test("-12345", short_(-s)));
+ BOOST_TEST(!test("-12345", short_(s)));
+
+ BOOST_TEST( test("1234567890", long_(1234567890)));
+ BOOST_TEST(!test("1234567890", long_(-1234567890)));
+ BOOST_TEST( test("1234567890", long_(l)));
+ BOOST_TEST(!test("1234567890", long_(-l)));
+
+ BOOST_TEST( test("-1234567890", long_(-1234567890)));
+ BOOST_TEST(!test("-1234567890", long_(1234567890)));
+ BOOST_TEST( test("-1234567890", long_(-l)));
+ BOOST_TEST(!test("-1234567890", long_(l)));
+ }
+
+ return boost::report_errors();
+}

Deleted: trunk/libs/spirit/test/qi/uint.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/uint.cpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
+++ (empty file)
@@ -1,226 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
- Copyright (c) 2001-2010 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 <climits>
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/qi_numeric.hpp>
-#include <boost/spirit/include/qi_char.hpp>
-#include <boost/spirit/include/qi_action.hpp>
-#include <boost/spirit/include/support_argument.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include "test.hpp"
-#include <cstring>
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// *** BEWARE PLATFORM DEPENDENT!!! ***
-// *** The following assumes 32 bit integers and 64 bit long longs.
-// *** Modify these constant strings when appropriate.
-//
-///////////////////////////////////////////////////////////////////////////////
-
- char const* max_unsigned = "4294967295";
- char const* unsigned_overflow = "4294967296";
- char const* max_int = "2147483647";
- char const* int_overflow = "2147483648";
- char const* min_int = "-2147483648";
- char const* int_underflow = "-2147483649";
- char const* max_binary = "11111111111111111111111111111111";
- char const* binary_overflow = "100000000000000000000000000000000";
- char const* max_octal = "37777777777";
- char const* octal_overflow = "100000000000";
- char const* max_hex = "FFFFFFFF";
- char const* hex_overflow = "100000000";
-
-///////////////////////////////////////////////////////////////////////////////
-// A custom int type
-struct custom_int
-{
- int n;
- custom_int() : n(0) {}
- explicit custom_int(int n_) : n(n_) {}
- custom_int& operator=(int n_) { n = n_; return *this; }
- friend custom_int operator*(custom_int a, custom_int b)
- { return custom_int(a.n * b.n); }
- friend custom_int operator+(custom_int a, custom_int b)
- { return custom_int(a.n + b.n); }
-};
-
-int
-main()
-{
- using spirit_test::test;
- using spirit_test::test_attr;
- ///////////////////////////////////////////////////////////////////////////
- // unsigned tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::uint_;
- unsigned u;
-
- BOOST_TEST(test("123456", uint_));
- BOOST_TEST(test_attr("123456", uint_, u));
- BOOST_TEST(u == 123456);
-
- BOOST_TEST(test(max_unsigned, uint_));
- BOOST_TEST(test_attr(max_unsigned, uint_, u));
- BOOST_TEST(u == UINT_MAX);
-
- BOOST_TEST(!test(unsigned_overflow, uint_));
- BOOST_TEST(!test_attr(unsigned_overflow, uint_, u));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // binary tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::bin;
- unsigned u;
-
- BOOST_TEST(test("11111110", bin));
- BOOST_TEST(test_attr("11111110", bin, u));
- BOOST_TEST(u == 0xFE);
-
- BOOST_TEST(test(max_binary, bin));
- BOOST_TEST(test_attr(max_binary, bin, u));
- BOOST_TEST(u == UINT_MAX);
-
- BOOST_TEST(!test(binary_overflow, bin));
- BOOST_TEST(!test_attr(binary_overflow, bin, u));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // octal tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::oct;
- unsigned u;
-
- BOOST_TEST(test("12545674515", oct));
- BOOST_TEST(test_attr("12545674515", oct, u));
- BOOST_TEST(u == 012545674515);
-
- BOOST_TEST(test(max_octal, oct));
- BOOST_TEST(test_attr(max_octal, oct, u));
- BOOST_TEST(u == UINT_MAX);
-
- BOOST_TEST(!test(octal_overflow, oct));
- BOOST_TEST(!test_attr(octal_overflow, oct, u));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // hex tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::hex;
- unsigned u;
-
- BOOST_TEST(test("95BC8DF", hex));
- BOOST_TEST(test_attr("95BC8DF", hex, u));
- BOOST_TEST(u == 0x95BC8DF);
-
- BOOST_TEST(test("abcdef12", hex));
- BOOST_TEST(test_attr("abcdef12", hex, u));
- BOOST_TEST(u == 0xabcdef12);
-
- BOOST_TEST(test(max_hex, hex));
- BOOST_TEST(test_attr(max_hex, hex, u));
- BOOST_TEST(u == UINT_MAX);
-
- BOOST_TEST(!test(hex_overflow, hex));
- BOOST_TEST(!test_attr(hex_overflow, hex, u));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // limited fieldwidth
- ///////////////////////////////////////////////////////////////////////////
- {
- unsigned u;
- using boost::spirit::qi::uint_parser;
-
- uint_parser<unsigned, 10, 1, 3> uint3;
- BOOST_TEST(test("123456", uint3, false));
- BOOST_TEST(test_attr("123456", uint3, u, false));
- BOOST_TEST(u == 123);
-
- uint_parser<unsigned, 10, 2, 4> uint4;
- BOOST_TEST(test("123456", uint4, false));
- BOOST_TEST(test_attr("123456", uint4, u, false));
- BOOST_TEST(u == 1234);
-
- char const * first = "0000000";
- char const * last = first + std::strlen(first);
- uint_parser<unsigned, 10, 4, 4> uint_exact4;
- BOOST_TEST(boost::spirit::qi::parse(first, last, uint_exact4, u)
- && first != last && (last-first == 3) && u == 0);
-
- first = "0001400";
- last = first + std::strlen(first);
- BOOST_TEST(boost::spirit::qi::parse(first, last, uint_exact4, u)
- && first != last && (last-first == 3) && u == 1);
-
- BOOST_TEST(!test("1", uint4));
- BOOST_TEST(!test_attr("1", uint4, u));
- BOOST_TEST(test_attr("014567", uint4, u, false) && u == 145);
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // uint_parser<unused_type> tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::uint_parser;
- using boost::spirit::qi::unused_type;
- uint_parser<unused_type> any_int;
-
- BOOST_TEST(test("123456", any_int));
- BOOST_TEST(test("1234567890123456789", any_int));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // action tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::phoenix::ref;
- using boost::spirit::qi::_1;
- using boost::spirit::qi::uint_;
- using boost::spirit::ascii::space;
- int n;
-
- BOOST_TEST(test("123", uint_[ref(n) = _1]));
- BOOST_TEST(n == 123);
- BOOST_TEST(test(" 456", uint_[ref(n) = _1], space));
- BOOST_TEST(n == 456);
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // Check overflow is parse error
- ///////////////////////////////////////////////////////////////////////////
- {
- boost::spirit::qi::uint_parser<boost::uint8_t> uint8_;
- boost::uint8_t u;
-
- BOOST_TEST(!test_attr("999", uint8_, u));
- }
-
- ///////////////////////////////////////////////////////////////////////////
- // custom uint tests
- ///////////////////////////////////////////////////////////////////////////
- {
- using boost::spirit::qi::uint_;
- using boost::spirit::qi::uint_parser;
- custom_int u;
-
- BOOST_TEST(test_attr("123456", uint_, u));
-
- uint_parser<custom_int, 10, 1, 2> uint2;
- BOOST_TEST(test_attr("12", uint2, u));
- }
-
- return boost::report_errors();
-}

Added: trunk/libs/spirit/test/qi/uint.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/uint.hpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -0,0 +1,62 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Bryce Lelbach
+
+ 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_TEST_QI_UINT_HPP)
+#define BOOST_SPIRIT_TEST_QI_UINT_HPP
+
+#include <climits>
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include "test.hpp"
+#include <cstring>
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// *** BEWARE PLATFORM DEPENDENT!!! ***
+// *** The following assumes 32 bit integers and 64 bit long longs.
+// *** Modify these constant strings when appropriate.
+//
+///////////////////////////////////////////////////////////////////////////////
+
+ char const* max_unsigned = "4294967295";
+ char const* unsigned_overflow = "4294967296";
+ char const* max_int = "2147483647";
+ char const* int_overflow = "2147483648";
+ char const* min_int = "-2147483648";
+ char const* int_underflow = "-2147483649";
+ char const* max_binary = "11111111111111111111111111111111";
+ char const* binary_overflow = "100000000000000000000000000000000";
+ char const* max_octal = "37777777777";
+ char const* octal_overflow = "100000000000";
+ char const* max_hex = "FFFFFFFF";
+ char const* hex_overflow = "100000000";
+
+///////////////////////////////////////////////////////////////////////////////
+// A custom int type
+struct custom_int
+{
+ int n;
+ custom_int() : n(0) {}
+ explicit custom_int(int n_) : n(n_) {}
+ custom_int& operator=(int n_) { n = n_; return *this; }
+ friend bool operator==(custom_int a, custom_int b)
+ { return a.n == b.n; }
+ friend custom_int operator*(custom_int a, custom_int b)
+ { return custom_int(a.n * b.n); }
+ friend custom_int operator+(custom_int a, custom_int b)
+ { return custom_int(a.n + b.n); }
+};
+
+#endif
+

Copied: trunk/libs/spirit/test/qi/uint1.cpp (from r67493, /trunk/libs/spirit/test/qi/uint.cpp)
==============================================================================
--- /trunk/libs/spirit/test/qi/uint.cpp (original)
+++ trunk/libs/spirit/test/qi/uint1.cpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -1,56 +1,13 @@
 /*=============================================================================
- Copyright (c) 2001-2010 Joel de Guzman
- Copyright (c) 2001-2010 Hartmut Kaiser
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Bryce Lelbach
 
     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 <climits>
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/qi_numeric.hpp>
-#include <boost/spirit/include/qi_char.hpp>
-#include <boost/spirit/include/qi_action.hpp>
-#include <boost/spirit/include/support_argument.hpp>
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include "test.hpp"
-#include <cstring>
-
-///////////////////////////////////////////////////////////////////////////////
-//
-// *** BEWARE PLATFORM DEPENDENT!!! ***
-// *** The following assumes 32 bit integers and 64 bit long longs.
-// *** Modify these constant strings when appropriate.
-//
-///////////////////////////////////////////////////////////////////////////////
-
- char const* max_unsigned = "4294967295";
- char const* unsigned_overflow = "4294967296";
- char const* max_int = "2147483647";
- char const* int_overflow = "2147483648";
- char const* min_int = "-2147483648";
- char const* int_underflow = "-2147483649";
- char const* max_binary = "11111111111111111111111111111111";
- char const* binary_overflow = "100000000000000000000000000000000";
- char const* max_octal = "37777777777";
- char const* octal_overflow = "100000000000";
- char const* max_hex = "FFFFFFFF";
- char const* hex_overflow = "100000000";
-
-///////////////////////////////////////////////////////////////////////////////
-// A custom int type
-struct custom_int
-{
- int n;
- custom_int() : n(0) {}
- explicit custom_int(int n_) : n(n_) {}
- custom_int& operator=(int n_) { n = n_; return *this; }
- friend custom_int operator*(custom_int a, custom_int b)
- { return custom_int(a.n * b.n); }
- friend custom_int operator+(custom_int a, custom_int b)
- { return custom_int(a.n + b.n); }
-};
+
+#include "uint.hpp"
 
 int
 main()

Added: trunk/libs/spirit/test/qi/uint2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/uint2.cpp 2010-12-30 16:55:39 EST (Thu, 30 Dec 2010)
@@ -0,0 +1,89 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Bryce Lelbach
+
+ 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 "uint.hpp"
+
+int
+main()
+{
+ using spirit_test::test;
+ using spirit_test::test_attr;
+ ///////////////////////////////////////////////////////////////////////////
+ // unsigned tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::uint_;
+ unsigned u = 123456;
+
+ BOOST_TEST( test("123456", uint_(123456)));
+ BOOST_TEST(!test("123456", uint_(4321)));
+ BOOST_TEST( test("123456", uint_(u)));
+ BOOST_TEST(!test("123456", uint_(u - 1)));
+
+ BOOST_TEST(test(max_unsigned, uint_(UINT_MAX)));
+
+ BOOST_TEST(!test(unsigned_overflow, uint_(345)));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // binary tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::bin;
+ unsigned u = 0xFE;
+
+ BOOST_TEST( test("11111110", bin(0xFE)));
+ BOOST_TEST(!test("11111110", bin(0xEF)));
+ BOOST_TEST( test("11111110", bin(u)));
+ BOOST_TEST(!test("11111110", bin(u - 1)));
+
+ BOOST_TEST(test(max_binary, bin(UINT_MAX)));
+
+ BOOST_TEST(!test(binary_overflow, bin(9)));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // octal literal tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::oct;
+ unsigned u = 012545674515;
+
+ BOOST_TEST( test("12545674515", oct(012545674515)));
+ BOOST_TEST(!test("12545674515", oct(051554521)));
+ BOOST_TEST( test("12545674515", oct(u)));
+ BOOST_TEST(!test("12545674515", oct(u + 1)));
+
+ BOOST_TEST(test(max_octal, oct(UINT_MAX)));
+
+ BOOST_TEST(!test(octal_overflow, oct(12)));
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // hex literal tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::qi::hex;
+ unsigned u = 0x95BC8DF;
+
+ BOOST_TEST( test("95BC8DF", hex(0x95BC8DF)));
+ BOOST_TEST(!test("95BC8DF", hex(0xFD8C9)));
+ BOOST_TEST( test("95BC8DF", hex(u)));
+ BOOST_TEST(!test("95BC8DF", hex(u + 1)));
+
+ BOOST_TEST( test("abcdef12", hex(0xabcdef12)));
+ BOOST_TEST(!test("abcdef12", hex(0x12abcdef)));
+
+ BOOST_TEST(test(max_hex, hex(UINT_MAX)));
+
+ BOOST_TEST(!test(hex_overflow, hex(0xdd)));
+ }
+
+ 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