Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76383 - in trunk/libs/spirit: doc repository/example/karma
From: hartmut.kaiser_at_[hidden]
Date: 2012-01-09 08:52:24


Author: hkaiser
Date: 2012-01-09 08:52:23 EST (Mon, 09 Jan 2012)
New Revision: 76383
URL: http://svn.boost.org/trac/boost/changeset/76383

Log:
Spirit: fixed Karma examples
Text files modified:
   trunk/libs/spirit/doc/what_s_new.qbk | 1 +
   trunk/libs/spirit/repository/example/karma/calc2_ast.hpp | 27 +++++++++++++++++++--------
   2 files changed, 20 insertions(+), 8 deletions(-)

Modified: trunk/libs/spirit/doc/what_s_new.qbk
==============================================================================
--- trunk/libs/spirit/doc/what_s_new.qbk (original)
+++ trunk/libs/spirit/doc/what_s_new.qbk 2012-01-09 08:52:23 EST (Mon, 09 Jan 2012)
@@ -25,6 +25,7 @@
   as sequences, Kleene, list, or plus.
 * Fixed `karma::subrule` from the [@../../repository/doc/html/index.html repository]
   (thanks to Lee Clagett for submitting a patch).
+* Fixed __karma__ examples (thanks to Lee Clagett for submitting a patch).
 
 [endsect]
 

Modified: trunk/libs/spirit/repository/example/karma/calc2_ast.hpp
==============================================================================
--- trunk/libs/spirit/repository/example/karma/calc2_ast.hpp (original)
+++ trunk/libs/spirit/repository/example/karma/calc2_ast.hpp 2012-01-09 08:52:23 EST (Mon, 09 Jan 2012)
@@ -1,6 +1,6 @@
 /*=============================================================================
     Copyright (c) 2001-2010 Joel de Guzman
- Copyright (c) 2001-2010 Hartmut Kaiser
+ Copyright (c) 2001-2012 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)
@@ -19,10 +19,11 @@
 #define SPIRIT_EXAMPLE_CALC2_AST_APR_30_2008_1011AM
 
 #include <boost/variant.hpp>
-#include <boost/variant/get.hpp>
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/spirit/include/phoenix_function.hpp>
 #include <boost/spirit/include/phoenix_statement.hpp>
+#include <boost/spirit/home/karma/domain.hpp>
+#include <boost/spirit/include/support_attributes_fwd.hpp>
 
 ///////////////////////////////////////////////////////////////////////////////
 // Our AST
@@ -42,7 +43,7 @@
>
     type;
 
- // expose variant types
+ // expose variant types
     typedef type::types types;
 
     // expose variant functionality
@@ -82,16 +83,26 @@
         return boost::get<T>(expr.expr);
     }
 
- // the specialization below tells Spirit to handle expression_ast as if it
+ // the specialization below tells Spirit to handle expression_ast as if it
     // where a 'real' variant
     namespace spirit { namespace traits
     {
- template <typename T>
- struct not_is_variant;
-
+ // the specialization below tells Spirit to handle expression_ast as
+ // if it where a 'real' variant (if used with Spirit.Karma)
         template <>
- struct not_is_variant<expression_ast>
+ struct not_is_variant<expression_ast, karma::domain>
           : mpl::false_ {};
+
+ // the specialization of variant_which allows to generically extract
+ // the current type stored in the given variant like type
+ template <>
+ struct variant_which<expression_ast>
+ {
+ static int call(expression_ast const& v)
+ {
+ return v.which();
+ }
+ };
     }}
 }
 


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