Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60925 - in trunk/libs/spirit/example/scheme: . input output
From: hartmut.kaiser_at_[hidden]
Date: 2010-03-29 21:58:24


Author: hkaiser
Date: 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
New Revision: 60925
URL: http://svn.boost.org/trac/boost/changeset/60925

Log:
Spirit: refactoring scheme code
Added:
   trunk/libs/spirit/example/scheme/input/parse_sexpr.hpp (contents, props changed)
   trunk/libs/spirit/example/scheme/input/parse_sexpr_impl.hpp (contents, props changed)
   trunk/libs/spirit/example/scheme/output/generate_sexpr.hpp (contents, props changed)
   trunk/libs/spirit/example/scheme/output/generate_sexpr_impl.hpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/example/scheme/input/sexpr.hpp | 2 +-
   trunk/libs/spirit/example/scheme/output/sexpr.hpp | 4 ++--
   trunk/libs/spirit/example/scheme/sexpr_output_test.cpp | 34 ++++------------------------------
   trunk/libs/spirit/example/scheme/sexpr_test.cpp | 17 ++---------------
   4 files changed, 9 insertions(+), 48 deletions(-)

Added: trunk/libs/spirit/example/scheme/input/parse_sexpr.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/input/parse_sexpr.hpp 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -0,0 +1,23 @@
+// Copyright (c) 2001-2010 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)
+
+#if !defined(BOOST_SPIRIT_PARSE_SEXPR)
+#define BOOST_SPIRIT_PARSE_SEXPR
+
+#include "../utree.hpp"
+#include "../input/sexpr.hpp"
+
+namespace scheme { namespace input
+{
+ template <typename InputStream>
+ bool parse_sexpr(InputStream& is, utree& result);
+
+ template <typename InputStream>
+ bool parse_sexpr_list(InputStream& is, utree& result);
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/scheme/input/parse_sexpr_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/input/parse_sexpr_impl.hpp 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -0,0 +1,55 @@
+// Copyright (c) 2001-2010 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)
+
+#if !defined(BOOST_SPIRIT_PARSE_SEXPR_IMPL)
+#define BOOST_SPIRIT_PARSE_SEXPR_IMPL
+
+#include <iostream>
+#include <boost/spirit/include/support_istream_iterator.hpp>
+#include <boost/spirit/include/qi_parse.hpp>
+
+#include "../input/sexpr.hpp"
+#include "../input/parse_sexpr.hpp"
+
+namespace scheme { namespace input
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename InputStream>
+ bool parse_sexpr(InputStream& is, utree& result)
+ {
+ // no white space skipping in the stream!
+ is.unsetf(std::ios::skipws);
+
+ typedef boost::spirit::basic_istream_iterator<char> iterator_type;
+ iterator_type first(is);
+ iterator_type last;
+
+ scheme::input::sexpr<iterator_type> p;
+ scheme::input::white_space<iterator_type> ws;
+
+ return phrase_parse(first, last, p, ws, result);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename InputStream>
+ bool parse_sexpr_list(InputStream& is, utree& result)
+ {
+ // no white space skipping in the stream!
+ is.unsetf(std::ios::skipws);
+
+ typedef boost::spirit::basic_istream_iterator<char> iterator_type;
+ iterator_type first(is);
+ iterator_type last;
+
+ scheme::input::sexpr<iterator_type> p;
+ scheme::input::white_space<iterator_type> ws;
+
+ return phrase_parse(first, last, *p, ws, result);
+ }
+}}
+
+#endif
+
+

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-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -17,7 +17,7 @@
 #include <boost/spirit/include/phoenix_operator.hpp>
 #include <boost/regex/pending/unicode_iterator.hpp>
 
-#include "utree.hpp"
+#include "../utree.hpp"
 
 namespace scheme { namespace input
 {

Added: trunk/libs/spirit/example/scheme/output/generate_sexpr.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/output/generate_sexpr.hpp 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -0,0 +1,25 @@
+// Copyright (c) 2001-2010 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)
+
+#if !defined(SCHEME_OUTPUT_GENERATE_SEXPR_MAR_29_2010_1210PM)
+#define SCHEME_OUTPUT_GENERATE_SEXPR_MAR_29_2010_1210PM
+
+#include "../utree.hpp"
+#include "../output/sexpr.hpp"
+
+namespace scheme { namespace output
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename OutputStream>
+ bool generate_sexpr(OutputStream& os, utree const& tree);
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename OutputStream>
+ bool generate_sexpr_list(OutputStream& os, utree const& tree);
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/scheme/output/generate_sexpr_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/output/generate_sexpr_impl.hpp 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -0,0 +1,49 @@
+// Copyright (c) 2001-2010 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)
+
+#if !defined(SCHEME_OUTPUT_GENERATE_SEXPR_IMPL_MAR_29_2010_1210PM)
+#define SCHEME_OUTPUT_GENERATE_SEXPR_MAR_IMPL_29_2010_1210PM
+
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_list.hpp>
+#include <boost/spirit/include/support_ostream_iterator.hpp>
+
+#include "../output/sexpr.hpp"
+#include "../output/generate_sexpr.hpp"
+
+namespace scheme { namespace output
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename OutputStream>
+ bool generate_sexpr(OutputStream& os, utree const& tree)
+ {
+ typedef boost::spirit::ostream_iterator output_iterator_type;
+ using boost::spirit::karma::space;
+
+ output_iterator_type sink(os);
+
+ scheme::output::sexpr<output_iterator_type> g;
+ return generate_delimited(sink, g, space, tree);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename OutputStream>
+ bool generate_sexpr_list(OutputStream& os, utree const& tree)
+ {
+ typedef boost::spirit::ostream_iterator output_iterator_type;
+ using boost::spirit::karma::space;
+ using boost::spirit::karma::eol;
+
+ output_iterator_type sink(os);
+
+ scheme::output::sexpr<output_iterator_type> g;
+ return generate_delimited(sink, g % eol, space, tree);
+ }
+}}
+
+#endif
+
+

Modified: trunk/libs/spirit/example/scheme/output/sexpr.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/output/sexpr.hpp (original)
+++ trunk/libs/spirit/example/scheme/output/sexpr.hpp 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -12,8 +12,8 @@
 #include <boost/mpl/bool.hpp>
 #include <boost/spirit/include/karma.hpp>
 
-#include "utree.hpp"
-#include "detail/utree_detail3.hpp"
+#include "../utree.hpp"
+#include "../detail/utree_detail3.hpp"
 
 ///////////////////////////////////////////////////////////////////////////////
 namespace boost { namespace spirit { namespace traits

Modified: trunk/libs/spirit/example/scheme/sexpr_output_test.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/sexpr_output_test.cpp (original)
+++ trunk/libs/spirit/example/scheme/sexpr_output_test.cpp 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -11,8 +11,8 @@
 #include <fstream>
 #include <iterator>
 
-#include "input/sexpr.hpp"
-#include "output/sexpr.hpp"
+#include "input/parse_sexpr_impl.hpp"
+#include "output/generate_sexpr_impl.hpp"
 
 namespace client
 {
@@ -42,21 +42,7 @@
             }
         }
 
- std::string source_code; // We will read the contents here.
- in.unsetf(std::ios::skipws); // No white space skipping!
- std::copy(
- std::istream_iterator<char>(in),
- std::istream_iterator<char>(),
- std::back_inserter(source_code));
-
- typedef std::string::const_iterator iterator_type;
- iterator_type first(source_code.begin());
- iterator_type last(source_code.end());
-
- scheme::input::sexpr<iterator_type> p;
- scheme::input::white_space<iterator_type> ws;
-
- return phrase_parse(first, last, p, ws, result);
+ return scheme::input::parse_sexpr(in, result);
     }
 
     bool generate_sexpr_to_file(scheme::utree const& tree, char const* filename)
@@ -70,19 +56,7 @@
             exit(-1);
         }
 
- typedef std::back_insert_iterator<std::string> output_iterator_type;
- using boost::spirit::karma::space;
-
- std::string output;
- output_iterator_type sink(output);
- scheme::output::sexpr<output_iterator_type> g;
- if (!generate_delimited(sink, g, space, tree))
- {
- return false;
- }
-
- out << output;
- return true;
+ return scheme::output::generate_sexpr(out, tree);
     }
 }
 

Modified: trunk/libs/spirit/example/scheme/sexpr_test.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/sexpr_test.cpp (original)
+++ trunk/libs/spirit/example/scheme/sexpr_test.cpp 2010-03-29 21:58:23 EDT (Mon, 29 Mar 2010)
@@ -7,6 +7,7 @@
 #include <boost/config/warning_disable.hpp>
 
 #include "input/sexpr.hpp"
+#include "input/parse_sexpr_impl.hpp"
 #include "simple_print.hpp"
 #include <iostream>
 #include <fstream>
@@ -53,22 +54,8 @@
         }
     }
 
- std::string source_code; // We will read the contents here.
- in.unsetf(std::ios::skipws); // No white space skipping!
- std::copy(
- std::istream_iterator<char>(in),
- std::istream_iterator<char>(),
- std::back_inserter(source_code));
-
- typedef std::string::const_iterator iterator_type;
- iterator_type first(source_code.begin());
- iterator_type last(source_code.end());
-
- scheme::input::sexpr<iterator_type> p;
- scheme::input::white_space<iterator_type> ws;
-
     scheme::utree result;
- if (phrase_parse(first, last, p, ws, result))
+ if (scheme::input::parse_sexpr(in, result))
     {
         std::cout << "success: ";
         println(std::cout, result);


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