|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r61679 - in trunk/libs/spirit/example/scheme: example/generate_qiexpr output qi
From: hartmut.kaiser_at_[hidden]
Date: 2010-04-29 12:18:10
Author: hkaiser
Date: 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
New Revision: 61679
URL: http://svn.boost.org/trac/boost/changeset/61679
Log:
Spirit: Qi generator fully functional now
Text files modified:
trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qi_test.cpp | 10 ++--
trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qiexpr.cpp | 1
trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_sexpr_to_ostream.cpp | 1
trunk/libs/spirit/example/scheme/output/utree_traits.hpp | 94 ++++++++++++++++++++++++++++-----------
trunk/libs/spirit/example/scheme/qi/generate_qiexpr.hpp | 3 +
trunk/libs/spirit/example/scheme/qi/generate_qiexpr_impl.hpp | 12 +++++
trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp | 41 ++++++++++++++---
7 files changed, 121 insertions(+), 41 deletions(-)
Modified: trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qi_test.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qi_test.cpp (original)
+++ trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qi_test.cpp 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
@@ -24,8 +24,8 @@
{
if (scheme::input::parse_qi_expr(str, result))
{
-// std::string scheme_str;
-// scheme::output::generate_sexpr(scheme_str, result);
+ std::string scheme_str;
+ scheme::output::generate_sexpr(scheme_str, result);
std::string strout;
if (scheme::output::generate_qi_expr(result, strout))
@@ -72,10 +72,10 @@
if (scheme::input::parse_qi_grammar(str, result))
{
std::string scheme_str;
- scheme::output::generate_sexpr(scheme_str, result);
+ scheme::output::generate_sexpr_list(scheme_str, result);
std::string strout;
- if (scheme::output::generate_qi_expr(result, strout))
+ if (scheme::output::generate_qi_expr_list(result, strout))
{
std::cout << strout << std::endl;
return true;
@@ -115,7 +115,7 @@
}
// now test grammar rule
-// BOOST_TEST(test_grammar(rules));
+ BOOST_TEST(test_grammar(rules));
return boost::report_errors();
}
Modified: trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qiexpr.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qiexpr.cpp (original)
+++ trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_qiexpr.cpp 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
@@ -14,6 +14,7 @@
namespace scheme { namespace output
{
template bool generate_qi_expr(utree& u, std::string& str);
+ template bool generate_qi_expr_list(utree& u, std::string& str);
}}
namespace scheme
Modified: trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_sexpr_to_ostream.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_sexpr_to_ostream.cpp (original)
+++ trunk/libs/spirit/example/scheme/example/generate_qiexpr/generate_sexpr_to_ostream.cpp 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
@@ -14,6 +14,7 @@
{
template bool generate_sexpr(BOOST_TYPEOF(std::cout)&, utree const& result);
template bool generate_sexpr(std::string& str, utree const& result);
+ template bool generate_sexpr_list(std::string& str, utree const& result);
}}
#if defined(SCHEME_USE_SPIRIT_IO)
Modified: trunk/libs/spirit/example/scheme/output/utree_traits.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/output/utree_traits.hpp (original)
+++ trunk/libs/spirit/example/scheme/output/utree_traits.hpp 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
@@ -11,7 +11,6 @@
#include <string>
#include <boost/cstdint.hpp>
-#include <boost/mpl/bool.hpp>
#include <boost/spirit/include/karma.hpp>
///////////////////////////////////////////////////////////////////////////////
@@ -42,9 +41,11 @@
: mpl::true_
{
typedef iterator_range<scheme::utree::iterator> compatible_type;
- typedef mpl::int_<scheme::utree_type::list_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::list_type;
+ }
};
template <>
@@ -53,9 +54,11 @@
: mpl::true_
{
typedef iterator_range<scheme::utree::const_iterator> compatible_type;
- typedef mpl::int_<scheme::utree_type::list_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::list_type;
+ }
};
template <>
@@ -63,9 +66,11 @@
: mpl::true_
{
typedef scheme::nil compatible_type;
- typedef mpl::int_<scheme::utree_type::nil_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::nil_type;
+ }
};
template <>
@@ -73,9 +78,11 @@
: mpl::true_
{
typedef bool compatible_type;
- typedef mpl::int_<scheme::utree_type::bool_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::bool_type;
+ }
};
template <>
@@ -83,9 +90,11 @@
: mpl::true_
{
typedef int compatible_type;
- typedef mpl::int_<scheme::utree_type::int_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::int_type;
+ }
};
template <>
@@ -93,9 +102,11 @@
: mpl::true_
{
typedef double compatible_type;
- typedef mpl::int_<scheme::utree_type::double_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::double_type;
+ }
};
template <>
@@ -104,9 +115,11 @@
: mpl::true_
{
typedef scheme::utf8_string_range compatible_type;
- typedef mpl::int_<scheme::utree_type::string_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::string_type;
+ }
};
template <>
@@ -115,9 +128,11 @@
: mpl::true_
{
typedef scheme::utf8_string compatible_type;
- typedef mpl::int_<scheme::utree_type::string_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::string_type;
+ }
};
template <>
@@ -126,9 +141,11 @@
: mpl::true_
{
typedef scheme::utf8_symbol_range compatible_type;
- typedef mpl::int_<scheme::utree_type::symbol_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::symbol_type;
+ }
};
template <>
@@ -137,9 +154,11 @@
: mpl::true_
{
typedef scheme::utf8_symbol compatible_type;
- typedef mpl::int_<scheme::utree_type::symbol_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::symbol_type;
+ }
};
template <>
@@ -148,9 +167,11 @@
: mpl::true_
{
typedef scheme::binary_range compatible_type;
- typedef mpl::int_<scheme::utree_type::binary_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::binary_type;
+ }
};
template <>
@@ -159,9 +180,11 @@
: mpl::true_
{
typedef scheme::binary_string compatible_type;
- typedef mpl::int_<scheme::utree_type::binary_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::binary_type;
+ }
};
template <>
@@ -169,7 +192,20 @@
: mpl::true_
{
typedef scheme::utree compatible_type;
- typedef mpl::int_<scheme::utree_type::reference_type> distance;
+
+ static bool is_compatible(int d)
+ {
+ return d >= scheme::utree_type::nil_type &&
+ d <= scheme::utree_type::reference_type;
+ }
+ };
+
+ template <>
+ struct compute_compatible_component_variant<
+ scheme::utree, std::vector<scheme::utree> >
+ : mpl::true_
+ {
+ typedef scheme::utree compatible_type;
static bool is_compatible(int d)
{
@@ -185,9 +221,11 @@
: mpl::true_
{
typedef iterator_range<scheme::utree::const_iterator> compatible_type;
- typedef mpl::int_<scheme::utree_type::list_type> distance;
- static bool is_compatible(int d) { return d == distance::value; }
+ static bool is_compatible(int d)
+ {
+ return d == scheme::utree_type::list_type;
+ }
};
///////////////////////////////////////////////////////////////////////////
Modified: trunk/libs/spirit/example/scheme/qi/generate_qiexpr.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/qi/generate_qiexpr.hpp (original)
+++ trunk/libs/spirit/example/scheme/qi/generate_qiexpr.hpp 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
@@ -12,6 +12,9 @@
{
template <typename String>
bool generate_qi_expr(utree& result, String& str);
+
+ template <typename String>
+ bool generate_qi_expr_list(utree& result, String& str);
}}
#endif
Modified: trunk/libs/spirit/example/scheme/qi/generate_qiexpr_impl.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/qi/generate_qiexpr_impl.hpp (original)
+++ trunk/libs/spirit/example/scheme/qi/generate_qiexpr_impl.hpp 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
@@ -25,6 +25,18 @@
scheme::qi::qiexpr_generator<output_iterator_type> g;
return generate_delimited(output_iterator_type(str), g, space, u);
}
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename String>
+ bool generate_qi_expr_list(utree& u, String& str)
+ {
+ using boost::spirit::karma::space;
+
+ typedef std::back_insert_iterator<String> output_iterator_type;
+
+ scheme::qi::qiexpr_generator<output_iterator_type> g;
+ return generate_delimited(output_iterator_type(str), g.grammar_, space, u);
+ }
}}
#endif
Modified: trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp (original)
+++ trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp 2010-04-29 12:18:09 EDT (Thu, 29 Apr 2010)
@@ -33,6 +33,26 @@
using boost::spirit::karma::symbols;
///////////////////////////////////////////////////////////////////////////
+ namespace traits
+ {
+ template <typename Count>
+ struct deref_spec
+ : boost::spirit::result_of::terminal<boost::spirit::tag::repeat(Count)>
+ {};
+ };
+
+ template <typename Count>
+ inline typename traits::deref_spec<Count>::type
+ deref_spec(Count const& count)
+ {
+ using boost::spirit::karma::repeat;
+ return repeat(count);
+ }
+
+ typedef traits::deref_spec<int>::type deref_tag_type;
+ deref_tag_type const deref = deref_spec(1);
+
+ ///////////////////////////////////////////////////////////////////////////
template <typename OutputIterator>
struct qiexpr_generator : grammar<OutputIterator, space_type, utree()>
{
@@ -43,20 +63,23 @@
using boost::spirit::karma::eps;
using boost::spirit::karma::ascii::string;
using boost::spirit::karma::omit;
- using boost::spirit::karma::repeat;
using boost::spirit::karma::_r1;
using boost::spirit::karma::strict;
using boost::spirit::karma::eol;
start =
nil
- | rule_ % eol
| rule_
;
+ grammar_ =
+ nil
+ | rule_ % eol
+ ;
+
rule_ =
&symbol(std::string("define"))
- << repeat(1)[rule_name] << '=' << repeat(1)[alternative]
+ << deref[rule_name] << '=' << deref[alternative]
| alternative
;
@@ -79,18 +102,18 @@
;
term = strict[
- unary << '(' << repeat(1)[alternative] << ')'
+ unary << '(' << deref[alternative] << ')'
| primitive2 << '(' << literal << ',' << literal << ')'
| primitive1 << '(' << literal << ')'
| primitive0_rule
- | directive0 << '[' << repeat(1)[alternative] << ']'
+ | directive0 << '[' << deref[alternative] << ']'
| alternative_rule
];
- primitive0_rule = strict[repeat(1)[primitive0]];
+ primitive0_rule = strict[deref[primitive0]];
alternative_rule = alternative;
- rule_name = strict[repeat(1)[any_symbol]];
+ rule_name = strict[deref[any_symbol]];
any_symbol = string;
symbol = string(_r1);
@@ -115,6 +138,7 @@
directive0.add(utf8_symbol(name + *p));
BOOST_SPIRIT_DEBUG_NODE(start);
+ BOOST_SPIRIT_DEBUG_NODE(grammar_);
BOOST_SPIRIT_DEBUG_NODE(rule_);
BOOST_SPIRIT_DEBUG_NODE(rule_name);
BOOST_SPIRIT_DEBUG_NODE(alternative);
@@ -132,7 +156,8 @@
typedef rule<OutputIterator, space_type, utree()> delimiting_rule_type;
delimiting_rule_type start, alternative, permutation, sequence, term;
- delimiting_rule_type rule_, rule_name, primitive0_rule, alternative_rule;
+ delimiting_rule_type grammar_, rule_;
+ delimiting_rule_type rule_name, primitive0_rule, alternative_rule;
rule<OutputIterator, nil()> nil;
rule<OutputIterator, scheme::utf8_string()> literal;
rule<OutputIterator, scheme::utf8_symbol(std::string)> symbol;
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