Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r55127 - in trunk/boost/spirit/home: qi qi/auxiliary support
From: hartmut.kaiser_at_[hidden]
Date: 2009-07-23 11:54:20


Author: hkaiser
Date: 2009-07-23 11:54:19 EDT (Thu, 23 Jul 2009)
New Revision: 55127
URL: http://svn.boost.org/trac/boost/changeset/55127

Log:
Spirit: added attr() pseudo parser
Added:
   trunk/boost/spirit/home/qi/auxiliary/attr.hpp (contents, props changed)
Text files modified:
   trunk/boost/spirit/home/qi/auxiliary.hpp | 1 +
   trunk/boost/spirit/home/support/attributes.hpp | 5 +++--
   trunk/boost/spirit/home/support/common_terminals.hpp | 1 +
   trunk/boost/spirit/home/support/container.hpp | 6 +++---
   4 files changed, 8 insertions(+), 5 deletions(-)

Modified: trunk/boost/spirit/home/qi/auxiliary.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/auxiliary.hpp (original)
+++ trunk/boost/spirit/home/qi/auxiliary.hpp 2009-07-23 11:54:19 EDT (Thu, 23 Jul 2009)
@@ -16,5 +16,6 @@
 #include <boost/spirit/home/qi/auxiliary/lazy.hpp>
 #include <boost/spirit/home/qi/auxiliary/eol.hpp>
 #include <boost/spirit/home/qi/auxiliary/eoi.hpp>
+#include <boost/spirit/home/qi/auxiliary/attr.hpp>
 
 #endif

Added: trunk/boost/spirit/home/qi/auxiliary/attr.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/qi/auxiliary/attr.hpp 2009-07-23 11:54:19 EDT (Thu, 23 Jul 2009)
@@ -0,0 +1,91 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 Hartmut Kaiser
+ Copyright (c) 2001-2009 Joel de Guzman
+
+ 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_ATTR_JUL_23_2008_0956AM)
+#define BOOST_SPIRIT_ATTR_JUL_23_2008_0956AM
+
+#include <boost/mpl/bool.hpp>
+#include <boost/spirit/home/qi/domain.hpp>
+#include <boost/spirit/home/qi/parser.hpp>
+#include <boost/spirit/home/qi/detail/assign_to.hpp>
+#include <boost/spirit/home/qi/meta_compiler.hpp>
+#include <boost/spirit/home/support/common_terminals.hpp>
+
+namespace boost { namespace spirit
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // Enablers
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename A0> // enables attr()
+ struct use_terminal<
+ qi::domain, terminal_ex<tag::attr, fusion::vector1<A0> > >
+ : mpl::true_ {};
+
+ template <> // enables *lazy* attr()
+ struct use_lazy_terminal<qi::domain, tag::attr, 1>
+ : mpl::true_ {};
+
+}}
+
+namespace boost { namespace spirit { namespace qi
+{
+ using spirit::attr;
+
+ template <typename Value>
+ struct attr_parser : primitive_parser<attr_parser<Value> >
+ {
+ template <typename Context, typename Iterator>
+ struct attribute
+ {
+ typedef Value type;
+ };
+
+ attr_parser(typename add_reference<Value>::type value)
+ : value_(value) {}
+
+ 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::detail::assign_to(value_, attr);
+ return true; // never consume any input, succeed always
+ }
+
+ template <typename Context>
+ info what(Context& context) const
+ {
+ return info("attr");
+ }
+
+ Value value_;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Parser generators: make_xxx function (objects)
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Modifiers, typename A0>
+ struct make_primitive<
+ terminal_ex<tag::attr, fusion::vector1<A0> >
+ , Modifiers>
+ {
+ typedef typename add_const<A0>::type const_value;
+ typedef attr_parser<const_value> result_type;
+
+ template <typename Terminal>
+ result_type operator()(Terminal const& term, unused_type) const
+ {
+ return result_type(fusion::at_c<0>(term.args));
+ }
+ };
+
+}}}
+
+#endif
+
+

Modified: trunk/boost/spirit/home/support/attributes.hpp
==============================================================================
--- trunk/boost/spirit/home/support/attributes.hpp (original)
+++ trunk/boost/spirit/home/support/attributes.hpp 2009-07-23 11:54:19 EDT (Thu, 23 Jul 2009)
@@ -1,5 +1,6 @@
 /*=============================================================================
     Copyright (c) 2001-2009 Joel de Guzman
+ 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)
@@ -423,7 +424,7 @@
     {
         typedef T type;
     };
-
+
     ///////////////////////////////////////////////////////////////////////////
     // clear
     //
@@ -492,7 +493,7 @@
         if (val)
             clear(*val);
     }
-
+
     // variants
     template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
     void clear(variant<BOOST_VARIANT_ENUM_PARAMS(T)>& var)

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-07-23 11:54:19 EDT (Thu, 23 Jul 2009)
@@ -75,6 +75,7 @@
         ( set_state )
         ( in_state )
         ( token )
+ ( attr )
     )
 }}
 

Modified: trunk/boost/spirit/home/support/container.hpp
==============================================================================
--- trunk/boost/spirit/home/support/container.hpp (original)
+++ trunk/boost/spirit/home/support/container.hpp 2009-07-23 11:54:19 EDT (Thu, 23 Jul 2009)
@@ -71,13 +71,13 @@
         {
             typedef T type;
         };
-
+
         template <typename T>
         struct remove_value_const<T const>
         {
             typedef typename remove_value_const<T>::type type;
         };
-
+
         template <typename F, typename S>
         struct remove_value_const<std::pair<F, S> >
         {
@@ -92,7 +92,7 @@
         ///////////////////////////////////////////////////////////////////////
         template <typename Container>
         struct value
- {
+ {
             typedef typename detail::remove_value_const<
                 typename Container::value_type>::type
             type;


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