|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56471 - in trunk/boost/spirit/home: karma/numeric qi qi/numeric
From: hartmut.kaiser_at_[hidden]
Date: 2009-09-29 10:30:55
Author: hkaiser
Date: 2009-09-29 10:30:54 EDT (Tue, 29 Sep 2009)
New Revision: 56471
URL: http://svn.boost.org/trac/boost/changeset/56471
Log:
Spirit: added qi::bool_
Added:
trunk/boost/spirit/home/qi/numeric/bool.hpp (contents, props changed)
trunk/boost/spirit/home/qi/numeric/bool_policies.hpp (contents, props changed)
Text files modified:
trunk/boost/spirit/home/karma/numeric/bool.hpp | 2 +-
trunk/boost/spirit/home/qi/numeric.hpp | 1 +
2 files changed, 2 insertions(+), 1 deletions(-)
Modified: trunk/boost/spirit/home/karma/numeric/bool.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/numeric/bool.hpp (original)
+++ trunk/boost/spirit/home/karma/numeric/bool.hpp 2009-09-29 10:30:54 EDT (Tue, 29 Sep 2009)
@@ -185,7 +185,7 @@
, Attribute const& attr) const
{
if (!traits::has_optional_value(attr) ||
- n_ != traits::optional_value(attr))
+ bool(n_) != bool(traits::optional_value(attr)))
{
return false;
}
Modified: trunk/boost/spirit/home/qi/numeric.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/numeric.hpp (original)
+++ trunk/boost/spirit/home/qi/numeric.hpp 2009-09-29 10:30:54 EDT (Tue, 29 Sep 2009)
@@ -11,6 +11,7 @@
#pragma once
#endif
+#include <boost/spirit/home/qi/numeric/bool.hpp>
#include <boost/spirit/home/qi/numeric/int.hpp>
#include <boost/spirit/home/qi/numeric/uint.hpp>
#include <boost/spirit/home/qi/numeric/real.hpp>
Added: trunk/boost/spirit/home/qi/numeric/bool.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/qi/numeric/bool.hpp 2009-09-29 10:30:54 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,114 @@
+/*=============================================================================
+ 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(SPIRIT_QI_BOOL_SEP_29_2009_0709AM)
+#define SPIRIT_QI_BOOL_SEP_29_2009_0709AM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/qi/skip_over.hpp>
+#include <boost/spirit/home/qi/meta_compiler.hpp>
+#include <boost/spirit/home/qi/parser.hpp>
+#include <boost/spirit/home/qi/numeric/bool_policies.hpp>
+#include <boost/spirit/home/support/common_terminals.hpp>
+#include <boost/spirit/home/support/info.hpp>
+#include <boost/mpl/assert.hpp>
+
+namespace boost { namespace spirit
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // Enablers
+ ///////////////////////////////////////////////////////////////////////////
+ template <>
+ struct use_terminal<qi::domain, tag::bool_> // enables bool_
+ : mpl::true_ {};
+}}
+
+namespace boost { namespace spirit { namespace qi
+{
+ using spirit::bool_;
+ using spirit::bool__type;
+
+ namespace detail
+ {
+ template <typename T, typename Policies>
+ struct bool_impl
+ {
+ template <typename Iterator, typename Attribute>
+ static bool parse(Iterator& first, Iterator const& last
+ , Attribute& attr, Policies const& p)
+ {
+ if (first == last)
+ return false;
+
+ return p.parse_true(first, last, attr) ||
+ p.parse_false(first, last, attr);
+ }
+ };
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // This actual boolean parser
+ ///////////////////////////////////////////////////////////////////////////
+ template <
+ typename T = bool
+ , typename Policies = bool_policies<T> >
+ struct bool_parser_impl
+ : primitive_parser<bool_parser_impl<T, Policies> >
+ {
+ template <typename Context, typename Iterator>
+ struct attribute
+ {
+ typedef T 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
+ {
+ qi::skip_over(first, last, skipper);
+ return detail::bool_impl<T, Policies>::
+ parse(first, last, attr, Policies());
+ }
+
+ template <typename Context>
+ info what(Context& /*context*/) const
+ {
+ return info("boolean");
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // uint_parser is the class that the user can instantiate directly
+ ///////////////////////////////////////////////////////////////////////////
+ template <
+ typename T
+ , typename Policies = bool_policies<T> >
+ struct bool_parser
+ : proto::terminal<bool_parser_impl<T, Policies> >::type
+ {
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Parser generators: make_xxx function (objects)
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Modifiers>
+ struct make_primitive<tag::bool_, Modifiers>
+ {
+ typedef bool_parser_impl<bool> result_type;
+ result_type operator()(unused_type, unused_type) const
+ {
+ return result_type();
+ }
+ };
+
+}}}
+
+#endif
Added: trunk/boost/spirit/home/qi/numeric/bool_policies.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/qi/numeric/bool_policies.hpp 2009-09-29 10:30:54 EDT (Tue, 29 Sep 2009)
@@ -0,0 +1,52 @@
+/*=============================================================================
+ 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(SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM)
+#define SPIRIT_QI_BOOL_POLICIES_SEP_29_2009_0710AM
+
+#if defined(_MSC_VER)
+#pragma once
+#endif
+
+#include <boost/spirit/home/qi/detail/string_parse.hpp>
+#include <boost/spirit/home/qi/detail/assign_to.hpp>
+
+namespace boost { namespace spirit { namespace qi
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // Default boolean policies
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename T = bool>
+ struct bool_policies
+ {
+ template <typename Iterator, typename Attribute>
+ static bool
+ parse_true(Iterator& first, Iterator const& last, Attribute& attr)
+ {
+ if (detail::string_parse("true", first, last, unused))
+ {
+ detail::assign_to(T(true), attr); // result is true
+ return true;
+ }
+ return false;
+ }
+
+ template <typename Iterator, typename Attribute>
+ static bool
+ parse_false(Iterator& first, Iterator const& last, Attribute& attr)
+ {
+ if (detail::string_parse("false", first, last, unused))
+ {
+ detail::assign_to(T(false), attr); // result is false
+ return true;
+ }
+ return false;
+ }
+ };
+
+}}}
+
+#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