Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r61302 - in trunk/libs/spirit/example/scheme: qi test test/generate_qiexpr test/parse_qiexpr
From: hartmut.kaiser_at_[hidden]
Date: 2010-04-15 18:58:16


Author: hkaiser
Date: 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
New Revision: 61302
URL: http://svn.boost.org/trac/boost/changeset/61302

Log:
Spirit: beginnings of Qi generator
Added:
   trunk/libs/spirit/example/scheme/qi/component_names.hpp (contents, props changed)
   trunk/libs/spirit/example/scheme/qi/generate_qiexpr.hpp (contents, props changed)
   trunk/libs/spirit/example/scheme/qi/generate_qiexpr_impl.hpp (contents, props changed)
   trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp (contents, props changed)
   trunk/libs/spirit/example/scheme/test/generate_qiexpr/
   trunk/libs/spirit/example/scheme/test/generate_qiexpr/generate_qi_test.cpp (contents, props changed)
   trunk/libs/spirit/example/scheme/test/generate_qiexpr/generate_qiexpr.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp | 60 ---------------------------------------
   trunk/libs/spirit/example/scheme/test/Jamfile | 14 +++++++--
   trunk/libs/spirit/example/scheme/test/parse_qiexpr/parse_qiexpr.cpp | 4 +-
   3 files changed, 14 insertions(+), 64 deletions(-)

Added: trunk/libs/spirit/example/scheme/qi/component_names.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/qi/component_names.hpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -0,0 +1,72 @@
+// 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_QI_COMPONENT_NAMES)
+#define BOOST_SPIRIT_QI_COMPONENT_NAMES
+
+///////////////////////////////////////////////////////////////////////////////
+namespace scheme { namespace qi
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // a list of names for all supported parser primitives taking no parameters
+ static char const* const primitives0[] =
+ {
+ // character parsers
+ "char_"
+ , "alnum", "alpha", "blank", "cntrl", "digit", "graph", "print", "punct"
+ , "space", "xdigit"
+ , "lower", "upper"
+
+ // numerics
+ , "long_long", "long_", "int_", "short_"
+ , "ulong_long", "ulong_", "uint_", "ushort_"
+ , "bin", "oct", "hex"
+ , "bool_", "true_", "false_"
+ , "long_double", "double_", "float_"
+
+ // binary
+ , "qword", "dword", "word", "byte_"
+ , "little_qword", "little_dword", "little_word"
+ , "big_qword", "big_dword", "big_word"
+
+ // auxiliary
+ , "eol", "eoi", "eps"
+ , 0
+ };
+
+ // a list of names for all supported parser primitives taking 1 parameter
+ static char const* const primitives1[] =
+ {
+ // character parsers
+ "char_", "lit", "string"
+ , 0
+ };
+
+ // a list of names for all supported parser primitives taking 2 parameter
+ static char const* const primitives2[] =
+ {
+ "char_"
+ , 0
+ };
+
+ // a list of names for all supported parser directives taking 0 parameter
+ static char const* const directives0[] =
+ {
+ // manage skip parser
+ "lexeme", "skip", "no_skip"
+
+ // case management
+ , "no_case"
+
+ // auxiliary
+ , "omit", "raw"
+
+ // encoding
+ , "ascii", "standard", "standard_wide", "iso8859_1", "unicode"
+ , 0
+ };
+}}
+
+#endif

Added: trunk/libs/spirit/example/scheme/qi/generate_qiexpr.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/qi/generate_qiexpr.hpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -0,0 +1,19 @@
+// 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_GENERATE_QIEXPR)
+#define BOOST_SPIRIT_GENERATE_QIEXPR
+
+#include <utree/utree.hpp>
+
+namespace scheme { namespace output
+{
+ template <typename String>
+ bool generate_qiexpr(utree& result, String& str);
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/scheme/qi/generate_qiexpr_impl.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/qi/generate_qiexpr_impl.hpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -0,0 +1,32 @@
+// 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_GENERATE_QIEXPR_IMPL)
+#define BOOST_SPIRIT_GENERATE_QIEXPR_IMPL
+
+#include <iostream>
+#include <boost/spirit/include/karma_generate.hpp>
+
+#include <qi/qiexpr_generator.hpp>
+#include <qi/generate_qiexpr.hpp>
+
+namespace scheme { namespace output
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename String>
+ bool generate_qiexpr(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, space, u);
+ }
+}}
+
+#endif
+
+

Added: trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/qi/qiexpr_generator.hpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -0,0 +1,89 @@
+// 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_QIEXPR_GENERATOR)
+#define BOOST_SPIRIT_QIEXPR_GENERATOR
+
+#include <string>
+
+#include <boost/cstdint.hpp>
+#include <boost/spirit/include/karma.hpp>
+
+#include <utree/utree.hpp>
+#include <utree/detail/utree_detail3.hpp>
+#include <utree/operators.hpp>
+#include <qi/component_names.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+namespace boost { namespace spirit { namespace traits
+{
+ template <>
+ struct symbols_lookup<scheme::utree, std::string>
+ {
+ typedef std::string type;
+ static type call(scheme::utree const& t)
+ {
+ BOOST_ASSERT(t.which() == scheme::utree_type::list_type);
+ return boost::get<scheme::utf8_symbol>(t.front());
+ }
+ };
+
+ template <>
+ struct symbols_value<scheme::utree, std::string>
+ {
+ typedef unused_type type;
+ static type call(scheme::utree const& t)
+ {
+ return unused;
+ }
+ };
+}}}
+
+///////////////////////////////////////////////////////////////////////////////
+namespace scheme { namespace qi
+{
+ using boost::spirit::karma::grammar;
+ using boost::spirit::karma::rule;
+ using boost::spirit::karma::space_type;
+ using boost::spirit::karma::symbols;
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename OutputIterator>
+ struct qiexpr_generator : grammar<OutputIterator, space_type, utree()>
+ {
+ qiexpr_generator() : qiexpr_generator::base_type(start)
+ {
+ using boost::spirit::karma::eps;
+
+ start = term.alias();
+
+ term =
+// primitives2 << '(' << string << ',' << string << ')'
+// | primitives1 << '(' << string << ')'
+ /*|*/ primitive0
+ ;
+
+ // fill the symbol tables with all known primitive parser names
+ for (char const* const* p = primitives0; *p; ++p)
+ primitive0.add(*p);
+
+ for (char const* const* p = primitives1; *p; ++p)
+ primitive1.add(*p);
+
+ for (char const* const* p = primitives2; *p; ++p)
+ primitive2.add(*p);
+ }
+
+ typedef rule<OutputIterator, space_type, utree()> rule_type;
+
+ rule_type start, term;
+ symbols<std::string> primitive0, primitive1, primitive2;
+ };
+}}
+
+#endif
+
+
+

Modified: trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp
==============================================================================
--- trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp (original)
+++ trunk/libs/spirit/example/scheme/qi/qiexpr_parser.hpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -20,6 +20,7 @@
 #include <utree/detail/utree_detail3.hpp>
 #include <utree/operators.hpp>
 #include <input/string.hpp>
+#include <qi/component_names.hpp>
 
 namespace boost { namespace spirit { namespace traits
 {
@@ -136,65 +137,6 @@
     }
 
     ///////////////////////////////////////////////////////////////////////////
- // a list of names for all supported parser primitives taking no parameters
- static char const* const primitives0[] =
- {
- // character parsers
- "char_"
- , "alnum", "alpha", "blank", "cntrl", "digit", "graph", "print", "punct"
- , "space", "xdigit"
- , "lower", "upper"
-
- // numerics
- , "long_long", "long_", "int_", "short_"
- , "ulong_long", "ulong_", "uint_", "ushort_"
- , "bin", "oct", "hex"
- , "bool_", "true_", "false_"
- , "long_double", "double_", "float_"
-
- // binary
- , "qword", "dword", "word", "byte_"
- , "little_qword", "little_dword", "little_word"
- , "big_qword", "big_dword", "big_word"
-
- // auxiliary
- , "eol", "eoi", "eps"
- , 0
- };
-
- // a list of names for all supported parser primitives taking 1 parameter
- static char const* const primitives1[] =
- {
- // character parsers
- "char_", "lit", "string"
- , 0
- };
-
- // a list of names for all supported parser primitives taking 2 parameter
- static char const* const primitives2[] =
- {
- "char_"
- , 0
- };
-
- // a list of names for all supported parser directives taking 0 parameter
- static char const* const directives0[] =
- {
- // manage skip parser
- "lexeme", "skip", "no_skip"
-
- // case management
- , "no_case"
-
- // auxiliary
- , "omit", "raw"
-
- // encoding
- , "ascii", "standard", "standard_wide", "iso8859_1", "unicode"
- , 0
- };
-
- ///////////////////////////////////////////////////////////////////////////
     template <typename Iterator>
     struct qiexpr_parser
       : grammar<Iterator, qiexpr_white_space<Iterator>, utree()>

Modified: trunk/libs/spirit/example/scheme/test/Jamfile
==============================================================================
--- trunk/libs/spirit/example/scheme/test/Jamfile (original)
+++ trunk/libs/spirit/example/scheme/test/Jamfile 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -27,9 +27,17 @@
 exe sexpr_input_test : sexpr/sexpr_input_test.cpp ;
 exe sexpr_output_test : sexpr/sexpr_output_test.cpp ;
 
-exe generate_sexpr_to_ostream : parse_qiexpr/generate_sexpr_to_ostream.cpp ;
-exe parse_qi_test : parse_qiexpr/parse_qi_test.cpp ;
-exe parse_qiexpr : parse_qiexpr/parse_qiexpr.cpp ;
+exe parse_qi_test
+ : parse_qiexpr/generate_sexpr_to_ostream.cpp
+ parse_qiexpr/parse_qi_test.cpp
+ parse_qiexpr/parse_qiexpr.cpp
+ ;
+
+exe generate_qi_test
+ : parse_qiexpr/parse_qiexpr.cpp
+ generate_qiexpr/generate_qi_test.cpp
+ generate_qiexpr/generate_qiexpr.cpp
+ ;
 
 exe scheme_test1 : scheme/scheme_test1.cpp ;
 exe scheme_test2 : scheme/scheme_test2.cpp ;

Added: trunk/libs/spirit/example/scheme/test/generate_qiexpr/generate_qi_test.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/test/generate_qiexpr/generate_qi_test.cpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 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)
+
+#include <boost/config/warning_disable.hpp>
+
+#define BOOST_SPIRIT_UNICODE
+
+#include <iostream>
+#include <fstream>
+#include <iterator>
+
+#include <utree/utree.hpp>
+#include <qi/parse_qiexpr.hpp>
+#include <qi/generate_qiexpr.hpp>
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int main(int argc, char **argv)
+{
+ std::string str;
+ while (std::getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+ str += '\n';
+
+ scheme::utree result;
+ if (scheme::input::parse_qiexpr(str, result))
+ {
+ std::string str;
+ if (scheme::output::generate_qiexpr(result, str))
+ {
+ std::cout << str << std::endl;
+ }
+ else
+ {
+ std::cout << "generate error" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "parse error" << std::endl;
+ }
+ }
+ return 0;
+}

Added: trunk/libs/spirit/example/scheme/test/generate_qiexpr/generate_qiexpr.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/scheme/test/generate_qiexpr/generate_qiexpr.cpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -0,0 +1,14 @@
+// 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)
+
+#include "../../qi/generate_qiexpr.hpp"
+#include "../../qi/generate_qiexpr_impl.hpp"
+
+// explicit template instantiation for the function generate_qiexpr
+namespace scheme { namespace output
+{
+ template bool generate_qiexpr(utree& u, std::string& str);
+}}
+

Modified: trunk/libs/spirit/example/scheme/test/parse_qiexpr/parse_qiexpr.cpp
==============================================================================
--- trunk/libs/spirit/example/scheme/test/parse_qiexpr/parse_qiexpr.cpp (original)
+++ trunk/libs/spirit/example/scheme/test/parse_qiexpr/parse_qiexpr.cpp 2010-04-15 18:58:15 EDT (Thu, 15 Apr 2010)
@@ -3,12 +3,12 @@
 // 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)
 
-#include <fstream>
+#include <string>
 
 #include <qi/parse_qiexpr.hpp>
 #include <qi/parse_qiexpr_impl.hpp>
 
-// explicit template instantiation for the function parse_sexpr
+// explicit template instantiation for the function parse_qiexpr
 namespace scheme { namespace input
 {
     template bool parse_qiexpr(std::string const&, utree& 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