$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r61273 - in trunk/libs/spirit/example/scheme: . input
From: joel_at_[hidden]
Date: 2010-04-14 08:00:26
Author: djowel
Date: 2010-04-14 08:00:25 EDT (Wed, 14 Apr 2010)
New Revision: 61273
URL: http://svn.boost.org/trac/boost/changeset/61273
Log:
tweaks
Text files modified: 
   trunk/libs/spirit/example/scheme/input/parse_sexpr.hpp      |    31 ++++++++++++++++++++++---------         
   trunk/libs/spirit/example/scheme/input/parse_sexpr_impl.hpp |    40 ++++++++++++++++++++++++++++------------
   trunk/libs/spirit/example/scheme/scheme_compiler.hpp        |    36 +++++++++++++++++++++++++++++++++++-    
   trunk/libs/spirit/example/scheme/scheme_interpreter.hpp     |     2 +-                                      
   4 files changed, 86 insertions(+), 23 deletions(-)
Modified: trunk/libs/spirit/example/scheme/input/parse_sexpr.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/input/parse_sexpr.hpp	(original)
+++ trunk/libs/spirit/example/scheme/input/parse_sexpr.hpp	2010-04-14 08:00:25 EDT (Wed, 14 Apr 2010)
@@ -1,6 +1,7 @@
 //  Copyright (c) 2001-2010 Hartmut Kaiser
-// 
-//  Distributed under the Boost Software License, Version 1.0. (See accompanying 
+//  Copyright (c) 2001-2010 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_PARSE_SEXPR)
@@ -8,24 +9,36 @@
 
 #include "../utree.hpp"
 #include "../input/sexpr.hpp"
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_base_of.hpp>
 #include <iosfwd>
-#include <string>
 
 namespace scheme { namespace input
 {
     ///////////////////////////////////////////////////////////////////////////
     template <typename Char>
-    bool parse_sexpr(std::basic_istream<Char>& is, utree& result);
+    bool
+    parse_sexpr(std::basic_istream<Char>& is, utree& result);
 
     template <typename Char>
-    bool parse_sexpr_list(std::basic_istream<Char>& is, utree& result);
+    bool
+    parse_sexpr_list(std::basic_istream<Char>& is, utree& result);
 
     ///////////////////////////////////////////////////////////////////////////
-    template <typename Char>
-    bool parse_sexpr(std::basic_string<Char>& str, utree& result);
+    template <typename Range>
+    typename boost::disable_if<
+        boost::is_base_of<std::ios_base, Range>, bool>::type
+    parse_sexpr(Range const& rng, utree& result);
+
+    template <typename Range>
+    typename boost::disable_if<
+        boost::is_base_of<std::ios_base, Range>, bool>::type
+    parse_sexpr_list(Range const& rng, utree& result);
 
-    template <typename Char>
-    bool parse_sexpr_list(std::basic_string<Char>& str, utree& result);
+    ///////////////////////////////////////////////////////////////////////////
+    bool parse_sexpr(utree const& in, utree& result);
+
+    bool parse_sexpr_list(utree const& in, utree& result);
 }}
 
 #endif
Modified: trunk/libs/spirit/example/scheme/input/parse_sexpr_impl.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/input/parse_sexpr_impl.hpp	(original)
+++ trunk/libs/spirit/example/scheme/input/parse_sexpr_impl.hpp	2010-04-14 08:00:25 EDT (Wed, 14 Apr 2010)
@@ -1,6 +1,7 @@
 //  Copyright (c) 2001-2010 Hartmut Kaiser
-// 
-//  Distributed under the Boost Software License, Version 1.0. (See accompanying 
+//  Copyright (c) 2001-2010 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_PARSE_SEXPR_IMPL)
@@ -18,7 +19,7 @@
 {
     ///////////////////////////////////////////////////////////////////////////
     template <typename Char>
-    bool parse_sexpr(std::basic_istream<Char>& is, utree& result)
+    inline bool parse_sexpr(std::basic_istream<Char>& is, utree& result)
     {
         // no white space skipping in the stream!
         is.unsetf(std::ios::skipws);
@@ -36,7 +37,7 @@
 
     ///////////////////////////////////////////////////////////////////////////
     template <typename Char>
-    bool parse_sexpr_list(std::basic_istream<Char>& is, utree& result)
+    inline bool parse_sexpr_list(std::basic_istream<Char>& is, utree& result)
     {
         // no white space skipping in the stream!
         is.unsetf(std::ios::skipws);
@@ -53,28 +54,43 @@
     }
 
     ///////////////////////////////////////////////////////////////////////////
-    template <typename Char>
-    bool parse_sexpr(std::basic_string<Char>& str, utree& result)
+    template <typename Range>
+    inline
+    typename boost::disable_if<boost::is_base_of<std::ios_base, Range>, bool>::type
+    parse_sexpr(Range const& rng, utree& result)
     {
-        typedef typename std::basic_string<Char>::const_iterator iterator_type;
+        typedef typename Range::const_iterator iterator_type;
 
         scheme::input::sexpr<iterator_type> p;
         scheme::input::sexpr_white_space<iterator_type> ws;
 
         using boost::spirit::qi::phrase_parse;
-        return phrase_parse(str.begin(), str.end(), p, ws, result);
+        return phrase_parse(rng.begin(), rng.end(), p, ws, result);
     }
 
-    template <typename Char>
-    bool parse_sexpr_list(std::basic_string<Char>& str, utree& result)
+    template <typename Range>
+    inline
+    typename boost::disable_if<boost::is_base_of<std::ios_base, Range>, bool>::type
+    parse_sexpr_list(Range const& rng, utree& result)
     {
-        typedef typename std::basic_string<Char>::const_iterator iterator_type;
+        typedef typename Range::const_iterator iterator_type;
 
         scheme::input::sexpr<iterator_type> p;
         scheme::input::sexpr_white_space<iterator_type> ws;
 
         using boost::spirit::qi::phrase_parse;
-        return phrase_parse(str.begin(), str.end(), +p, ws, result);
+        return phrase_parse(rng.begin(), rng.end(), +p, ws, result);
+    }
+
+    ///////////////////////////////////////////////////////////////////////////
+    inline bool parse_sexpr(utree const& in, utree& result)
+    {
+        return parse_sexpr(in.as<utf8_string_range>(), result);
+    }
+
+    inline bool parse_sexpr_list(utree const& in, utree& result)
+    {
+        return parse_sexpr_list(in.as<utf8_string_range>(), result);
     }
 }}
 
Modified: trunk/libs/spirit/example/scheme/scheme_compiler.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/scheme_compiler.hpp	(original)
+++ trunk/libs/spirit/example/scheme/scheme_compiler.hpp	2010-04-14 08:00:25 EDT (Wed, 14 Apr 2010)
@@ -1,4 +1,4 @@
-/*=============================================================================
+/*=============================================================================
     Copyright (c) 2001-2010 Joel de Guzman
 
     Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -222,6 +222,40 @@
         env.define("-", minus);
         env.define("*", times);
     }
+
+    ///////////////////////////////////////////////////////////////////////////
+    // interpreter
+    ///////////////////////////////////////////////////////////////////////////
+    template <typename Source>
+    struct interpreter : composite<interpreter<Source> >
+    {
+        interpreter(Source const& in, environment* outer = 0)
+        {
+            if (outer == 0)
+                build_basic_environment(env);
+
+            if (input::parse_sexpr_list(in, program))
+            {
+                compile_all(program, env, flist, fragments);
+            }
+            else
+            {
+                // $$$ Use exceptions $$$
+                BOOST_ASSERT(false);
+            }
+        }
+
+        using composite<interpreter<Source> >::operator();
+        actor operator()(actor_list const& elements) const
+        {
+            return actor(lambda_function(flist.back(), elements));
+        }
+
+        environment env;
+        utree program;
+        actor_list fragments;
+        actor_list flist;
+    };
 }
 
 #endif
Modified: trunk/libs/spirit/example/scheme/scheme_interpreter.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/scheme_interpreter.hpp	(original)
+++ trunk/libs/spirit/example/scheme/scheme_interpreter.hpp	2010-04-14 08:00:25 EDT (Wed, 14 Apr 2010)
@@ -126,7 +126,7 @@
         typedef utree result_type;
         utree operator()(args_type args) const
         {
-            return utree(boost::ref(*(args.begin()+n)));
+            return utree(boost::ref(args[n]));
         }
     };