|
Boost-Commit : |
From: hartmut.kaiser_at_[hidden]
Date: 2008-07-13 12:49:10
Author: hkaiser
Date: 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
New Revision: 47385
URL: http://svn.boost.org/trac/boost/changeset/47385
Log:
Spirit.Karma: Changed grammars to conform to new Qi grammars
Added:
trunk/boost/spirit/home/karma/nonterminal/grammar_fwd.hpp (contents, props changed)
Text files modified:
trunk/boost/spirit/home/karma/nonterminal/grammar.hpp | 94 +++++++++++----------------------------
trunk/boost/spirit/home/karma/nonterminal/rule.hpp | 6 -
trunk/boost/spirit/home/qi/nonterminal/grammar_fwd.hpp | 2
trunk/libs/spirit/example/karma/calc2_ast_dump.cpp | 7 +-
trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp | 7 +-
trunk/libs/spirit/example/karma/calc2_ast_vm.cpp | 9 +--
trunk/libs/spirit/example/karma/mini_xml_karma.cpp | 7 +-
trunk/libs/spirit/test/karma/grammar.cpp | 7 +-
trunk/libs/spirit/test/karma/grammar_fail.cpp | 2
9 files changed, 48 insertions(+), 93 deletions(-)
Modified: trunk/boost/spirit/home/karma/nonterminal/grammar.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/nonterminal/grammar.hpp (original)
+++ trunk/boost/spirit/home/karma/nonterminal/grammar.hpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -8,7 +8,8 @@
#define BOOST_SPIRIT_KARMA_GRAMMAR_MAR_05_2007_0542PM
#include <boost/spirit/home/support/unused.hpp>
-#include <boost/spirit/home/support/nonterminal/nonterminal.hpp>
+#include <boost/spirit/home/karma/nonterminal/nonterminal.hpp>
+#include <boost/spirit/home/karma/nonterminal/grammar_fwd.hpp>
#include <boost/spirit/home/karma/domain.hpp>
#include <boost/spirit/home/karma/nonterminal/rule.hpp>
#include <boost/spirit/home/karma/nonterminal/nonterminal_director.hpp>
@@ -17,100 +18,61 @@
namespace boost { namespace spirit { namespace karma
{
- template <typename Definition>
+ template <typename Iterator, typename T0 , typename T1 , typename T2>
struct grammar
: nonterminal<
- grammar<Definition>,
- typename Definition::sig_type,
- typename Definition::locals_type
- >
+ grammar<Iterator, T0, T1, T2>,
+ typename karma::rule<Iterator, T0, T1, T2>::sig_type,
+ typename karma::rule<Iterator, T0, T1, T2>::locals_type
+ >, noncopyable
{
- typedef typename Definition::sig_type sig_type;
- typedef typename Definition::locals_type locals_type;
- typedef typename Definition::delimiter_type delimiter_type;
- typedef typename Definition::start_type start_type;
- typedef typename Definition::iterator_type iterator_type;
+ typedef Iterator iterator_type;
+ typedef karma::rule<Iterator, T0, T1, T2> start_type;
+ typedef typename start_type::sig_type sig_type;
+ typedef typename start_type::locals_type locals_type;
+ typedef typename start_type::delimiter_type delimiter_type;
+ typedef grammar<Iterator, T0, T1, T2> base_type;
+
+ grammar(start_type const& start, std::string const& name_ = std::string())
+ : start_(start), name_(name_)
+ {}
- explicit grammar(Definition const& definition_)
- : definition(definition_), start(definition_.start)
+ std::string name() const
{
+ return name_;
}
- template <typename Definition_, typename Start>
- grammar(Definition_ const& definition_, Start const& start_)
- : definition(definition_), start(start_)
+ void name(std::string const& name__)
{
+ name_ = name__;
}
+ start_type const& start_;
+ std::string name_;
+
private:
template <typename OutputIterator, typename Context, typename Delimiter>
bool generate(OutputIterator& sink, Context& context,
Delimiter const& delim) const
{
- return start.generate(sink, context, delim);
+ return start_.generate(sink, context, delim);
}
std::string what() const
{
- if (definition.name().empty())
+ if (name().empty())
{
- return start.what();
+ return start_.what();
}
else
{
- return definition.name();
+ return name();
}
}
friend struct nonterminal_director;
- Definition const& definition;
- start_type const& start;
};
- template <typename OutputIterator, typename T0 = unused_type,
- typename T1 = unused_type, typename T2 = unused_type>
- struct grammar_def : noncopyable
- {
- typedef karma::rule<OutputIterator, T0, T1, T2> start_type;
- typedef typename start_type::iterator_type iterator_type;
- typedef typename start_type::sig_type sig_type;
- typedef typename start_type::locals_type locals_type;
- typedef typename start_type::delimiter_type delimiter_type;
-
- grammar_def(std::string const& name_ = std::string())
- : name_(name_) {}
-
- std::string name() const
- {
- return name_;
- }
-
- void name(std::string const& name__)
- {
- name_ = name__;
- }
-
- std::string name_;
- };
-
- ///////////////////////////////////////////////////////////////////////////
- // Generator functions helping to construct a proper grammar object
- // instance
- ///////////////////////////////////////////////////////////////////////////
- template <typename Definition>
- inline grammar<Definition>
- make_generator(Definition const& def)
- {
- return grammar<Definition>(def);
- }
-
- template <typename Definition, typename Start>
- inline grammar<Definition>
- make_generator(Definition const& def, Start const& start)
- {
- return grammar<Definition>(def, start);
- }
-
}}}
#endif
Added: trunk/boost/spirit/home/karma/nonterminal/grammar_fwd.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/spirit/home/karma/nonterminal/grammar_fwd.hpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -0,0 +1,26 @@
+/*=============================================================================
+ Copyright (c) 2001-2008 Joel de Guzman
+ Copyright (c) 2001-2008 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_KARMA_GRAMMAR_FWD_JULY_13_2008_0924AM)
+#define BOOST_SPIRIT_KARMA_GRAMMAR_FWD_JULY_13_2008_0924AM
+
+#include <boost/spirit/home/support/unused.hpp>
+
+namespace boost { namespace spirit { namespace karma
+{
+ // forward declaration
+ template <
+ typename Iterator,
+ typename T0 = unused_type,
+ typename T1 = unused_type,
+ typename T2 = unused_type
+ >
+ struct grammar;
+
+}}}
+
+#endif
Modified: trunk/boost/spirit/home/karma/nonterminal/rule.hpp
==============================================================================
--- trunk/boost/spirit/home/karma/nonterminal/rule.hpp (original)
+++ trunk/boost/spirit/home/karma/nonterminal/rule.hpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -13,6 +13,7 @@
#include <boost/spirit/home/support/unused.hpp>
#include <boost/spirit/home/karma/nonterminal/nonterminal.hpp>
+#include <boost/spirit/home/karma/nonterminal/grammar_fwd.hpp>
#include <boost/spirit/home/karma/nonterminal/detail/rule.hpp>
#include <boost/spirit/home/karma/domain.hpp>
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
@@ -26,9 +27,6 @@
namespace boost { namespace spirit { namespace karma
{
- template <typename Definition>
- struct grammar; // forward declaration
-
template <typename OutputIterator, typename T0 = unused_type,
typename T1 = unused_type, typename T2 = unused_type>
struct rule
@@ -140,7 +138,7 @@
private:
- template <typename Definition>
+ template <typename Iterator_, typename T0_, typename T1_, typename T2_>
friend struct grammar;
template <typename Expr, typename Auto>
Modified: trunk/boost/spirit/home/qi/nonterminal/grammar_fwd.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/nonterminal/grammar_fwd.hpp (original)
+++ trunk/boost/spirit/home/qi/nonterminal/grammar_fwd.hpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -7,6 +7,8 @@
#if !defined(BOOST_SPIRIT_GRAMMAR_FWD_JULY_11_2008_1034AM)
#define BOOST_SPIRIT_GRAMMAR_FWD_JULY_11_2008_1034AM
+#include <boost/spirit/home/support/unused.hpp>
+
namespace boost { namespace spirit { namespace qi
{
// forward declaration
Modified: trunk/libs/spirit/example/karma/calc2_ast_dump.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_dump.cpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast_dump.cpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -66,9 +66,9 @@
///////////////////////////////////////////////////////////////////////////////
template <typename OuputIterator>
struct dump_ast
- : karma::grammar_def<OuputIterator, expression_ast(), space_type>
+ : karma::grammar<OuputIterator, expression_ast(), space_type>
{
- dump_ast()
+ dump_ast() : dump_ast::base_type(ast_node)
{
ast_node %=
int_ [_1 = _int(_val)]
@@ -117,8 +117,7 @@
typedef std::back_insert_iterator<std::string> output_iterator_type;
typedef dump_ast<output_iterator_type> dump_ast;
- dump_ast dump_ast_def;
- karma::grammar<dump_ast> ast_grammar(dump_ast_def, dump_ast_def.ast_node);
+ dump_ast ast_grammar;
std::string str;
while (std::getline(std::cin, str))
Modified: trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -67,9 +67,9 @@
///////////////////////////////////////////////////////////////////////////////
template <typename OuputIterator>
struct ast_rpn
- : karma::grammar_def<OuputIterator, expression_ast(), space_type>
+ : karma::grammar<OuputIterator, expression_ast(), space_type>
{
- ast_rpn()
+ ast_rpn() : ast_rpn::base_type(ast_node)
{
ast_node %=
int_ [_1 = _int(_val)]
@@ -120,8 +120,7 @@
typedef std::back_insert_iterator<std::string> output_iterator_type;
typedef ast_rpn<output_iterator_type> ast_rpn;
- ast_rpn ast_rpn_def;
- karma::grammar<ast_rpn> ast_grammar(ast_rpn_def, ast_rpn_def.ast_node);
+ ast_rpn ast_grammar;
std::string str;
while (std::getline(std::cin, str))
Modified: trunk/libs/spirit/example/karma/calc2_ast_vm.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_vm.cpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast_vm.cpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -133,9 +133,9 @@
///////////////////////////////////////////////////////////////////////////////
template <typename OuputIterator, typename Delimiter>
struct generate_byte_code
- : karma::grammar_def<OuputIterator, expression_ast(), Delimiter>
+ : karma::grammar<OuputIterator, expression_ast(), Delimiter>
{
- generate_byte_code()
+ generate_byte_code() : generate_byte_code::base_type(ast_node)
{
ast_node %=
(dword(op_int) << dword) [_1 = _int(_val)]
@@ -172,11 +172,8 @@
// Our generator grammar definitions
typedef char* output_iterator_type;
typedef generate_byte_code<output_iterator_type, Delimiter> generate_byte_code;
-
- generate_byte_code generate_byte_code_def;
- karma::grammar<generate_byte_code> gen_vm(
- generate_byte_code_def, generate_byte_code_def.ast_node);
+ generate_byte_code gen_vm;
return karma::generate_delimited((*code.begin()).bytes, gen_vm, ast, d);
}
Modified: trunk/libs/spirit/example/karma/mini_xml_karma.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/mini_xml_karma.cpp (original)
+++ trunk/libs/spirit/example/karma/mini_xml_karma.cpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -128,9 +128,9 @@
///////////////////////////////////////////////////////////////////////////////
template <typename OutputIterator>
struct mini_xml_generator
- : karma::grammar_def<OutputIterator, mini_xml()>
+ : karma::grammar<OutputIterator, mini_xml()>
{
- mini_xml_generator()
+ mini_xml_generator() : mini_xml_generator::base_type(xml)
{
node %=
lit[_1 = _string(_r0)]
@@ -196,8 +196,7 @@
typedef std::back_insert_iterator<std::string> outiter_type;
typedef mini_xml_generator<outiter_type> mini_xml_generator;
- mini_xml_generator gen; // Our grammar definition
- karma::grammar<mini_xml_generator> xmlout(gen, gen.xml); // Our grammar
+ mini_xml_generator xmlout; // Our grammar definition
std::string generated;
bool r = karma::generate(std::back_inserter(generated), xmlout, ast);
Modified: trunk/libs/spirit/test/karma/grammar.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/grammar.cpp (original)
+++ trunk/libs/spirit/test/karma/grammar.cpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -29,9 +29,9 @@
typedef spirit_test::output_iterator<char>::type outiter_type;
-struct num_list : grammar_def<outiter_type, space_type>
+struct num_list : grammar<outiter_type, space_type>
{
- num_list()
+ num_list() : num_list::base_type(start)
{
using boost::spirit::int_;
num1 = int_(123);
@@ -47,8 +47,7 @@
main()
{
{ // simple grammar test
- num_list def;
- grammar<num_list> nlist(def);
+ num_list nlist;
BOOST_TEST(test_delimited("123 , 456 , 789 ", nlist, space));
}
Modified: trunk/libs/spirit/test/karma/grammar_fail.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/grammar_fail.cpp (original)
+++ trunk/libs/spirit/test/karma/grammar_fail.cpp 2008-07-13 12:49:09 EDT (Sun, 13 Jul 2008)
@@ -19,7 +19,7 @@
using namespace boost::spirit::karma;
using namespace boost::spirit::ascii;
-struct num_list : grammar_def<char const*, rule<char const*> >
+struct num_list : grammar<char const*, rule<char const*> >
{
num_list()
{
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