|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63681 - in trunk/libs/spirit/example: karma scheme/input
From: hartmut.kaiser_at_[hidden]
Date: 2010-07-05 22:24:27
Author: hkaiser
Date: 2010-07-05 22:24:26 EDT (Mon, 05 Jul 2010)
New Revision: 63681
URL: http://svn.boost.org/trac/boost/changeset/63681
Log:
Spirit: Fixing examples
Text files modified:
trunk/libs/spirit/example/karma/calc2_ast.hpp | 23 ++++++++++++++++-------
trunk/libs/spirit/example/karma/calc2_ast_vm.hpp | 23 +++++++++++++++++------
trunk/libs/spirit/example/scheme/input/sexpr.hpp | 2 +-
3 files changed, 34 insertions(+), 14 deletions(-)
Modified: trunk/libs/spirit/example/karma/calc2_ast.hpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast.hpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast.hpp 2010-07-05 22:24:26 EDT (Mon, 05 Jul 2010)
@@ -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/include/karma_domain.hpp>
+#include <boost/spirit/include/support_attributes_fwd.hpp>
///////////////////////////////////////////////////////////////////////////////
// Our AST
@@ -82,16 +83,24 @@
return boost::get<T>(expr.expr);
}
- // 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();
+ }
+ };
}}
}
Modified: trunk/libs/spirit/example/karma/calc2_ast_vm.hpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_vm.hpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast_vm.hpp 2010-07-05 22:24:26 EDT (Mon, 05 Jul 2010)
@@ -18,11 +18,12 @@
#if !defined(SPIRIT_EXAMPLE_CALC2_AST_APR_30_2008_1011AM)
#define SPIRIT_EXAMPLE_CALC2_AST_APR_30_2008_1011AM
-#include <boost/variant/recursive_variant.hpp>
-#include <boost/variant/get.hpp>
+#include <boost/variant.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/include/karma_domain.hpp>
+#include <boost/spirit/include/support_attributes_fwd.hpp>
///////////////////////////////////////////////////////////////////////////////
// Our AST
@@ -86,12 +87,22 @@
// 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();
+ }
+ };
}}
}
Modified: trunk/libs/spirit/example/scheme/input/sexpr.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/input/sexpr.hpp (original)
+++ trunk/libs/spirit/example/scheme/input/sexpr.hpp 2010-07-05 22:24:26 EDT (Mon, 05 Jul 2010)
@@ -122,12 +122,12 @@
byte_str = lexeme['#' > +hex2 > '#'];
start.name("sexpr");
- start.name("sexpr");
list.name("list");
atom.name("atom");
symbol.name("symbol");
integer.name("integer");
byte_str.name("byte_str");
+
on_error<fail>(start, error_handler(_1, _2, _3, _4));
}
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