|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52605 - in trunk/libs/spirit: . example/karma example/lex example/lex/static_lexer example/qi example/qi/calc6 example/qi/calc7 example/qi/mini_c test test/karma test/lex test/qi test/support test/support/detail
From: hartmut.kaiser_at_[hidden]
Date: 2009-04-26 10:47:02
Author: hkaiser
Date: 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
New Revision: 52605
URL: http://svn.boost.org/trac/boost/changeset/52605
Log:
Merging Spirit V2.1
Added:
trunk/libs/spirit/example/karma/karma_problem.cpp (contents, props changed)
trunk/libs/spirit/example/qi/calc4_debug.cpp (contents, props changed)
trunk/libs/spirit/test/karma/and_attribute.cpp (contents, props changed)
trunk/libs/spirit/test/karma/format_manip_attr.cpp (contents, props changed)
trunk/libs/spirit/test/karma/generate_attr.cpp (contents, props changed)
trunk/libs/spirit/test/karma/maxwidth.cpp (contents, props changed)
trunk/libs/spirit/test/karma/plus.cpp (contents, props changed)
trunk/libs/spirit/test/karma/stream.cpp (contents, props changed)
trunk/libs/spirit/test/karma/test_attr.hpp (contents, props changed)
trunk/libs/spirit/test/karma/test_manip_attr.hpp (contents, props changed)
trunk/libs/spirit/test/karma/tricky_alignment.cpp (contents, props changed)
trunk/libs/spirit/test/qi/match_manip_attr.cpp (contents, props changed)
trunk/libs/spirit/test/qi/omit.cpp (contents, props changed)
trunk/libs/spirit/test/qi/parse_attr.cpp (contents, props changed)
trunk/libs/spirit/test/qi/repeat.cpp (contents, props changed)
trunk/libs/spirit/test/qi/skip.cpp (contents, props changed)
trunk/libs/spirit/test/qi/terminal_ex.cpp (contents, props changed)
trunk/libs/spirit/test/qi/test_attr.hpp (contents, props changed)
trunk/libs/spirit/test/qi/test_manip_attr.hpp (contents, props changed)
Removed:
trunk/libs/spirit/example/karma/calc2_ast_dump.cpp
trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp
trunk/libs/spirit/example/karma/functor_facilities.cpp
trunk/libs/spirit/example/qi/calc3_lexer.cpp
trunk/libs/spirit/test/karma/none.cpp
trunk/libs/spirit/test/qi/none.cpp
trunk/libs/spirit/test/support/detail/
trunk/libs/spirit/test/support/hold_any.cpp
trunk/libs/spirit/test/support/multi_pass.cpp
trunk/libs/spirit/test/support/multi_pass_compile.cpp
Text files modified:
trunk/libs/spirit/CMakeLists.txt | 2
trunk/libs/spirit/example/karma/Jamfile | 11
trunk/libs/spirit/example/karma/actions.cpp | 28 ++-
trunk/libs/spirit/example/karma/basic_facilities.cpp | 100 +++++++----
trunk/libs/spirit/example/karma/calc2_ast.hpp | 4
trunk/libs/spirit/example/karma/calc2_ast_vm.cpp | 30 ++-
trunk/libs/spirit/example/karma/mini_xml_karma.cpp | 22 +-
trunk/libs/spirit/example/karma/quick_start1.cpp | 16 +-
trunk/libs/spirit/example/lex/Jamfile | 29 +-
trunk/libs/spirit/example/lex/example1.cpp | 49 +++---
trunk/libs/spirit/example/lex/example2.cpp | 49 +++---
trunk/libs/spirit/example/lex/example3.cpp | 34 +--
trunk/libs/spirit/example/lex/example4.cpp | 53 +++---
trunk/libs/spirit/example/lex/example5.cpp | 95 +++++------
trunk/libs/spirit/example/lex/example6.cpp | 53 +++---
trunk/libs/spirit/example/lex/print_numbers.cpp | 40 ++--
trunk/libs/spirit/example/lex/static_lexer/Jamfile | 3
trunk/libs/spirit/example/lex/static_lexer/word_count_generate.cpp | 8
trunk/libs/spirit/example/lex/static_lexer/word_count_static.cpp | 40 ++--
trunk/libs/spirit/example/lex/static_lexer/word_count_static.hpp | 84 +++++-----
trunk/libs/spirit/example/lex/static_lexer/word_count_tokens.hpp | 11
trunk/libs/spirit/example/lex/strip_comments.cpp | 35 ++--
trunk/libs/spirit/example/lex/strip_comments.input | 82 ++++++----
trunk/libs/spirit/example/lex/strip_comments_lexer.cpp | 82 ++++++++--
trunk/libs/spirit/example/lex/word_count.cpp | 40 ++--
trunk/libs/spirit/example/lex/word_count_functor.cpp | 18 +-
trunk/libs/spirit/example/lex/word_count_lexer.cpp | 29 +--
trunk/libs/spirit/example/qi/Jamfile | 6
trunk/libs/spirit/example/qi/actions.cpp | 58 ++++---
trunk/libs/spirit/example/qi/calc1.cpp | 75 +++++----
trunk/libs/spirit/example/qi/calc2.cpp | 97 ++++++-----
trunk/libs/spirit/example/qi/calc2_ast.cpp | 296 +++++++++++++++++++++---------------
trunk/libs/spirit/example/qi/calc3.cpp | 80 +++++----
trunk/libs/spirit/example/qi/calc4.cpp | 121 ++++++++-------
trunk/libs/spirit/example/qi/calc5.cpp | 305 +++++++++++++++++++------------------
trunk/libs/spirit/example/qi/calc6/calc6.cpp | 4
trunk/libs/spirit/example/qi/calc6/calc6.hpp | 40 ++--
trunk/libs/spirit/example/qi/calc6/calc6a.cpp | 2
trunk/libs/spirit/example/qi/calc6/calc6b.cpp | 4
trunk/libs/spirit/example/qi/calc6/calc6b.hpp | 11 +
trunk/libs/spirit/example/qi/calc6/calc6c.cpp | 2
trunk/libs/spirit/example/qi/calc6/calc6c.hpp | 15 +
trunk/libs/spirit/example/qi/calc7/calc7.cpp | 4
trunk/libs/spirit/example/qi/calc7/calc7.hpp | 44 ++--
trunk/libs/spirit/example/qi/calc7/calc7a.cpp | 2
trunk/libs/spirit/example/qi/calc7/calc7b.cpp | 4
trunk/libs/spirit/example/qi/calc7/calc7b.hpp | 12 +
trunk/libs/spirit/example/qi/calc7/calc7c.cpp | 2
trunk/libs/spirit/example/qi/calc7/calc7c.hpp | 13 +
trunk/libs/spirit/example/qi/complex_number.cpp | 59 +++---
trunk/libs/spirit/example/qi/employee.cpp | 104 +++++++-----
trunk/libs/spirit/example/qi/mini_c/mini_c.cpp | 4
trunk/libs/spirit/example/qi/mini_c/mini_c.hpp | 13
trunk/libs/spirit/example/qi/mini_c/mini_ca.cpp | 2
trunk/libs/spirit/example/qi/mini_c/mini_cb.cpp | 2
trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp | 6
trunk/libs/spirit/example/qi/mini_c/mini_cc.cpp | 2
trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp | 6
trunk/libs/spirit/example/qi/mini_c/mini_cd.cpp | 2
trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp | 8
trunk/libs/spirit/example/qi/mini_xml1.cpp | 276 ++++++++++++++++++----------------
trunk/libs/spirit/example/qi/mini_xml2.cpp | 273 +++++++++++++++++----------------
trunk/libs/spirit/example/qi/mini_xml3.cpp | 316 ++++++++++++++++++++-------------------
trunk/libs/spirit/example/qi/num_list1.cpp | 52 +++---
trunk/libs/spirit/example/qi/num_list2.cpp | 68 ++++---
trunk/libs/spirit/example/qi/num_list3.cpp | 66 ++++---
trunk/libs/spirit/example/qi/num_list4.cpp | 61 ++++---
trunk/libs/spirit/example/qi/roman.cpp | 200 +++++++++++++------------
trunk/libs/spirit/example/qi/sum.cpp | 68 ++++---
trunk/libs/spirit/test/CMakeLists.txt | 94 +++++++----
trunk/libs/spirit/test/Jamfile | 52 +++--
trunk/libs/spirit/test/karma/actions.cpp | 75 +++++++-
trunk/libs/spirit/test/karma/alternative.cpp | 138 ++++++++++-------
trunk/libs/spirit/test/karma/binary.cpp | 22 +-
trunk/libs/spirit/test/karma/case_handling.cpp | 178 ++++++++++++++++------
trunk/libs/spirit/test/karma/center_alignment.cpp | 15 +
trunk/libs/spirit/test/karma/char.cpp | 175 ++++++++++++---------
trunk/libs/spirit/test/karma/delimiter.cpp | 16 +
trunk/libs/spirit/test/karma/eps.cpp | 31 +++
trunk/libs/spirit/test/karma/format_manip.cpp | 54 ++---
trunk/libs/spirit/test/karma/grammar.cpp | 4
trunk/libs/spirit/test/karma/grammar_fail.cpp | 23 +-
trunk/libs/spirit/test/karma/int_numerics.cpp | 85 ++++++----
trunk/libs/spirit/test/karma/kleene.cpp | 75 ++------
trunk/libs/spirit/test/karma/lazy.cpp | 30 +-
trunk/libs/spirit/test/karma/left_alignment.cpp | 16 +-
trunk/libs/spirit/test/karma/list.cpp | 6
trunk/libs/spirit/test/karma/lit.cpp | 93 +++++++----
trunk/libs/spirit/test/karma/optional.cpp | 12 -
trunk/libs/spirit/test/karma/pattern.cpp | 133 ++++++++++------
trunk/libs/spirit/test/karma/pattern2.cpp | 100 +++++++++++
trunk/libs/spirit/test/karma/real_numerics.cpp | 188 +++++++++++++++--------
trunk/libs/spirit/test/karma/right_alignment.cpp | 12
trunk/libs/spirit/test/karma/rule_fail.cpp | 19 +-
trunk/libs/spirit/test/karma/sequence.cpp | 46 +++--
trunk/libs/spirit/test/karma/test.hpp | 64 ++++---
trunk/libs/spirit/test/lex/lexertl1.cpp | 47 ++---
trunk/libs/spirit/test/lex/lexertl2.cpp | 67 +++----
trunk/libs/spirit/test/lex/lexertl3.cpp | 41 ++--
trunk/libs/spirit/test/lex/lexertl4.cpp | 37 ++--
trunk/libs/spirit/test/lex/lexertl5.cpp | 45 ++---
trunk/libs/spirit/test/lex/state_switcher_test.cpp | 85 +++++-----
trunk/libs/spirit/test/lex/test_parser.hpp | 26 +--
trunk/libs/spirit/test/qi/actions.cpp | 28 ++-
trunk/libs/spirit/test/qi/alternative.cpp | 66 ++++++--
trunk/libs/spirit/test/qi/and_predicate.cpp | 4
trunk/libs/spirit/test/qi/binary.cpp | 43 +++--
trunk/libs/spirit/test/qi/char.cpp | 144 ++++++++++++-----
trunk/libs/spirit/test/qi/char_class.cpp | 18 +-
trunk/libs/spirit/test/qi/difference.cpp | 17 +-
trunk/libs/spirit/test/qi/end.cpp | 67 +++----
trunk/libs/spirit/test/qi/eps.cpp | 19 +
trunk/libs/spirit/test/qi/expect.cpp | 33 ++-
trunk/libs/spirit/test/qi/grammar.cpp | 20 +
trunk/libs/spirit/test/qi/int.cpp | 37 +++
trunk/libs/spirit/test/qi/kleene.cpp | 50 +++---
trunk/libs/spirit/test/qi/lazy.cpp | 33 +++-
trunk/libs/spirit/test/qi/lexeme.cpp | 11
trunk/libs/spirit/test/qi/list.cpp | 26 ++
trunk/libs/spirit/test/qi/lit.cpp | 60 +++++--
trunk/libs/spirit/test/qi/match_manip.cpp | 77 ++++----
trunk/libs/spirit/test/qi/no_case.cpp | 59 ++++++-
trunk/libs/spirit/test/qi/not_predicate.cpp | 5
trunk/libs/spirit/test/qi/optional.cpp | 19 +-
trunk/libs/spirit/test/qi/permutation.cpp | 11
trunk/libs/spirit/test/qi/plus.cpp | 28 +-
trunk/libs/spirit/test/qi/range_run.cpp | 2
trunk/libs/spirit/test/qi/raw.cpp | 18 +
trunk/libs/spirit/test/qi/real.cpp | 75 +++++---
trunk/libs/spirit/test/qi/rule.cpp | 236 ++++++++++++++++++++++++-----
trunk/libs/spirit/test/qi/sequence.cpp | 129 +++++----------
trunk/libs/spirit/test/qi/sequential_or.cpp | 29 ++
trunk/libs/spirit/test/qi/symbols.cpp | 93 +++++++++++
trunk/libs/spirit/test/qi/test.hpp | 36 ++++
trunk/libs/spirit/test/qi/tst.cpp | 8
trunk/libs/spirit/test/qi/uint.cpp | 65 ++++---
136 files changed, 4361 insertions(+), 3141 deletions(-)
Modified: trunk/libs/spirit/CMakeLists.txt
==============================================================================
--- trunk/libs/spirit/CMakeLists.txt (original)
+++ trunk/libs/spirit/CMakeLists.txt 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -13,7 +13,7 @@
TESTDIRS test
HEADERS ${lib_headers}
# DOCDIRS
- DESCRIPTION "LL parser framework represents parsers directly as EBNF grammars in inlined C++."
+ DESCRIPTION "A object oriented, recursive-descent parser and output generation library using the yyntax of Parsing Expression Grammars (PEGs) directly in C++"
MODULARIZED
AUTHORS "Joel de Guzman <joel -at- boost-consulting.com>"
"Hartmut Kaiser <hartmut.kaiser -at- gmail.com>"
Modified: trunk/libs/spirit/example/karma/Jamfile
==============================================================================
--- trunk/libs/spirit/example/karma/Jamfile (original)
+++ trunk/libs/spirit/example/karma/Jamfile 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
#==============================================================================
-# Copyright (c) 2001-2008 Joel de Guzman
-# Copyright (c) 2001-2008 Hartmut Kaiser
+# Copyright (c) 2001-2009 Joel de Guzman
+# Copyright (c) 2001-2009 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)
@@ -9,9 +9,12 @@
exe quick_start1 : quick_start1.cpp ;
exe actions_example : actions.cpp ;
-exe basic_facilities : basic_facilities.cpp ;
-exe functor_facilities : functor_facilities.cpp ;
+exe basic_facilities : basic_facilities.cpp /boost//date_time ;
exe calc2_ast_dump : calc2_ast_dump.cpp ;
exe calc2_ast_rpn : calc2_ast_rpn.cpp ;
exe calc2_ast_vm : calc2_ast_vm.cpp ;
+exe min_xml_karma : min_xml_karma.cpp ;
+
+# not ported yet:
+# exe functor_facilities : functor_facilities.cpp ;
Modified: trunk/libs/spirit/example/karma/actions.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/actions.cpp (original)
+++ trunk/libs/spirit/example/karma/actions.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
/*=============================================================================
- Copyright (c) 2001-2008 Hartmut Kaiser
- Copyright (c) 2001-2008 Joel de Guzman
+ Copyright (c) 2001-2009 Hartmut Kaiser
+ Copyright (c) 2001-2009 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)
@@ -20,7 +20,7 @@
// * Using boost.bind
// * Using boost.lambda
-using namespace boost::spirit;
+using boost::spirit::unused_type;
void read(int& i)
{
@@ -39,8 +39,11 @@
int main()
{
{ // example using plain functions
+ using namespace boost::spirit;
+
std::string generated;
- bool result = karma::generate(std::back_inserter(generated),
+ std::back_insert_iterator<std::string> outit(generated);
+ bool result = karma::generate(outit,
'{' << int_[&read] << '}');
if (result)
@@ -48,8 +51,11 @@
}
{ // example using simple function objects
+ using namespace boost::spirit;
+
std::string generated;
- bool result = karma::generate(std::back_inserter(generated),
+ std::back_insert_iterator<std::string> outit(generated);
+ bool result = karma::generate(outit,
'{' << int_[read_action()] << '}');
if (result)
@@ -57,9 +63,13 @@
}
{ // example using boost.bind
+ using boost::spirit::int_;
+ using boost::spirit::karma::generate;
+
std::string generated;
- bool result = karma::generate(std::back_inserter(generated),
- '{' << int_[boost::bind(&read, _1)] << '}');
+ std::back_insert_iterator<std::string> outit(generated);
+ bool result = generate(outit,
+ '{' << int_[boost::bind(read, _1)] << '}');
if (result)
std::cout << "Boost.Bind: " << generated << std::endl;
@@ -67,11 +77,13 @@
{ // example using boost.lambda
namespace lambda = boost::lambda;
+ using namespace boost::spirit;
std::string generated;
std::stringstream strm("42");
- bool result = karma::generate(std::back_inserter(generated),
+ std::back_insert_iterator<std::string> outit(generated);
+ bool result = karma::generate(outit,
'{' << int_[strm >> lambda::_1] << '}');
if (result)
Modified: trunk/libs/spirit/example/karma/basic_facilities.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/basic_facilities.cpp (original)
+++ trunk/libs/spirit/example/karma/basic_facilities.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -26,6 +26,7 @@
#include <cstdlib>
#include <boost/range.hpp>
+#include <boost/array.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/fusion/include/std_pair.hpp>
@@ -59,17 +60,24 @@
{
// output the container as a space separated sequence
os <<
+ karma::format(
+ *stream, // format description
+ c // data
+ ) << std::endl << std::endl;
+
+ // output the container as a space separated sequence
+ os <<
karma::format_delimited(
*stream, // format description
- c, // data
- space // delimiter
+ space, // delimiter
+ c // data
) << std::endl << std::endl;
os <<
karma::format_delimited(
'[' << *stream << ']', // format description
- c, // data
- space // delimiter
+ space, // delimiter
+ c // data
) << std::endl << std::endl;
// output the container as a comma separated list
@@ -85,11 +93,17 @@
c // data
) << std::endl << std::endl;
- os <<
- karma::format(
- '[' << -(stream % ", ") << ']', // format description
- c // data
- ) << std::endl << std::endl;
+// os <<
+// karma::format(
+// '[' << -(stream % ", ") << ']', // format description
+// c // data
+// ) << std::endl << std::endl;
+
+// os <<
+// karma::format(
+// '[' << (+stream | "empty") << ']', // format description
+// c // data
+// ) << std::endl << std::endl;
// output the container as a comma separated list of items enclosed in '()'
os <<
@@ -105,15 +119,15 @@
) << ']', // format description
c // data
) << std::endl << std::endl;
-
+
// output the container as a HTML list
os <<
karma::format_delimited(
- "<ol>" <<
+ /*"<ol>" << */
*verbatim["<li>" << stream << "</li>"]
- << "</ol>", // format description
- c, // data
- '\n' // delimiter
+ /*<< "</ol>"*/, // format description
+ '\n', // delimiter
+ c // data
) << std::endl;
// output the container as right aligned column
@@ -122,8 +136,8 @@
*verbatim[
"|" << right_align[stream] << "|"
], // format description
- c, // data
- '\n' // delimiter
+ '\n', // delimiter
+ c // data
) << std::endl;
os << std::endl;
@@ -132,15 +146,24 @@
int main()
{
///////////////////////////////////////////////////////////////////////////
+ // C-style array
+ int i[4] = { 3, 6, 9, 12 };
+
+ std::cout << "-------------------------------------------------------------"
+ << std::endl;
+ std::cout << "int i[]" << std::endl;
+ output_container(std::cout, boost::make_iterator_range(i, i+4));
+
+ ///////////////////////////////////////////////////////////////////////////
// vector
- std::vector<int> v (8);
+ std::vector<int> v (5);
std::generate(v.begin(), v.end(), std::rand); // randomly fill the vector
std::cout << "-------------------------------------------------------------"
<< std::endl;
std::cout << "std::vector<int>" << std::endl;
output_container(std::cout, v);
-
+
///////////////////////////////////////////////////////////////////////////
// list
std::list<char> l;
@@ -154,15 +177,6 @@
output_container(std::cout, l);
///////////////////////////////////////////////////////////////////////////
- // C-style array
- int i[4] = { 3, 6, 9, 12 };
-
- std::cout << "-------------------------------------------------------------"
- << std::endl;
- std::cout << "int i[]" << std::endl;
- output_container(std::cout, boost::make_iterator_range(i, i+4));
-
- ///////////////////////////////////////////////////////////////////////////
// strings
std::string str("Hello world!");
@@ -170,7 +184,17 @@
<< std::endl;
std::cout << "std::string" << std::endl;
output_container(std::cout, str);
-
+
+ ///////////////////////////////////////////////////////////////////////////
+ // boost::array
+ boost::array<long, 5> arr;
+ std::generate(arr.begin(), arr.end(), std::rand); // randomly fill the array
+
+ std::cout << "-------------------------------------------------------------"
+ << std::endl;
+ std::cout << "boost::array<long, 5>" << std::endl;
+ output_container(std::cout, arr);
+
///////////////////////////////////////////////////////////////////////////
// vector of boost::date objects
// Note: any registered facets get used!
@@ -187,18 +211,18 @@
<< std::endl;
std::cout << "std::vector<boost::date>" << std::endl;
output_container(std::cout, dates);
-
+
///////////////////////////////////////////////////////////////////////////
// map of int --> string mappings
- std::map<int, std::string> mappings;
- mappings.insert(std::make_pair(0, "zero"));
- mappings.insert(std::make_pair(1, "one"));
- mappings.insert(std::make_pair(2, "two"));
-
- std::cout << "-------------------------------------------------------------"
- << std::endl;
- std::cout << "std::map<int, std::string>" << std::endl;
- output_container(std::cout, mappings);
+// std::map<int, std::string> mappings;
+// mappings.insert(std::make_pair(0, "zero"));
+// mappings.insert(std::make_pair(1, "one"));
+// mappings.insert(std::make_pair(2, "two"));
+//
+// std::cout << "-------------------------------------------------------------"
+// << std::endl;
+// std::cout << "std::map<int, std::string>" << std::endl;
+// output_container(std::cout, mappings);
return 0;
}
Modified: trunk/libs/spirit/example/karma/calc2_ast.hpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast.hpp (original)
+++ trunk/libs/spirit/example/karma/calc2_ast.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
/*=============================================================================
- Copyright (c) 2001-2008 Joel de Guzman
- Copyright (c) 2001-2008 Hartmut Kaiser
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Deleted: trunk/libs/spirit/example/karma/calc2_ast_dump.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_dump.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,165 +0,0 @@
-/*=============================================================================
- 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)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A Calculator example demonstrating generation of AST which gets dumped into
-// a human readable format afterwards.
-//
-// [ JDG April 28, 2008 ]
-// [ HK April 28, 2008 ]
-//
-///////////////////////////////////////////////////////////////////////////////
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/karma.hpp>
-
-#include <iostream>
-#include <vector>
-#include <string>
-
-#include "calc2_ast.hpp"
-
-using namespace boost::spirit;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator parser grammar
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : qi::grammar<Iterator, expression_ast(), space_type>
-{
- calculator() : calculator::base_type(expression)
- {
- expression =
- term [_val = _1]
- >> *( ('+' >> term [_val += _1])
- | ('-' >> term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' >> factor [_val *= _1])
- | ('/' >> factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' >> expression [_val = _1] >> ')'
- | ('-' >> factor [_val = neg(_1)])
- | ('+' >> factor [_val = pos(_1)])
- ;
- }
-
- qi::rule<Iterator, expression_ast(), space_type> expression, term, factor;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Our AST grammar for the generator, this just dumps the AST as a expression
-///////////////////////////////////////////////////////////////////////////////
-template <typename OuputIterator>
-struct dump_ast
- : karma::grammar<OuputIterator, expression_ast(), space_type>
-{
- dump_ast() : dump_ast::base_type(ast_node)
- {
- ast_node %=
- int_ [_1 = _int(_val)]
- | binary_node [_1 = _bin_op(_val)]
- | unary_node [_1 = _unary_op(_val)]
- ;
-
- binary_node =
- ('(' << ast_node << char_ << ast_node << ')')
- [
- _1 = _left(_val), _2 = _op(_val), _3 = _right(_val)
- ]
- ;
-
- unary_node =
- ('(' << char_ << ast_node << ')')
- [
- _1 = _op(_val), _2 = _right(_val)
- ]
- ;
- }
-
- karma::rule<OuputIterator, expression_ast(), space_type> ast_node;
- karma::rule<OuputIterator, binary_op(), space_type> binary_node;
- karma::rule<OuputIterator, unary_op(), space_type> unary_node;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Dump AST's for simple expressions...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- // Our parser grammar definitions
- typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
-
- calculator calc;
-
- // Our generator grammar definitions
- typedef std::back_insert_iterator<std::string> output_iterator_type;
- typedef dump_ast<output_iterator_type> dump_ast;
-
- dump_ast ast_grammar;
-
- std::string str;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- expression_ast ast;
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = qi::phrase_parse(iter, end, calc, ast, space);
-
- if (r && iter == end)
- {
- std::string generated;
- r = karma::generate_delimited(
- std::back_inserter(generated), ast_grammar, ast, space);
-
- if (r)
- {
- std::cout << "AST for '" << str << "': " << generated
- << std::endl;
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Generating failed\n";
- std::cout << "-------------------------\n";
- }
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-
Deleted: trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/calc2_ast_rpn.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,169 +0,0 @@
-/*=============================================================================
- 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)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A Calculator example demonstrating generation of AST which gets dumped into
-// a reverse polish notation afterwards.
-//
-// [ JDG April 28, 2008 ]
-// [ HK April 28, 2008 ]
-//
-///////////////////////////////////////////////////////////////////////////////
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/karma.hpp>
-
-#include <iostream>
-#include <vector>
-#include <string>
-
-#include "calc2_ast.hpp"
-
-using namespace boost::spirit;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator parser grammar
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : qi::grammar<Iterator, expression_ast(), space_type>
-{
- calculator() : calculator::base_type(expression)
- {
- expression =
- term [_val = _1]
- >> *( ('+' >> term [_val += _1])
- | ('-' >> term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' >> factor [_val *= _1])
- | ('/' >> factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' >> expression [_val = _1] >> ')'
- | ('-' >> factor [_val = neg(_1)])
- | ('+' >> factor [_val = pos(_1)])
- ;
- }
-
- qi::rule<Iterator, expression_ast(), space_type> expression, term, factor;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Our AST grammar for the generator, this prints the AST in reverse polish
-// notation
-///////////////////////////////////////////////////////////////////////////////
-template <typename OuputIterator>
-struct ast_rpn
- : karma::grammar<OuputIterator, expression_ast(), space_type>
-{
- ast_rpn() : ast_rpn::base_type(ast_node)
- {
- ast_node %=
- int_ [_1 = _int(_val)]
- | binary_node [_1 = _bin_op(_val)]
- | unary_node [_1 = _unary_op(_val)]
- ;
-
- binary_node =
- (ast_node << ast_node << char_)
- [
- _1 = _left(_val), _2 = _right(_val), _3 = _op(_val)
- ]
- ;
-
- unary_node =
- verbatim [
- ('(' << ast_node << char_ << ')')
- [
- _1 = _right(_val), _2 = _op(_val)
- ]
- ]
- ;
- }
-
- karma::rule<OuputIterator, expression_ast(), space_type> ast_node;
- karma::rule<OuputIterator, binary_op(), space_type> binary_node;
- karma::rule<OuputIterator, unary_op(), space_type> unary_node;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "RPN generator for simple expressions...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- // Our parser grammar definitions
- typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
-
- calculator calc;
-
- // Our generator grammar definitions
- typedef std::back_insert_iterator<std::string> output_iterator_type;
- typedef ast_rpn<output_iterator_type> ast_rpn;
-
- ast_rpn ast_grammar;
-
- std::string str;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- expression_ast ast; // this will hold the generated AST
-
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
- bool r = qi::phrase_parse(iter, end, calc, ast, space);
-
- if (r && iter == end)
- {
- std::string generated;
- r = karma::generate_delimited(
- std::back_inserter(generated), ast_grammar, ast, space);
-
- if (r)
- {
- std::cout << "RPN for '" << str << "': " << generated
- << std::endl;
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Generating failed\n";
- std::cout << "-------------------------\n";
- }
- }
- else
- {
- std::string rest(iter, end);
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "stopped at: \": " << rest << "\"\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-
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 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -16,9 +16,9 @@
//
///////////////////////////////////////////////////////////////////////////////
#include <boost/config/warning_disable.hpp>
+
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/karma.hpp>
-#include <boost/spirit/home/karma/binary.hpp>
#include <iostream>
#include <vector>
@@ -28,13 +28,13 @@
using namespace boost::spirit;
using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
///////////////////////////////////////////////////////////////////////////////
// Our calculator parser grammar
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
-struct calculator : qi::grammar<Iterator, expression_ast(), space_type>
+struct calculator
+ : qi::grammar<Iterator, expression_ast(), space_type>
{
calculator() : calculator::base_type(expression)
{
@@ -138,20 +138,24 @@
generate_byte_code() : generate_byte_code::base_type(ast_node)
{
ast_node %=
- (dword(op_int) << dword) [_1 = _int(_val)]
- | binary_node [_1 = _bin_op(_val)]
- | unary_node [_1 = _unary_op(_val)]
+ int_node [_1 = _int(_val)]
+ | binary_node [_1 = _bin_op(_val)]
+ | unary_node [_1 = _unary_op(_val)]
+ ;
+
+ int_node %=
+ dword(op_int) << dword
;
-
+
binary_node =
- (ast_node << ast_node << byte)
+ (ast_node << ast_node << byte_)
[
_1 = _left(_val), _2 = _right(_val), _3 = _op(_val)
]
;
unary_node =
- (ast_node << byte)
+ (ast_node << byte_)
[
_1 = _right(_val), _2 = _op(_val)
]
@@ -159,6 +163,7 @@
}
karma::rule<OuputIterator, expression_ast(), Delimiter> ast_node;
+ karma::rule<OuputIterator, int(), Delimiter> int_node;
karma::rule<OuputIterator, binary_op(), Delimiter> binary_node;
karma::rule<OuputIterator, unary_op(), Delimiter> unary_node;
};
@@ -173,8 +178,9 @@
typedef char* output_iterator_type;
typedef generate_byte_code<output_iterator_type, Delimiter> generate_byte_code;
+ char* outbuffer = (*code.begin()).bytes;
generate_byte_code gen_vm;
- return karma::generate_delimited((*code.begin()).bytes, gen_vm, ast, d);
+ return karma::generate_delimited(outbuffer, gen_vm, d, ast);
}
///////////////////////////////////////////////////////////////////////////////
@@ -203,14 +209,14 @@
expression_ast ast;
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
- bool r = qi::phrase_parse(iter, end, calc, ast, space);
+ bool r = qi::phrase_parse(iter, end, calc, space, ast);
if (r && iter == end)
{
// we assume a vm code size of 4096 is sufficient
std::vector<vmachine::element> code (4096);
r = generate_vm_code(ast, code, pad(4));
-
+
if (r)
{
vmachine vm;
Deleted: trunk/libs/spirit/example/karma/functor_facilities.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/functor_facilities.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,199 +0,0 @@
-// Copyright (c) 2001-2009 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)
-
-// This examples demonstrate how to write functor based generators for special
-// purposes.
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/karma.hpp>
-#include <boost/spirit/include/karma_stream.hpp>
-
-#include <boost/spirit/include/phoenix_core.hpp>
-#include <boost/spirit/include/phoenix_bind.hpp>
-
-#include <iostream>
-#include <string>
-#include <vector>
-#include <list>
-#include <algorithm>
-#include <cstdlib>
-
-using namespace boost::spirit;
-
-///////////////////////////////////////////////////////////////////////////////
-// The functor generator 'counter' can be used for output annotation with some
-// item counting information.
-///////////////////////////////////////////////////////////////////////////////
-struct counter_impl : boost::spirit::karma::functor_base
-{
- template <typename OutputIterator, typename Context, typename Parameter>
- bool operator()(Parameter const&, Context& ctx, OutputIterator& sink) const
- {
- return karma::generate(sink, int_ << ": ", counter++);
- }
-
- counter_impl(int& counter_)
- : counter(counter_) {}
-
- int& counter;
-};
-
-inline boost::spirit::result_of::as_generator<counter_impl>::type
-counter(int& counter_)
-{
- using namespace boost::spirit::karma;
- return as_generator(counter_impl(counter_));
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// The functor generator 'confix' allows a simple syntax for generating
-// output wrapped inside a pair of a prefix and a suffix.
-///////////////////////////////////////////////////////////////////////////////
-template <typename Expr>
-struct confix_impl : public boost::spirit::karma::functor_base
-{
- template <typename Context>
- struct apply
- {
- typedef boost::spirit::hold_any type;
- };
-
- template <typename OutputIterator, typename Context, typename Parameter>
- bool operator()(Parameter const& v, Context& ctx, OutputIterator& sink) const
- {
- return karma::generate(sink, open << xpr << close, v);
- }
-
- confix_impl(char const* open_, char const* close_, Expr const& xpr_)
- : open(open_), close(close_), xpr(xpr_) {}
-
- std::string open;
- std::string close;
- Expr xpr;
-};
-
-template <typename Expr>
-inline typename boost::spirit::result_of::as_generator<confix_impl<Expr> >::type
-confix(Expr const& xpr_, char const* open_ = "", char const* close_ = "")
-{
- using namespace boost::spirit::karma;
- return as_generator(confix_impl<Expr>(open_, close_, xpr_));
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// The functor generator 'list' allows a simple syntax for generating
-// list formatted output.
-//
-// This example uses phoenix::bind to allow to omit the second argument from
-// the operator() and to allow to switch the remaining two arguments.
-///////////////////////////////////////////////////////////////////////////////
-template <typename Expr>
-struct list_impl : boost::spirit::karma::functor_base
-{
- // this function will be called to generate the output
- template <typename OutputIterator, typename Parameter>
- bool operator()(OutputIterator& sink, Parameter const& v) const
- {
- return karma::generate(sink, xpr % delim, v);
- }
-
- list_impl(Expr const& xpr_, char const* delim_)
- : xpr(xpr_), delim(delim_) {}
-
- Expr xpr;
- std::string delim;
-};
-
-// Supply the expected parameter type explicitly
-struct list_impl_mf
-{
- // the expected parameter type of a functor has to be defined using a
- // embedded apply metafunction
- template <typename Context>
- struct apply
- {
- typedef boost::spirit::hold_any type;
- };
-};
-
-template <typename Expr>
-inline list_impl<Expr>
-list(Expr const& xpr, char const* delim)
-{
- return list_impl<Expr>(xpr, delim);
-}
-
-///////////////////////////////////////////////////////////////////////////////
-int main()
-{
- using namespace boost::phoenix;
- using namespace boost::phoenix::arg_names;
-
- ///////////////////////////////////////////////////////////////////////////
- // Output the given containers in list format
- // We use a special functor generator here to annotate the output with
- // a integer counting the entries.
- ///////////////////////////////////////////////////////////////////////////
- std::vector<int> v (8);
- std::generate(v.begin(), v.end(), std::rand); // randomly fill the vector
-
- int counter1 = 1;
- std::cout <<
- karma::format(
- (counter(counter1) << int_) % ", ", // format description
- v // data
- ) << std::endl;
-
- // Here we initialize the counter to 100
- int counter2 = 100;
- std::cout <<
- karma::format(
- '[' << (
- (counter(counter2) << int_) % ", "
- ) << ']', // format description
- v // data
- ) << std::endl;
-
- ///////////////////////////////////////////////////////////////////////////
- // list
- // The output format description used below adds special item formatting
- ///////////////////////////////////////////////////////////////////////////
- std::list<std::string> names;
- names.push_back("Spirit");
- names.push_back("Qi");
- names.push_back("Karma");
-
- // specifying a prefix item suffix scheme directly
- std::cout <<
- karma::format(
- ('{' << stream << '}') % ", ", // format description
- names // data
- ) << std::endl;
-
- // The confix generator nicely wraps the given expression with prefix and
- // suffix strings
- std::cout <<
- karma::format(
- confix(stream % ", ", "[", "]"), // format description
- names // data
- ) << std::endl;
-
- ///////////////////////////////////////////////////////////////////////////
- // Output the given container as a list
- // We use a separate metafunction list_impl_mf to specify the expected
- // parameter type of this functor generator.
- // We use phoenix::bind to allow to omit the 2nd argument from the functor
- // function operator and to change the sequence of the remaining two
- // arguments.
- ///////////////////////////////////////////////////////////////////////////
- std::string str("Hello world!");
- std::cout <<
- karma::format(
- karma::as_generator_mf<list_impl_mf>(bind(list(stream, ", "), _3, _1)),
- str
- ) << std::endl;
-
- return 0;
-}
Added: trunk/libs/spirit/example/karma/karma_problem.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/karma/karma_problem.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,79 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 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/spirit/include/karma.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_fusion.hpp>
+#include <boost/fusion/include/adapt_struct.hpp>
+#include <boost/variant/recursive_variant.hpp>
+
+#include <string>
+#include <vector>
+
+using namespace boost::spirit;
+using namespace boost::spirit::ascii;
+
+namespace fusion = boost::fusion;
+namespace phoenix = boost::phoenix;
+
+using phoenix::at_c;
+
+struct mini_xml;
+
+typedef
+ boost::variant<
+ boost::recursive_wrapper<mini_xml>
+ , std::string
+ >
+mini_xml_node;
+
+struct mini_xml
+{
+ std::string name; // tag name
+ std::vector<mini_xml_node> children; // children
+};
+
+BOOST_FUSION_ADAPT_STRUCT(
+ mini_xml,
+ (std::string, name)
+ (std::vector<mini_xml_node>, children)
+)
+
+template <typename OutputIterator>
+struct mini_xml_generator
+ : karma::grammar<OutputIterator, mini_xml()>
+{
+ mini_xml_generator() : mini_xml_generator::base_type(xml)
+ {
+ xml =
+// string[_1 = at_c<0>(_val)] // this compiles
+ string(at_c<0>(_val)) // this doesn't compile
+ ;
+ }
+
+ karma::rule<OutputIterator, mini_xml()> xml;
+};
+
+int main(int argc, char **argv)
+{
+ mini_xml ast;
+
+ typedef std::back_insert_iterator<std::string> outiter_type;
+ typedef mini_xml_generator<outiter_type> mini_xml_generator;
+
+ mini_xml_generator xmlout;
+
+ std::string generated;
+ outiter_type outit(generated);
+ bool r = karma::generate(outit, xmlout, ast);
+
+ return 0;
+}
+
+
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 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
/*=============================================================================
- Copyright (c) 2001-2008 Joel de Guzman
- Copyright (c) 2001-2008 Hartmut Kaiser
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -15,6 +15,7 @@
///////////////////////////////////////////////////////////////////////////////
#include <boost/config/warning_disable.hpp>
+
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
@@ -32,7 +33,6 @@
using namespace boost::spirit;
using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
namespace fusion = boost::fusion;
namespace phoenix = boost::phoenix;
@@ -133,13 +133,14 @@
mini_xml_generator() : mini_xml_generator::base_type(xml)
{
node %=
- lit[_1 = _string(_r0)]
- | xml[_1 = _xml(_r0)]
+ string [_1 = _string(_val)]
+ | xml [_1 = _xml(_val)]
;
- xml = char_('<') << lit(at_c<0>(_r0)) << '>'
- << (*node)[_1 = at_c<1>(_r0)]
- << lit("</") << lit(at_c<0>(_r0)) << '>'
+ xml =
+ char_('<') << string[_1 = at_c<0>(_val)] << '>'
+ << (*node)[_1 = at_c<1>(_val)]
+ << lit("</") << string[_1 = at_c<0>(_val)] << '>'
;
}
@@ -185,7 +186,7 @@
std::string::const_iterator iter = storage.begin();
std::string::const_iterator end = storage.end();
- bool r = qi::phrase_parse(iter, end, xmlin, ast, space);
+ bool r = qi::phrase_parse(iter, end, xmlin, space, ast);
if (r && iter == end)
{
@@ -199,7 +200,8 @@
mini_xml_generator xmlout; // Our grammar definition
std::string generated;
- bool r = karma::generate(std::back_inserter(generated), xmlout, ast);
+ outiter_type outit(generated);
+ bool r = karma::generate(outit, xmlout, ast);
if (r)
std::cout << generated << std::endl;
Modified: trunk/libs/spirit/example/karma/quick_start1.cpp
==============================================================================
--- trunk/libs/spirit/example/karma/quick_start1.cpp (original)
+++ trunk/libs/spirit/example/karma/quick_start1.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -41,15 +41,15 @@
std::cout <<
karma::format_delimited(
*int_, // format description
- v, // data
- space // delimiter
+ space, // delimiter
+ v // data
) << std::endl << std::endl;
std::cout <<
karma::format_delimited(
'[' << *int_ << ']', // format description
- v, // data
- space // delimiter
+ space, // delimiter
+ v // data
) << std::endl << std::endl;
// output the container as a comma separated list
@@ -98,8 +98,8 @@
// no delimiting within verbatim
*verbatim[" <li>" << int_ << "</li>"]
<< "</ol>", // format description
- v, // data
- '\n' // delimiter
+ '\n', // delimiter
+ v // data
) << std::endl;
// output the container as right aligned column
@@ -109,8 +109,8 @@
*verbatim[
"|" << right_align[int_] << "|"
], // format description
- v, // data
- '\n' // delimiter
+ '\n', // delimiter
+ v // data
) << std::endl;
std::cout << std::endl;
Modified: trunk/libs/spirit/example/lex/Jamfile
==============================================================================
--- trunk/libs/spirit/example/lex/Jamfile (original)
+++ trunk/libs/spirit/example/lex/Jamfile 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
#==============================================================================
-# Copyright (c) 2001-2008 Joel de Guzman
-# Copyright (c) 2001-2008 Hartmut Kaiser
+# Copyright (c) 2001-2009 Joel de Guzman
+# Copyright (c) 2001-2009 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)
@@ -8,16 +8,17 @@
project spirit-lexer-example ;
-exe example1 : example1.cpp ;
-exe example2 : example2.cpp ;
-exe example3 : example3.cpp ;
-exe example4 : example4.cpp ;
-exe example5 : example5.cpp ;
-exe example6 : example6.cpp ;
-exe print_numbers : print_numbers.cpp ;
-exe word_count : word_count.cpp ;
-exe word_count_functor : word_count_functor.cpp ;
-exe word_count_lexer : word_count_lexer.cpp ;
-exe strip_comments : strip_comments.cpp ;
-exe strip_comments_lexer : strip_comments_lexer.cpp ;
+exe example1 : example1.cpp ;
+exe example2 : example2.cpp ;
+exe example3 : example3.cpp ;
+exe example4 : example4.cpp ;
+exe example5 : example5.cpp ;
+exe example6 : example6.cpp ;
+exe print_numbers : print_numbers.cpp ;
+exe word_count : word_count.cpp ;
+exe word_count_functor : word_count_functor.cpp ;
+exe word_count_lexer : word_count_lexer.cpp ;
+exe word_count_lexer_flex : word_count_lexer_flex.cpp ;
+exe strip_comments : strip_comments.cpp ;
+exe strip_comments_lexer : strip_comments_lexer.cpp ;
Modified: trunk/libs/spirit/example/lex/example1.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/example1.cpp (original)
+++ trunk/libs/spirit/example/lex/example1.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,14 +1,13 @@
// Copyright (c) 2001-2009 Hartmut Kaiser
-// Copyright (c) 2001-2007 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)
// Simple lexer/parser to test the Spirit installation.
//
-// This example shows, how to create a simple lexer recognizing 4 different
+// This example shows, how to create a simple lexer recognizing 5 different
// tokens, and how to use a single token definition as the skip parser during
-// the parsing. Additionally it demonstrates how to use one of the defined
+// the parsing. Additionally, it demonstrates how to use one of the defined
// tokens as a parser component in the grammar.
//
// The grammar recognizes a simple input structure, for instance:
@@ -20,6 +19,8 @@
// Any number of simple sentences (optionally comma separated) inside a pair
// of curly braces will be matched.
+// #define BOOST_SPIRIT_LEXERTL_DEBUG
+
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/lex_lexer_lexertl.hpp>
@@ -31,6 +32,7 @@
#include "example.hpp"
using namespace boost::spirit;
+using namespace boost::spirit::ascii;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
@@ -38,21 +40,20 @@
// Token definition
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct example1_tokens : lexer_def<Lexer>
+struct example1_tokens : lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ example1_tokens()
{
// define tokens and associate them with the lexer
identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
- self = token_def<>(',') | '{' | '}' | identifier;
-
+ this->self = char_(',') | '{' | '}' | identifier;
+
// any token definition to be used as the skip parser during parsing
// has to be associated with a separate lexer state (here 'WS')
- white_space = "[ \\t\\n]+";
- self("WS") = white_space;
+ this->white_space = "[ \\t\\n]+";
+ this->self("WS") = white_space;
}
-
+
token_def<> identifier, white_space;
};
@@ -78,29 +79,27 @@
{
// iterator type used to expose the underlying input stream
typedef std::string::iterator base_iterator_type;
-
+
// This is the token type to return from the lexer iterator
- typedef lexertl_token<base_iterator_type> token_type;
-
+ typedef lexertl::token<base_iterator_type> token_type;
+
// This is the lexer type to use to tokenize the input.
// We use the lexertl based lexer engine.
- typedef lexertl_lexer<token_type> lexer_type;
-
- // This is the token definition type (derived from the given lexer type).
- typedef example1_tokens<lexer_type> example1_tokens;
-
+ typedef lexertl::lexer<token_type> lexer_type;
+
+ // This is the lexer type (derived from the given lexer type).
+ typedef example1_tokens<lexer_type> example1_lex;
+
// This is the iterator type exposed by the lexer
- typedef lexer<example1_tokens>::iterator_type iterator_type;
+ typedef example1_lex::iterator_type iterator_type;
// This is the type of the grammar to parse
typedef example1_grammar<iterator_type> example1_grammar;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- example1_tokens tokens; // Our token definition
- example1_grammar calc(tokens); // Our grammar definition
-
- lexer<example1_tokens> lex(tokens); // Our lexer
+ example1_lex lex; // Our lexer
+ example1_grammar calc(lex); // Our grammar definition
std::string str (read_from_file("example1.input"));
@@ -115,7 +114,7 @@
// Note, how we use the token_def defined above as the skip parser. It must
// be explicitly wrapped inside a state directive, switching the lexer
// state for the duration of skipping whitespace.
- bool r = phrase_parse(iter, end, calc, in_state("WS")[tokens.white_space]);
+ bool r = phrase_parse(iter, end, calc, in_state("WS")[lex.white_space]);
if (r && iter == end)
{
Modified: trunk/libs/spirit/example/lex/example2.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/example2.cpp (original)
+++ trunk/libs/spirit/example/lex/example2.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,4 @@
// Copyright (c) 2001-2009 Hartmut Kaiser
-// Copyright (c) 2001-2007 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)
@@ -22,7 +21,7 @@
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>
@@ -32,6 +31,7 @@
#include "example.hpp"
using namespace boost::spirit;
+using namespace boost::spirit::ascii;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
using boost::phoenix::ref;
@@ -40,10 +40,9 @@
// Token definition
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct example2_tokens : lexer_def<Lexer>
+struct example2_tokens : lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ example2_tokens()
{
// A 'word' is comprised of one or more letters and an optional
// apostrophe. If it contains an apostrophe, there may only be one and
@@ -51,11 +50,15 @@
// For example, "I'm" and "doesn't" meet the definition of 'word' we
// define below.
word = "[a-zA-Z]+('[a-zA-Z]+)?";
-
- // associate the tokens and the token set with the lexer
+
+ // Associate the tokens and the token set with the lexer. Note that
+ // single character token definitions as used below always get
+ // interpreted literally and never as special regex characters. This is
+ // done to be able to assign single characters the id of their character
+ // code value, allowing to reference those as literals in Qi grammars.
self = token_def<>(',') | '!' | '.' | '?' | ' ' | '\n' | word;
}
-
+
token_def<> word;
};
@@ -67,8 +70,8 @@
{
template <typename TokenDef>
example2_grammar(TokenDef const& tok)
- : example2_grammar::base_type(story),
- paragraphs(0), commands(0), questions(0), statements(0)
+ : example2_grammar::base_type(story)
+ , paragraphs(0), commands(0), questions(0), statements(0)
{
story
= +paragraph
@@ -112,38 +115,36 @@
{
// iterator type used to expose the underlying input stream
typedef std::string::iterator base_iterator_type;
-
+
// This is the token type to return from the lexer iterator
- typedef lexertl_token<base_iterator_type> token_type;
-
+ typedef lexertl::token<base_iterator_type> token_type;
+
// This is the lexer type to use to tokenize the input.
// Here we use the lexertl based lexer engine.
- typedef lexertl_lexer<token_type> lexer_type;
-
+ typedef lexertl::lexer<token_type> lexer_type;
+
// This is the token definition type (derived from the given lexer type).
typedef example2_tokens<lexer_type> example2_tokens;
-
+
// this is the iterator type exposed by the lexer
- typedef lexer<example2_tokens>::iterator_type iterator_type;
+ typedef example2_tokens::iterator_type iterator_type;
// this is the type of the grammar to parse
typedef example2_grammar<iterator_type> example2_grammar;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- example2_tokens tokens; // Our token definition
- example2_grammar calc(tokens); // Our grammar definition
-
- lexer<example2_tokens> lex(tokens); // Our lexer
+ example2_tokens tokens; // Our lexer
+ example2_grammar calc(tokens); // Our parser
std::string str (read_from_file("example2.input"));
// At this point we generate the iterator pair used to expose the
// tokenized input stream.
std::string::iterator it = str.begin();
- iterator_type iter = lex.begin(it, str.end());
- iterator_type end = lex.end();
-
+ iterator_type iter = tokens.begin(it, str.end());
+ iterator_type end = tokens.end();
+
// Parsing is done based on the the token stream, not the character
// stream read from the input.
bool r = parse(iter, end, calc);
Modified: trunk/libs/spirit/example/lex/example3.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/example3.cpp (original)
+++ trunk/libs/spirit/example/lex/example3.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,4 @@
// Copyright (c) 2001-2009 Hartmut Kaiser
-// Copyright (c) 2001-2007 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)
@@ -40,29 +39,28 @@
// Token definition
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct example3_tokens : lexer_def<Lexer>
+struct example3_tokens : lexer<Lexer>
{
typedef typename Lexer::token_set token_set;
-
- template <typename Self>
- void def (Self& self)
+
+ example3_tokens()
{
// define the tokens to match
ellipses = "\\.\\.\\.";
number = "[0-9]+";
-
+
// define the whitespace to ignore (spaces, tabs, newlines and C-style
// comments)
white_space
= token_def<>("[ \\t\\n]+") // whitespace
| "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/" // C style comments
;
-
+
// associate the tokens and the token set with the lexer
- self = ellipses | '(' | ')' | number;
- self("WS") = white_space;
+ this->self = ellipses | '(' | ')' | number;
+ this->self("WS") = white_space;
}
-
+
// these tokens expose the iterator_range of the matched input sequence
token_def<> ellipses, identifier, number;
token_set white_space;
@@ -108,35 +106,33 @@
typedef std::string::iterator base_iterator_type;
// This is the token type to return from the lexer iterator
- typedef lexertl_token<base_iterator_type> token_type;
+ typedef lexertl::token<base_iterator_type> token_type;
// This is the lexer type to use to tokenize the input.
// Here we use the lexertl based lexer engine.
- typedef lexertl_lexer<token_type> lexer_type;
+ typedef lexertl::lexer<token_type> lexer_type;
// This is the token definition type (derived from the given lexer type).
typedef example3_tokens<lexer_type> example3_tokens;
// this is the iterator type exposed by the lexer
- typedef lexer<example3_tokens>::iterator_type iterator_type;
+ typedef example3_tokens::iterator_type iterator_type;
// this is the type of the grammar to parse
typedef example3_grammar<iterator_type, lexer_type> example3_grammar;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- example3_tokens tokens; // Our token definition
- example3_grammar calc(tokens); // Our grammar definition
-
- lexer<example3_tokens> lex(tokens); // Our lexer
+ example3_tokens tokens; // Our lexer
+ example3_grammar calc(tokens); // Our parser
std::string str (read_from_file("example3.input"));
// At this point we generate the iterator pair used to expose the
// tokenized input stream.
std::string::iterator it = str.begin();
- iterator_type iter = lex.begin(it, str.end());
- iterator_type end = lex.end();
+ iterator_type iter = tokens.begin(it, str.end());
+ iterator_type end = tokens.end();
// Parsing is done based on the the token stream, not the character
// stream read from the input.
Modified: trunk/libs/spirit/example/lex/example4.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/example4.cpp (original)
+++ trunk/libs/spirit/example/lex/example4.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,4 @@
// Copyright (c) 2001-2009 Hartmut Kaiser
-// Copyright (c) 2001-2007 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)
@@ -24,7 +23,7 @@
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>
@@ -36,7 +35,6 @@
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
-using namespace boost::spirit::arg_names;
using boost::phoenix::val;
@@ -44,12 +42,11 @@
// Token definition
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct example4_tokens : lexer_def<Lexer>
+struct example4_tokens : lexer<Lexer>
{
typedef typename Lexer::token_set token_set;
-
- template <typename Self>
- void def (Self& self)
+
+ example4_tokens()
{
// define the tokens to match
identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
@@ -57,29 +54,29 @@
if_ = "if";
else_ = "else";
while_ = "while";
-
+
// define the whitespace to ignore (spaces, tabs, newlines and C-style
// comments)
white_space
= token_def<>("[ \\t\\n]+")
| "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/"
;
-
+
// associate the tokens and the token set with the lexer
- self = token_def<>('(') | ')' | '{' | '}' | '=' | ';' | constant;
- self += if_ | else_ | while_ | identifier;
- self("WS") = white_space;
+ this->self = token_def<>('(') | ')' | '{' | '}' | '=' | ';' | constant;
+ this->self += if_ | else_ | while_ | identifier;
+ this->self("WS") = white_space;
}
//[example4_token_def
// these tokens expose the iterator_range of the matched input sequence
token_def<> if_, else_, while_;
-
+
// The following two tokens have an associated value type, 'identifier'
// carries a string (the identifier name) and 'constant' carries the
// matched integer value.
//
- // Note: any token value type specified explicitly during a token_def<>
+ // Note: any token attribute type explicitly specified in a token_def<>
// declaration needs to be listed during token type definition as
// well (see the typedef for the token_type below).
//
@@ -87,7 +84,7 @@
// once (on first access), which makes token values as efficient as
// possible. Moreover, token instances are constructed once by the lexer
// library. From this point on tokens are passed by reference only,
- // avoiding tokens being copied around.
+ // avoiding them being copied around.
token_def<std::string> identifier;
token_def<unsigned int> constant;
//]
@@ -155,11 +152,11 @@
typedef typename Lexer::token_set token_set;
typedef boost::variant<unsigned int, std::string> expression_type;
-
+
rule<Iterator, in_state_skipper<token_set> > program, block, statement;
rule<Iterator, in_state_skipper<token_set> > assignment, if_stmt;
rule<Iterator, in_state_skipper<token_set> > while_stmt;
-
+
// the expression is the only rule having a return value
rule<Iterator, expression_type(), in_state_skipper<token_set> > expression;
};
@@ -169,7 +166,7 @@
{
// iterator type used to expose the underlying input stream
typedef std::string::iterator base_iterator_type;
-
+
//[example4_token
// This is the lexer token type to use. The second template parameter lists
// all attribute types used for token_def's during token definition (see
@@ -184,36 +181,34 @@
// least one token value type you'll have to list all value types used
// for token_def<> declarations in the token definition class above,
// otherwise compilation errors will occur.
- typedef lexertl_token<
+ typedef lexertl::token<
base_iterator_type, boost::mpl::vector<unsigned int, std::string>
> token_type;
//]
// Here we use the lexertl based lexer engine.
- typedef lexertl_lexer<token_type> lexer_type;
-
+ typedef lexertl::lexer<token_type> lexer_type;
+
// This is the token definition type (derived from the given lexer type).
typedef example4_tokens<lexer_type> example4_tokens;
-
+
// this is the iterator type exposed by the lexer
- typedef lexer<example4_tokens>::iterator_type iterator_type;
+ typedef example4_tokens::iterator_type iterator_type;
// this is the type of the grammar to parse
typedef example4_grammar<iterator_type, lexer_type> example4_grammar;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- example4_tokens tokens; // Our token definition
- example4_grammar calc(tokens); // Our grammar definition
-
- lexer<example4_tokens> lex(tokens); // Our lexer
+ example4_tokens tokens; // Our lexer
+ example4_grammar calc(tokens); // Our parser
std::string str (read_from_file("example4.input"));
// At this point we generate the iterator pair used to expose the
// tokenized input stream.
std::string::iterator it = str.begin();
- iterator_type iter = lex.begin(it, str.end());
- iterator_type end = lex.end();
+ iterator_type iter = tokens.begin(it, str.end());
+ iterator_type end = tokens.end();
// Parsing is done based on the the token stream, not the character
// stream read from the input.
Modified: trunk/libs/spirit/example/lex/example5.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/example5.cpp (original)
+++ trunk/libs/spirit/example/lex/example5.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,4 @@
// Copyright (c) 2001-2009 Hartmut Kaiser
-// Copyright (c) 2001-2007 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)
@@ -13,7 +12,7 @@
// as the skip parser during parsing, allowing to define several tokens to be
// ignored.
//
-// The main purpose of this example is to show, how inheritance can be used to
+// The main purpose of this example is to show how inheritance can be used to
// overload parts of a base grammar and add token definitions to a base lexer.
//
// Further, it shows how you can use the 'omitted' attribute type specifier
@@ -38,7 +37,6 @@
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
-using namespace boost::spirit::arg_names;
using boost::phoenix::val;
@@ -46,40 +44,44 @@
// Token definition base, defines all tokens for the base grammar below
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct example5_base_tokens : lexer_def<Lexer>
+struct example5_base_tokens : lexer<Lexer>
{
typedef typename Lexer::token_set token_set;
-
- template <typename Self>
- void def (Self& self)
+
+protected:
+ // this lexer is supposed to be used as a base type only
+ example5_base_tokens() {}
+
+public:
+ void init_token_definitions()
{
// define the tokens to match
identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
constant = "[0-9]+";
if_ = "if";
while_ = "while";
-
+
// define the whitespace to ignore (spaces, tabs, newlines and C-style
// comments)
white_space
= token_def<>("[ \\t\\n]+")
| "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/"
;
-
+
// associate the tokens and the token set with the lexer
- self += token_def<>('(') | ')' | '{' | '}' | '=' | ';' | constant;
- self += if_ | while_ | identifier;
- self("WS") = white_space;
+ this->self += token_def<>('(') | ')' | '{' | '}' | '=' | ';' | constant;
+ this->self += if_ | while_ | identifier;
+ this->self("WS") = white_space;
}
-
- // these tokens have no value
+
+ // these tokens have no attribute
token_def<omitted> if_, while_;
-
- // The following two tokens have an associated value type, identifier
- // carries a string (the identifier name) and constant carries the matched
- // integer value.
+
+ // The following two tokens have an associated attribute type, 'identifier'
+ // carries a string (the identifier name) and 'constant' carries the
+ // matched integer value.
//
- // Note: any explicitly token value type specified during a token_def<>
+ // Note: any token attribute type explicitly specified in a token_def<>
// declaration needs to be listed during token type definition as
// well (see the typedef for the token_type below).
//
@@ -87,7 +89,7 @@
// once (on first access), which makes token values as efficient as
// possible. Moreover, token instances are constructed once by the lexer
// library. From this point on tokens are passed by reference only,
- // avoiding tokens being copied around.
+ // avoiding them being copied around.
token_def<std::string> identifier;
token_def<unsigned int> constant;
@@ -150,15 +152,12 @@
;
}
- typedef
- grammar<Iterator, in_state_skipper<typename Lexer::token_set> >
- base_type;
- typedef typename base_type::skipper_type skipper_type;
-
+ typedef in_state_skipper<typename Lexer::token_set> skipper_type;
+
rule<Iterator, skipper_type> program, block, statement;
rule<Iterator, skipper_type> assignment, if_stmt;
rule<Iterator, skipper_type> while_stmt;
-
+
// the expression is the only rule having a return value
typedef boost::variant<unsigned int, std::string> expression_type;
rule<Iterator, expression_type(), skipper_type> expression;
@@ -170,23 +169,23 @@
template <typename Lexer>
struct example5_tokens : example5_base_tokens<Lexer>
{
+ typedef example5_base_tokens<Lexer> base_type;
typedef typename Lexer::token_set token_set;
-
- template <typename Self>
- void def (Self& self)
+
+ example5_tokens()
{
// define the additional token to match
else_ = "else";
-
+
// associate the new token with the lexer, note we add 'else' before
// anything else to add it to the token set before the identifier
// token, otherwise "else" would be matched as an identifier
- self = else_;
-
- // call the base class definition function
- example5_base_tokens<Lexer>::def(self);
+ this->self = else_;
+
+ // now add the token definitions from the base class
+ this->base_type::init_token_definitions();
}
-
+
// this token has no value
token_def<omitted> else_;
};
@@ -213,10 +212,10 @@
{
// iterator type used to expose the underlying input stream
typedef std::string::iterator base_iterator_type;
-
+
// This is the lexer token type to use. The second template parameter lists
// all attribute types used for token_def's during token definition (see
- // calculator_tokens<> above). Here we use the predefined lexertl token
+ // example5_base_tokens<> above). Here we use the predefined lexertl token
// type, but any compatible token type may be used instead.
//
// If you don't list any token value types in the following declaration
@@ -227,36 +226,34 @@
// least one token value type you'll have to list all value types used
// for token_def<> declarations in the token definition class above,
// otherwise compilation errors will occur.
- typedef lexertl_token<
+ typedef lexertl::token<
base_iterator_type, boost::mpl::vector<unsigned int, std::string>
> token_type;
-
+
// Here we use the lexertl based lexer engine.
- typedef lexertl_lexer<token_type> lexer_type;
-
+ typedef lexertl::lexer<token_type> lexer_type;
+
// This is the token definition type (derived from the given lexer type).
typedef example5_tokens<lexer_type> example5_tokens;
-
+
// this is the iterator type exposed by the lexer
- typedef lexer<example5_tokens>::iterator_type iterator_type;
+ typedef example5_tokens::iterator_type iterator_type;
// this is the type of the grammar to parse
typedef example5_grammar<iterator_type, lexer_type> example5_grammar;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- example5_tokens tokens; // Our token definition
- example5_grammar calc(tokens); // Our grammar definition
-
- lexer<example5_tokens> lex(tokens); // Our lexer
+ example5_tokens tokens; // Our lexer
+ example5_grammar calc(tokens); // Our parser
std::string str (read_from_file("example5.input"));
// At this point we generate the iterator pair used to expose the
// tokenized input stream.
std::string::iterator it = str.begin();
- iterator_type iter = lex.begin(it, str.end());
- iterator_type end = lex.end();
+ iterator_type iter = tokens.begin(it, str.end());
+ iterator_type end = tokens.end();
// Parsing is done based on the the token stream, not the character
// stream read from the input.
Modified: trunk/libs/spirit/example/lex/example6.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/example6.cpp (original)
+++ trunk/libs/spirit/example/lex/example6.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,4 @@
// Copyright (c) 2001-2009 Hartmut Kaiser
-// Copyright (c) 2001-2007 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)
@@ -40,7 +39,6 @@
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
-using namespace boost::spirit::arg_names;
using boost::phoenix::val;
@@ -60,27 +58,26 @@
// Token definitions
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct example6_tokens : lexer_def<Lexer>
+struct example6_tokens : lexer<Lexer>
{
typedef typename Lexer::token_set token_set;
-
- template <typename Self>
- void def (Self& self)
+
+ example6_tokens()
{
// define the tokens to match
identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
constant = "[0-9]+";
-
+
// define the whitespace to ignore (spaces, tabs, newlines and C-style
// comments)
white_space
= token_def<>("[ \\t\\n]+")
| "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/"
;
-
+
// associate the tokens and the token set with the lexer
self = token_def<>('(') | ')' | '{' | '}' | '=' | ';';
-
+
// Token definitions can be added by using some special syntactic
// construct as shown below.
// Note, that the token definitions added this way expose the iterator
@@ -92,16 +89,16 @@
("while", ID_WHILE)
(identifier, ID_IDENTIFIER)
;
-
+
// add whitespace tokens to another lexer state (here: "WS")
self("WS") = white_space;
}
-
+
// The following two tokens have an associated value type, identifier
// carries a string (the identifier name) and constant carries the matched
// integer value.
//
- // Note: any explicitly token value type specified during a token_def<>
+ // Note: any token attribute type explicitly specified in a token_def<>
// declaration needs to be listed during token type definition as
// well (see the typedef for the token_type below).
//
@@ -109,7 +106,7 @@
// once (on first access), which makes token values as efficient as
// possible. Moreover, token instances are constructed once by the lexer
// library. From this point on tokens are passed by reference only,
- // avoiding tokens being copied around.
+ // avoiding them being copied around.
token_def<std::string> identifier;
token_def<unsigned int> constant;
@@ -179,11 +176,11 @@
typedef typename Lexer::token_set token_set;
typedef boost::variant<unsigned int, std::string> expression_type;
-
+
rule<Iterator, in_state_skipper<token_set> > program, block, statement;
rule<Iterator, in_state_skipper<token_set> > assignment, if_stmt;
rule<Iterator, in_state_skipper<token_set> > while_stmt;
-
+
// the expression is the only rule having a return value
rule<Iterator, expression_type(), in_state_skipper<token_set> > expression;
};
@@ -193,7 +190,7 @@
{
// iterator type used to expose the underlying input stream
typedef std::string::iterator base_iterator_type;
-
+
// This is the lexer token type to use. The second template parameter lists
// all attribute types used for token_def's during token definition (see
// calculator_tokens<> above). Here we use the predefined lexertl token
@@ -207,37 +204,35 @@
// least one token value type you'll have to list all value types used
// for token_def<> declarations in the token definition class above,
// otherwise compilation errors will occur.
- typedef lexertl_token<
+ typedef lexertl::token<
base_iterator_type, boost::mpl::vector<unsigned int, std::string>
> token_type;
-
+
// Here we use the lexertl based lexer engine.
- typedef lexertl_lexer<token_type> lexer_type;
-
+ typedef lexertl::lexer<token_type> lexer_type;
+
// This is the token definition type (derived from the given lexer type).
typedef example6_tokens<lexer_type> example6_tokens;
-
+
// this is the iterator type exposed by the lexer
- typedef lexer<example6_tokens>::iterator_type iterator_type;
+ typedef example6_tokens::iterator_type iterator_type;
// this is the type of the grammar to parse
typedef example6_grammar<iterator_type, lexer_type> example6_grammar;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- example6_tokens tokens; // Our token definition
- example6_grammar calc(tokens); // Our grammar definition
-
- lexer<example6_tokens> lex(tokens); // Our lexer
+ example6_tokens tokens; // Our lexer
+ example6_grammar calc(tokens); // Our parser
std::string str (read_from_file("example6.input"));
// At this point we generate the iterator pair used to expose the
// tokenized input stream.
std::string::iterator it = str.begin();
- iterator_type iter = lex.begin(it, str.end());
- iterator_type end = lex.end();
-
+ iterator_type iter = tokens.begin(it, str.end());
+ iterator_type end = tokens.end();
+
// Parsing is done based on the the token stream, not the character
// stream read from the input.
// Note, how we use the token_def defined above as the skip parser. It must
Modified: trunk/libs/spirit/example/lex/print_numbers.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/print_numbers.cpp (original)
+++ trunk/libs/spirit/example/lex/print_numbers.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -32,20 +32,21 @@
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
-using namespace boost::spirit::arg_names;
///////////////////////////////////////////////////////////////////////////////
// Token definition: We use the lexertl based lexer engine as the underlying
// lexer type.
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct print_numbers_tokens : lexer_def<Lexer>
+struct print_numbers_tokens : lexer<Lexer>
{
- // define tokens and associate it with the lexer
- template <typename Self>
- void def (Self& self)
+ // define tokens and associate it with the lexer, we set the lexer flags
+ // not to match newlines while matching a dot, so we need to add the
+ // '\n' explicitly below
+ print_numbers_tokens()
+ : print_numbers_tokens::base_type(match_flags::match_not_dot_newline)
{
- self = token_def<int>("[0-9]*") | ".|\n";
+ this->self = token_def<int>("[0-9]*") | ".|\n";
}
};
@@ -56,8 +57,11 @@
struct print_numbers_grammar : grammar<Iterator>
{
print_numbers_grammar()
- : grammar<Iterator>(start)
+ : print_numbers_grammar::base_type(start)
{
+ // we just know, that the token ids get assigned starting min_token_id
+ // so, "[0-9]*" gets the id 'min_token_id' and ".|\n" gets the id
+ // 'min_token_id+1'.
start = *( token(lex::min_token_id) [ std::cout << _1 << "\n" ]
| token(lex::min_token_id+1)
)
@@ -75,29 +79,25 @@
// the token type to be used, 'int' is available as the type of the token
// value and no lexer state is supported
- typedef lexertl_token<
- base_iterator_type, boost::mpl::vector<int>, boost::mpl::false_
- > token_type;
-
+ typedef lexertl::token<base_iterator_type, boost::mpl::vector<int>
+ , boost::mpl::false_> token_type;
+
// lexer type
- typedef lexertl_lexer<token_type> lexer_type;
-
+ typedef lexertl::lexer<token_type> lexer_type;
+
// iterator type exposed by the lexer
- typedef
- lexer_iterator<print_numbers_tokens<lexer_type> >::type
- iterator_type;
+ typedef print_numbers_tokens<lexer_type>::iterator_type iterator_type;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- print_numbers_tokens<lexer_type> print_tokens; // Our token definition
- print_numbers_grammar<iterator_type> print; // Our grammar definition
+ print_numbers_tokens<lexer_type> print_tokens; // Our lexer
+ print_numbers_grammar<iterator_type> print; // Our parser
// Parsing is done based on the the token stream, not the character
// stream read from the input.
std::string str (read_from_file(1 == argc ? "print_numbers.input" : argv[1]));
base_iterator_type first = str.begin();
- bool r = tokenize_and_parse(first, str.end(), make_lexer(print_tokens),
- print);
+ bool r = tokenize_and_parse(first, str.end(), print_tokens, print);
if (r) {
std::cout << "-------------------------\n";
Modified: trunk/libs/spirit/example/lex/static_lexer/Jamfile
==============================================================================
--- trunk/libs/spirit/example/lex/static_lexer/Jamfile (original)
+++ trunk/libs/spirit/example/lex/static_lexer/Jamfile 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,5 @@
#==============================================================================
-# Copyright (c) 2001-2007 Joel de Guzman
-# Copyright (c) 2001-2008 Hartmut Kaiser
+# Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/lex/static_lexer/word_count_generate.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/static_lexer/word_count_generate.cpp (original)
+++ trunk/libs/spirit/example/lex/static_lexer/word_count_generate.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -14,8 +14,8 @@
// #define BOOST_SPIRIT_LEXERTL_DEBUG
#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
-#include <boost/spirit/home/lex/lexer/lexertl/lexertl_generate_static.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
+#include <boost/spirit/home/lex/lexer/lexertl/generate_static.hpp>
#include <fstream>
@@ -29,7 +29,7 @@
int main(int argc, char* argv[])
{
// create the lexer object instance needed to invoke the generator
- word_count_tokens<lexertl_lexer<> > word_count; // the token definition
+ word_count_tokens<lexertl::lexer<> > word_count; // the token definition
// open the output file, where the generated tokenizer function will be
// written to
@@ -38,6 +38,6 @@
// invoke the generator, passing the token definition, the output stream
// and the name prefix of the tokenizing function to be generated
char const* function_name = (argc < 3 ? "" : argv[2]);
- return generate_static(make_lexer(word_count), out, function_name) ? 0 : -1;
+ return lexertl::generate_static(word_count, out, function_name) ? 0 : -1;
}
//]
Modified: trunk/libs/spirit/example/lex/static_lexer/word_count_static.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/static_lexer/word_count_static.cpp (original)
+++ trunk/libs/spirit/example/lex/static_lexer/word_count_static.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -17,7 +17,7 @@
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
//[wc_static_include
-#include <boost/spirit/include/lex_lexer_static_lexertl.hpp>
+#include <boost/spirit/include/lex_static_lexertl.hpp>
//]
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
@@ -27,11 +27,12 @@
#include <string>
#include "../example.hpp"
-#include "word_count_tokens.hpp" // token definition
+#include "word_count_tokens.hpp" // token definition
-#include "word_count_static.hpp" // generated tokenizer
+#include "word_count_static.hpp" // generated tokenizer
using namespace boost::spirit;
+using namespace boost::spirit::ascii;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
@@ -48,17 +49,17 @@
{
template <typename TokenDef>
word_count_grammar(TokenDef const& tok)
- : grammar<Iterator>(start), c(0), w(0), l(0)
+ : word_count_grammar::base_type(start)
+ , c(0), w(0), l(0)
{
- using boost::spirit::arg_names::_1;
using boost::phoenix::ref;
using boost::phoenix::size;
-
+
// associate the defined tokens with the lexer, at the same time
// defining the actions to be executed
- start = *( tok.word [++ref(w), ref(c) += size(_1)]
- | char_('\n') [++ref(l), ++ref(c)]
- | token(IDANY) [++ref(c)]
+ start = *( tok.word [ ++ref(w), ref(c) += size(_1) ]
+ | char_('\n') [ ++ref(l), ++ref(c) ]
+ | token(IDANY) [ ++ref(c) ]
)
;
}
@@ -74,7 +75,7 @@
{
// Define the token type to be used: 'std::string' is available as the type
// of the token value.
- typedef lexertl_token<
+ typedef lexertl::token<
char const*, boost::mpl::vector<std::string>
> token_type;
@@ -82,26 +83,25 @@
// definition.
//
// This is the only place where the code is different from an equivalent
- // dynamic lexical analyzer. We use the `lexertl_static_lexer<>` instead of
- // the `lexertl_lexer<>` as the base class for our token defintion type.
- //
- typedef lexertl_static_lexer<token_type> lexer_type;
-
+ // dynamic lexical analyzer. We use the `lexertl::static_lexer<>` instead of
+ // the `lexertl::lexer<>` as the base class for our token defintion type.
+ typedef lexertl::static_lexer<token_type> lexer_type;
+
// Define the iterator type exposed by the lexer.
- typedef lexer_iterator<word_count_tokens<lexer_type> >::type iterator_type;
+ typedef word_count_tokens<lexer_type>::iterator_type iterator_type;
// Now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process.
- word_count_tokens<lexer_type> word_count; // Our token definition
- word_count_grammar<iterator_type> g (word_count); // Our grammar definition
+ word_count_tokens<lexer_type> word_count; // Our lexer
+ word_count_grammar<iterator_type> g (word_count); // Our parser
// Read in the file into memory.
std::string str (read_from_file(1 == argc ? "word_count.input" : argv[1]));
char const* first = str.c_str();
char const* last = &first[str.size()];
-
+
// Parsing is done based on the the token stream, not the character stream.
- bool r = tokenize_and_parse(first, last, make_lexer(word_count), g);
+ bool r = tokenize_and_parse(first, last, word_count, g);
if (r) { // success
std::cout << "lines: " << g.l << ", words: " << g.w
Modified: trunk/libs/spirit/example/lex/static_lexer/word_count_static.hpp
==============================================================================
--- trunk/libs/spirit/example/lex/static_lexer/word_count_static.hpp (original)
+++ trunk/libs/spirit/example/lex/static_lexer/word_count_static.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,18 +1,20 @@
-// Copyright (c) 2008 Ben Hanson
+// Copyright (c) 2008-2009 Ben Hanson
+// Copyright (c) 2008-2009 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
-// Auto-generated by boost::lexer
-#if !defined(BOOST_SPIRIT_LEXER_NEXT_TOKEN_Apr_20_2008_17_34_03)
-#define BOOST_SPIRIT_LEXER_NEXT_TOKEN_Apr_20_2008_17_34_03
+// Auto-generated by boost::lexer, do not edit
+
+#if !defined(BOOST_SPIRIT_LEXER_NEXT_TOKEN_APR_23_2009_12_12_57)
+#define BOOST_SPIRIT_LEXER_NEXT_TOKEN_APR_23_2009_12_12_57
#include <boost/detail/iterator.hpp>
#include <boost/spirit/home/support/detail/lexer/char_traits.hpp>
// the generated table of state names and the tokenizer have to be
// defined in the boost::spirit::lex::static namespace
-namespace boost { namespace spirit { namespace lex { namespace static_ {
+namespace boost { namespace spirit { namespace lex { namespace lexertl { namespace static_ {
// this table defines the names of the lexer states
char const* const lexer_state_names[1] =
@@ -27,43 +29,43 @@
enum {end_state_index, id_index, state_index, bol_index, eol_index,
dead_state_index, dfa_offset};
static const std::size_t npos = static_cast<std::size_t>(~0);
- static const std::size_t lookup_[256] = {8, 8, 8, 8, 8, 8, 8, 8,
- 8, 7, 6, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 7, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8,
- 8, 8, 8, 8, 8, 8, 8, 8};
+ static const std::size_t lookup_[256] = {7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 8, 6, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 8, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7};
static const std::size_t dfa_alphabet_ = 9;
static const std::size_t dfa_[45] = {0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 3,
- 4, 2, 1, 65536, 0, 0, 0, 0,
- 0, 0, 2, 1, 10, 0, 0, 0,
+ 2, 4, 1, 65536, 0, 0, 0, 0,
+ 0, 2, 0, 1, 10, 0, 0, 0,
0, 0, 0, 0, 1, 65537, 0, 0,
0, 0, 0, 0, 0};
@@ -79,7 +81,7 @@
{
std::size_t const state_ =
ptr_[lookup_[static_cast<unsigned char>
- (*curr_++)]];
+ (*curr_++)]];
if (state_ == 0) break;
@@ -106,6 +108,6 @@
return id_;
}
-}}}} // namespace boost::spirit::lex::static_
+}}}}} // namespace boost::spirit::lex::lexertl::static_
#endif
Modified: trunk/libs/spirit/example/lex/static_lexer/word_count_tokens.hpp
==============================================================================
--- trunk/libs/spirit/example/lex/static_lexer/word_count_tokens.hpp (original)
+++ trunk/libs/spirit/example/lex/static_lexer/word_count_tokens.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -23,16 +23,17 @@
// possible use cases: a dynamic lexical analyzer, a code generator, and a
// static lexical analyzer.
template <typename BaseLexer>
-struct word_count_tokens : boost::spirit::lex::lexer_def<BaseLexer>
+struct word_count_tokens : boost::spirit::lex::lexer<BaseLexer>
{
- template <typename Self>
- void def (Self& self)
+ word_count_tokens()
+ : word_count_tokens::base_type(
+ boost::spirit::lex::match_flags::match_not_dot_newline)
{
// define tokens and associate them with the lexer
word = "[^ \t\n]+";
- self = word | '\n' | token_def<>(".", IDANY);
+ this->self = word | '\n' | token_def<>(".", IDANY);
}
-
+
boost::spirit::lex::token_def<std::string> word;
};
//]
Modified: trunk/libs/spirit/example/lex/strip_comments.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/strip_comments.cpp (original)
+++ trunk/libs/spirit/example/lex/strip_comments.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -47,7 +47,6 @@
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
-using namespace boost::spirit::arg_names;
///////////////////////////////////////////////////////////////////////////////
// Token definition: We use the lexertl based lexer engine as the underlying
@@ -59,35 +58,35 @@
};
template <typename Lexer>
-struct strip_comments_tokens : lexer_def<Lexer>
+struct strip_comments_tokens : lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ strip_comments_tokens()
+ : strip_comments_tokens::base_type(match_flags::match_default)
{
// define tokens and associate them with the lexer
cppcomment = "//[^\n]*";
ccomment = "/\\*";
endcomment = "\\*/";
-
+
// The following tokens are associated with the default lexer state
// (the "INITIAL" state). Specifying 'INITIAL' as a lexer state is
// strictly optional.
- self.add
+ this->self.add
(cppcomment) // no explicit token id is associated
(ccomment)
(".", IDANY) // IDANY is the token id associated with this token
// definition
;
-
+
// The following tokens are associated with the lexer state "COMMENT".
// We switch lexer states from inside the parsing process using the
// in_state("COMMENT")[] parser component as shown below.
- self("COMMENT").add
+ this->self("COMMENT").add
(endcomment)
(".", IDANY)
;
}
-
+
token_def<> cppcomment, ccomment, endcomment;
};
@@ -99,7 +98,7 @@
{
template <typename TokenDef>
strip_comments_grammar(TokenDef const& tok)
- : grammar<Iterator>(start)
+ : strip_comments_grammar::base_type(start)
{
// The in_state("COMMENT")[...] parser component switches the lexer
// state to be 'COMMENT' during the matching of the embedded parser.
@@ -124,26 +123,24 @@
{
// iterator type used to expose the underlying input stream
typedef std::string::iterator base_iterator_type;
-
+
// lexer type
- typedef lexertl_lexer<lexertl_token<base_iterator_type> > lexer_type;
-
+ typedef lexertl::lexer<lexertl::token<base_iterator_type> > lexer_type;
+
// iterator type exposed by the lexer
- typedef
- lexer_iterator<strip_comments_tokens<lexer_type> >::type
- iterator_type;
+ typedef strip_comments_tokens<lexer_type>::iterator_type iterator_type;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- strip_comments_tokens<lexer_type> strip_comments; // Our token definition
- strip_comments_grammar<iterator_type> g (strip_comments); // Our grammar definition
+ strip_comments_tokens<lexer_type> strip_comments; // Our lexer
+ strip_comments_grammar<iterator_type> g (strip_comments); // Our parser
// Parsing is done based on the the token stream, not the character
// stream read from the input.
std::string str (read_from_file(1 == argc ? "strip_comments.input" : argv[1]));
base_iterator_type first = str.begin();
- bool r = tokenize_and_parse(first, str.end(), make_lexer(strip_comments), g);
+ bool r = tokenize_and_parse(first, str.end(), strip_comments, g);
if (r) {
std::cout << "-------------------------\n";
Modified: trunk/libs/spirit/example/lex/strip_comments.input
==============================================================================
--- trunk/libs/spirit/example/lex/strip_comments.input (original)
+++ trunk/libs/spirit/example/lex/strip_comments.input 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,4 +1,4 @@
-// Copyright (c) 2001-2007 Hartmut Kaiser
+// Copyright (c) 2001-2009 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)
@@ -27,13 +27,17 @@
// }
//
// Its purpose is to strip comments out of C code.
+//
+// Additionally this example demonstrates the use of lexer states to structure
+// the lexer definition.
// #define BOOST_SPIRIT_LEXERTL_DEBUG
-#include <boost/spirit/qi.hpp>
-#include <boost/spirit/lex/lexer_lexertl.hpp>
-#include <boost/spirit/phoenix/operator.hpp>
-#include <boost/spirit/phoenix/container.hpp>
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_container.hpp>
#include <iostream>
#include <string>
@@ -43,39 +47,45 @@
using namespace boost::spirit;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
-using namespace boost::spirit::arg_names;
///////////////////////////////////////////////////////////////////////////////
// Token definition: We use the lexertl based lexer engine as the underlying
// lexer type.
///////////////////////////////////////////////////////////////////////////////
-enum {
+enum tokenids
+{
IDANY = lex::min_token_id + 10
};
-template <typename BaseIterator>
-struct strip_comments_tokens : lexer_def<lexertl_lexer<BaseIterator> >
+template <typename Lexer>
+struct strip_comments_tokens : lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ strip_comments_tokens()
{
// define tokens and associate them with the lexer
- cppcomment = "//.*\n";
+ cppcomment = "//[^\n]*";
ccomment = "/\\*";
endcomment = "\\*/";
-
- self.add
- (cppcomment)
+
+ // The following tokens are associated with the default lexer state
+ // (the "INITIAL" state). Specifying 'INITIAL' as a lexer state is
+ // strictly optional.
+ this->self.add
+ (cppcomment) // no explicit token id is associated
(ccomment)
- (".", IDANY)
+ (".", IDANY) // IDANY is the token id associated with this token
+ // definition
;
-
- self("COMMENT").add
+
+ // The following tokens are associated with the lexer state "COMMENT".
+ // We switch lexer states from inside the parsing process using the
+ // in_state("COMMENT")[] parser component as shown below.
+ this->self("COMMENT").add
(endcomment)
(".", IDANY)
;
}
-
+
token_def<> cppcomment, ccomment, endcomment;
};
@@ -83,16 +93,23 @@
// Grammar definition
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
-struct strip_comments_grammar : grammar_def<Iterator>
+struct strip_comments_grammar : grammar<Iterator>
{
template <typename TokenDef>
strip_comments_grammar(TokenDef const& tok)
+ : strip_comments_grammar::base_type(start)
{
+ // The in_state("COMMENT")[...] parser component switches the lexer
+ // state to be 'COMMENT' during the matching of the embedded parser.
start = *( tok.ccomment
>> in_state("COMMENT")
- [ *token(IDANY) >> tok.endcomment ]
+ [
+ // the lexer is in the 'COMMENT' state during
+ // matching of the following parser components
+ *token(IDANY) >> tok.endcomment
+ ]
| tok.cppcomment
- | token(IDANY)
+ | token(IDANY) [ std::cout << _1 ]
)
;
}
@@ -104,24 +121,25 @@
int main(int argc, char* argv[])
{
// iterator type used to expose the underlying input stream
- typedef std::string::const_iterator base_iterator_type;
-
+ typedef std::string::iterator base_iterator_type;
+
+ // lexer type
+ typedef lexertl::lexer<lexertl::token<base_iterator_type> > lexer_type;
+
// iterator type exposed by the lexer
- typedef
- lexer_iterator<strip_comments_tokens<base_iterator_type> >::type
- iterator_type;
+ typedef strip_comments_tokens<lexer_type>::iterator_type iterator_type;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- strip_comments_tokens<base_iterator_type> strip_comments; // Our token definition
- strip_comments_grammar<iterator_type> def (strip_comments); // Our grammar definition
+ strip_comments_tokens<lexer_type> strip_comments; // Our lexer
+ strip_comments_grammar<iterator_type> g (strip_comments); // Our grammar
// Parsing is done based on the the token stream, not the character
// stream read from the input.
std::string str (read_from_file(1 == argc ? "strip_comments.input" : argv[1]));
base_iterator_type first = str.begin();
- base_iterator_type end = str.end();
- bool r = lex_and_parse(first, end, strip_comments, make_grammar(def));
+
+ bool r = tokenize_and_parse(first, str.end(), strip_comments, g);
if (r) {
std::cout << "-------------------------\n";
@@ -129,7 +147,7 @@
std::cout << "-------------------------\n";
}
else {
- std::string rest(first, end);
+ std::string rest(first, str.end());
std::cout << "-------------------------\n";
std::cout << "Parsing failed\n";
std::cout << "stopped at: \"" << rest << "\"\n";
Modified: trunk/libs/spirit/example/lex/strip_comments_lexer.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/strip_comments_lexer.cpp (original)
+++ trunk/libs/spirit/example/lex/strip_comments_lexer.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -34,7 +34,7 @@
// #define BOOST_SPIRIT_LEXERTL_DEBUG
#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
@@ -57,11 +57,56 @@
IDEOL = lex::min_token_id + 11
};
+///////////////////////////////////////////////////////////////////////////////
+// Simple custom semantic action function object used to print the matched
+// input sequence for a particular token
+template <typename Char, typename Traits>
+struct echo_input_functor
+{
+ echo_input_functor (std::basic_ostream<Char, Traits>& os_)
+ : os(os_) {}
+
+ // This is called by the semantic action handling code during the lexing
+ template <typename Range, typename LexerContext>
+ void operator()(Range const& r, std::size_t, bool&, LexerContext&) const
+ {
+ os << r;
+ }
+
+ std::basic_ostream<Char, Traits>& os;
+};
+
+template <typename Char, typename Traits>
+inline echo_input_functor<Char, Traits>
+echo_input(std::basic_ostream<Char, Traits>& os)
+{
+ return echo_input_functor<Char, Traits>(os);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Another simple custom semantic action function object used to switch the
+// state of the lexer
+struct set_lexer_state
+{
+ set_lexer_state(char const* state_)
+ : state(state_) {}
+
+ // This is called by the semantic action handling code during the lexing
+ template <typename Range, typename LexerContext>
+ void operator()(Range const&, std::size_t, bool&, LexerContext& ctx) const
+ {
+ ctx.set_state_name(state.c_str());
+ }
+
+ std::string state;
+};
+
+///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct strip_comments_tokens : lexer_def<Lexer>
+struct strip_comments_tokens : lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ strip_comments_tokens()
+ : strip_comments_tokens::base_type(match_flags::match_default)
{
// define tokens and associate them with the lexer
cppcomment = "//[^\n]*";
@@ -69,24 +114,25 @@
endcomment = "\\*/";
any = ".";
eol = "\n";
-
+
// The following tokens are associated with the default lexer state
// (the "INITIAL" state). Specifying 'INITIAL' as a lexer state is
// strictly optional.
- self = cppcomment
- | ccomment [ set_state("COMMENT") ]
+ this->self
+ = cppcomment
+ | ccomment [ set_lexer_state("COMMENT") ]
| eol [ echo_input(std::cout) ]
| any [ echo_input(std::cout) ]
;
-
+
// The following tokens are associated with the lexer state 'COMMENT'.
- self("COMMENT")
- = endcomment [ set_state("INITIAL") ]
+ this->self("COMMENT")
+ = endcomment [ set_lexer_state("INITIAL") ]
| eol
| any
;
}
-
+
token_def<> cppcomment, ccomment, endcomment, any, eol;
};
@@ -95,19 +141,19 @@
{
// iterator type used to expose the underlying input stream
typedef std::string::iterator base_iterator_type;
-
+
// lexer type
- typedef lexertl_actor_lexer<lexertl_token<base_iterator_type> > lexer_type;
-
+ typedef lexertl::actor_lexer<lexertl::token<base_iterator_type> > lexer_type;
+
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- strip_comments_tokens<lexer_type> strip_comments; // Our token definition
+ strip_comments_tokens<lexer_type> strip_comments; // Our lexer
- // Parsing is done based on the the token stream, not the character
- // stream read from the input.
+ // No parsing is done alltogether, everzthing happens in the lexer semantic
+ // actions.
std::string str (read_from_file(1 == argc ? "strip_comments.input" : argv[1]));
base_iterator_type first = str.begin();
- bool r = tokenize(first, str.end(), make_lexer(strip_comments));
+ bool r = tokenize(first, str.end(), strip_comments);
if (!r) {
std::string rest(first, str.end());
Modified: trunk/libs/spirit/example/lex/word_count.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/word_count.cpp (original)
+++ trunk/libs/spirit/example/lex/word_count.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -37,7 +37,7 @@
#include <boost/config/warning_disable.hpp>
//[wcp_includes
#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <boost/spirit/include/phoenix_container.hpp>
@@ -50,6 +50,7 @@
//[wcp_namespaces
using namespace boost::spirit;
+using namespace boost::spirit::ascii;
using namespace boost::spirit::qi;
using namespace boost::spirit::lex;
//]
@@ -67,29 +68,29 @@
//[wcp_token_definition
template <typename Lexer>
-struct word_count_tokens : lexer_def<Lexer>
+struct word_count_tokens : lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ word_count_tokens()
{
// define patterns (lexer macros) to be used during token definition
// below
- self.add_pattern
+ this->self.add_pattern
("WORD", "[^ \t\n]+")
;
-
+
// define tokens and associate them with the lexer
word = "{WORD}"; // reference the pattern 'WORD' as defined above
// this lexer will recognize 3 token types: words, newlines, and
// everything else
- self.add
+ this->self.add
(word) // no token id is needed here
('\n') // characters are usable as tokens as well
- (".", IDANY)
+ (".", IDANY) // string literals will not be esacped by the library
;
}
-
+
+ // the token 'word' exposes the matched string as its parser attribute
token_def<std::string> word;
};
//]
@@ -103,16 +104,11 @@
{
template <typename TokenDef>
word_count_grammar(TokenDef const& tok)
- : grammar<Iterator>(start), c(0), w(0), l(0)
+ : word_count_grammar::base_type(start)
+ , c(0), w(0), l(0)
{
using boost::phoenix::ref;
using boost::phoenix::size;
-
- // As documented in the Spirit.Qi documentation, any placeholders
- // (_1 et.al.) used in semantic actions inside a grammar need to be
- // imported from the namespace boost::spirit::arg_names, and not from
- // the corresponding namespace in Phoenix.
- using boost::spirit::arg_names::_1;
start = *( tok.word [++ref(w), ref(c) += size(_1)]
| char_('\n') [++ref(c), ++ref(l)]
@@ -132,20 +128,20 @@
{
/*< define the token type to be used: `std::string` is available as the
type of the token value
->*/ typedef lexertl_token<
+>*/ typedef lexertl::token<
char const*, boost::mpl::vector<std::string>
> token_type;
/*< define the lexer type to use implementing the state machine
->*/ typedef lexertl_lexer<token_type> lexer_type;
+>*/ typedef lexertl::lexer<token_type> lexer_type;
/*< define the iterator type exposed by the lexer type
->*/ typedef lexer_iterator<word_count_tokens<lexer_type> >::type iterator_type;
+>*/ typedef word_count_tokens<lexer_type>::iterator_type iterator_type;
// now we use the types defined above to create the lexer and grammar
// object instances needed to invoke the parsing process
- word_count_tokens<lexer_type> word_count; // Our token definition
- word_count_grammar<iterator_type> g (word_count); // Our grammar definition
+ word_count_tokens<lexer_type> word_count; // Our lexer
+ word_count_grammar<iterator_type> g (word_count); // Our parser
// read in the file int memory
std::string str (read_from_file(1 == argc ? "word_count.input" : argv[1]));
@@ -156,7 +152,7 @@
// stream read from the input. The function `tokenize_and_parse()` wraps
// the passed iterator range `[first, last)` by the lexical analyzer and
// uses its exposed iterators to parse the toke stream.
- bool r = tokenize_and_parse(first, last, make_lexer(word_count), g);
+ bool r = tokenize_and_parse(first, last, word_count, g);
if (r) {
std::cout << "lines: " << g.l << ", words: " << g.w
Modified: trunk/libs/spirit/example/lex/word_count_functor.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/word_count_functor.cpp (original)
+++ trunk/libs/spirit/example/lex/word_count_functor.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -51,7 +51,7 @@
#include <boost/config/warning_disable.hpp>
//[wcf_includes
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/bind.hpp>
#include <boost/ref.hpp>
//]
@@ -62,7 +62,6 @@
#include "example.hpp"
//[wcf_namespaces
-using namespace boost::spirit;
using namespace boost::spirit::lex;
//]
@@ -91,14 +90,13 @@
example we use the Lexertl based lexer engine as the underlying lexer type.
*/
template <typename Lexer>
-struct word_count_tokens : lexer_def<Lexer>
+struct word_count_tokens : lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ word_count_tokens()
{
// define tokens (the regular expression to match and the corresponding
// token id) and add them to the lexer
- self.add
+ this->self.add
("[^ \t\n]+", ID_WORD) // words (anything except ' ', '\t' or '\n')
("\n", ID_EOL) // newline characters
(".", ID_CHAR) // anything else is a plain character
@@ -114,9 +112,9 @@
*/
struct counter
{
-//<- this is an implementation detail and doesn't show up in the documentation
+//<- this is an implementation detail specific to boost::bind and doesn't show
+// up in the documentation
typedef bool result_type;
-
//->
// the function operator gets called for each of the matched tokens
// c, l, w are references to the counters used to keep track of the numbers
@@ -160,13 +158,13 @@
std::string str (read_from_file(1 == argc ? "word_count.input" : argv[1]));
// create the token definition instance needed to invoke the lexical analyzer
- word_count_tokens<lexertl_lexer<> > word_count_functor;
+ word_count_tokens<lexertl::lexer<> > word_count_functor;
// tokenize the given string, the bound functor gets invoked for each of
// the matched tokens
char const* first = str.c_str();
char const* last = &first[str.size()];
- bool r = lex::tokenize(first, last, make_lexer(word_count_functor),
+ bool r = tokenize(first, last, word_count_functor,
boost::bind(counter(), _1, boost::ref(c), boost::ref(w), boost::ref(l)));
// print results
Modified: trunk/libs/spirit/example/lex/word_count_lexer.cpp
==============================================================================
--- trunk/libs/spirit/example/lex/word_count_lexer.cpp (original)
+++ trunk/libs/spirit/example/lex/word_count_lexer.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -34,8 +34,7 @@
#include <boost/config/warning_disable.hpp>
//[wcl_includes
-#include <boost/spirit/include/support_argument.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
#include <boost/spirit/include/phoenix_algorithm.hpp>
@@ -61,27 +60,25 @@
///////////////////////////////////////////////////////////////////////////////
//[wcl_token_definition
template <typename Lexer>
-struct word_count_tokens : lexer_def<Lexer>
+struct word_count_tokens : lexer<Lexer>
{
word_count_tokens()
- : c(0), w(0), l(0),
- word("[^ \t\n]+"), eol("\n"), any(".") // define tokens
- {}
-
- template <typename Self>
- void def (Self& self)
+ : c(0), w(0), l(0)
+ , word("[^ \t\n]+") // define tokens
+ , eol("\n")
+ , any(".")
{
using boost::phoenix::ref;
using boost::phoenix::distance;
- using boost::spirit::arg_names::_1;
// associate tokens with the lexer
- self = word [++ref(w), ref(c) += distance(_1)]
+ this->self
+ = word [++ref(w), ref(c) += distance(_1)]
| eol [++ref(c), ++ref(l)]
| any [++ref(c)]
;
}
-
+
std::size_t c, w, l;
token_def<> word, eol, any;
};
@@ -105,18 +102,18 @@
//
// As a result the token instances contain the token ids as the only data
// member.
- typedef lexertl_token<char const*, omitted, boost::mpl::false_> token_type;
+ typedef lexertl::token<char const*, omitted, boost::mpl::false_> token_type;
// lexer type
- typedef lexertl_actor_lexer<token_type> lexer_type;
-
+ typedef lexertl::actor_lexer<token_type> lexer_type;
+
// create the lexer object instance needed to invoke the lexical analysis
word_count_tokens<lexer_type> word_count_lexer;
// tokenize the given string, all generated tokens are discarded
char const* first = str.c_str();
char const* last = &first[str.size()];
- bool r = tokenize(first, last, make_lexer(word_count_lexer));
+ bool r = tokenize(first, last, word_count_lexer);
if (r) {
std::cout << "lines: " << word_count_lexer.l
Modified: trunk/libs/spirit/example/qi/Jamfile
==============================================================================
--- trunk/libs/spirit/example/qi/Jamfile (original)
+++ trunk/libs/spirit/example/qi/Jamfile 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -5,7 +5,7 @@
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#==============================================================================
project spirit-qi-example
- : requirements <toolset>gcc:<cxxflags>-ftemplate-depth-300
+ : requirements <toolset>gcc:<c++-template-depth>300
:
:
;
@@ -17,6 +17,7 @@
exe roman : roman.cpp ;
exe mini_xml1 : mini_xml1.cpp ;
exe mini_xml2 : mini_xml2.cpp ;
+exe mini_xml3 : mini_xml3.cpp ;
exe num_list1 : num_list1.cpp ;
exe num_list2 : num_list2.cpp ;
exe num_list3 : num_list3.cpp ;
@@ -26,8 +27,9 @@
exe calc2 : calc2.cpp ;
exe calc2_ast : calc2_ast.cpp ;
exe calc3 : calc3.cpp ;
-exe calc3_lexer : calc3_lexer.cpp ;
+#exe calc3_lexer : calc3_lexer.cpp ;
exe calc4 : calc4.cpp ;
+exe calc4_debug : calc4_debug.cpp ;
exe calc5 : calc5.cpp ;
exe calc6 :
Modified: trunk/libs/spirit/example/qi/actions.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/actions.cpp (original)
+++ trunk/libs/spirit/example/qi/actions.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,10 +1,9 @@
/*=============================================================================
- Copyright (c) 2001-2008 Joel de Guzman
+ Copyright (c) 2001-2009 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)
=============================================================================*/
-
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/lambda/lambda.hpp>
@@ -19,41 +18,50 @@
// * Using boost.bind with a member function
// * Using boost.lambda
-using namespace boost::spirit;
-
//[tutorial_semantic_action_functions
-// A plain function
-void write(int const& i)
+namespace client
{
- std::cout << i << std::endl;
-}
+ namespace qi = boost::spirit::qi;
-// A member function
-struct writer
-{
- void print(int const& i) const
+ // A plain function
+ void print(int const& i)
{
std::cout << i << std::endl;
}
-};
-// A function object
-struct write_action
-{
- void operator()(int const& i, unused_type, unused_type) const
+ // A member function
+ struct writer
{
- std::cout << i << std::endl;
- }
-};
+ void print(int const& i) const
+ {
+ std::cout << i << std::endl;
+ }
+ };
+
+ // A function object
+ struct print_action
+ {
+ void operator()(int const& i, qi::unused_type, qi::unused_type) const
+ {
+ std::cout << i << std::endl;
+ }
+ };
+}
//]
int main()
{
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::parse;
+ using client::print;
+ using client::writer;
+ using client::print_action;
+
{ // example using plain function
char const *first = "{42}", *last = first + std::strlen(first);
//[tutorial_attach_actions1
- qi::parse(first, last, '{' >> int_[&write] >> '}');
+ parse(first, last, '{' >> int_[&print] >> '}');
//]
}
@@ -61,7 +69,7 @@
char const *first = "{43}", *last = first + std::strlen(first);
//[tutorial_attach_actions2
- qi::parse(first, last, '{' >> int_[write_action()] >> '}');
+ parse(first, last, '{' >> int_[print_action()] >> '}');
//]
}
@@ -69,7 +77,7 @@
char const *first = "{44}", *last = first + std::strlen(first);
//[tutorial_attach_actions3
- qi::parse(first, last, '{' >> int_[boost::bind(&write, _1)] >> '}');
+ parse(first, last, '{' >> int_[boost::bind(&print, _1)] >> '}');
//]
}
@@ -78,7 +86,7 @@
char const *first = "{44}", *last = first + std::strlen(first);
//[tutorial_attach_actions4
writer w;
- qi::parse(first, last, '{' >> int_[boost::bind(&writer::print, &w, _1)] >> '}');
+ parse(first, last, '{' >> int_[boost::bind(&writer::print, &w, _1)] >> '}');
//]
}
@@ -88,7 +96,7 @@
char const *first = "{45}", *last = first + std::strlen(first);
using lambda::_1;
//[tutorial_attach_actions5
- qi::parse(first, last, '{' >> int_[std::cout << _1 << '\n'] >> '}');
+ parse(first, last, '{' >> int_[std::cout << _1 << '\n'] >> '}');
//]
}
Modified: trunk/libs/spirit/example/qi/calc1.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc1.cpp (original)
+++ trunk/libs/spirit/example/qi/calc1.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -19,42 +19,46 @@
#include <iostream>
#include <string>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator grammar
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : grammar<Iterator, space_type>
+namespace client
{
- calculator() : calculator::base_type(expression)
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our calculator grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct calculator : qi::grammar<Iterator, ascii::space_type>
{
- expression =
- term
- >> *( ('+' >> term)
- | ('-' >> term)
- )
- ;
-
- term =
- factor
- >> *( ('*' >> factor)
- | ('/' >> factor)
- )
- ;
-
- factor =
- uint_
- | '(' >> expression >> ')'
- | ('-' >> factor)
- | ('+' >> factor)
- ;
- }
+ calculator() : calculator::base_type(expression)
+ {
+ using qi::uint_;
+
+ expression =
+ term
+ >> *( ('+' >> term)
+ | ('-' >> term)
+ )
+ ;
+
+ term =
+ factor
+ >> *( ('*' >> factor)
+ | ('/' >> factor)
+ )
+ ;
+
+ factor =
+ uint_
+ | '(' >> expression >> ')'
+ | ('-' >> factor)
+ | ('+' >> factor)
+ ;
+ }
- rule<Iterator, space_type> expression, term, factor;
-};
+ qi::rule<Iterator, ascii::space_type> expression, term, factor;
+ };
+}
///////////////////////////////////////////////////////////////////////////////
// Main program
@@ -67,8 +71,9 @@
std::cout << "/////////////////////////////////////////////////////////\n\n";
std::cout << "Type an expression...or [q or Q] to quit\n\n";
+ using boost::spirit::ascii::space;
typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
+ typedef client::calculator<iterator_type> calculator;
calculator calc; // Our grammar
Modified: trunk/libs/spirit/example/qi/calc2.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc2.cpp (original)
+++ trunk/libs/spirit/example/qi/calc2.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -21,55 +21,59 @@
#include <iostream>
#include <string>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-
-///////////////////////////////////////////////////////////////////////////////
-// Semantic actions
-///////////////////////////////////////////////////////////////////////////////
-namespace
+namespace client
{
- void do_int(int n) { std::cout << "push " << n << std::endl; }
- void do_add() { std::cout << "add\n"; }
- void do_subt() { std::cout << "subtract\n"; }
- void do_mult() { std::cout << "mult\n"; }
- void do_div() { std::cout << "divide\n"; }
- void do_neg() { std::cout << "negate\n"; }
-}
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator grammar
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : grammar<Iterator, space_type>
-{
- calculator() : calculator::base_type(expression)
+ ///////////////////////////////////////////////////////////////////////////////
+ // Semantic actions
+ ///////////////////////////////////////////////////////////////////////////////
+ namespace
{
- expression =
- term
- >> *( ('+' >> term [&do_add])
- | ('-' >> term [&do_subt])
- )
- ;
-
- term =
- factor
- >> *( ('*' >> factor [&do_mult])
- | ('/' >> factor [&do_div])
- )
- ;
-
- factor =
- uint_ [&do_int]
- | '(' >> expression >> ')'
- | ('-' >> factor [&do_neg])
- | ('+' >> factor)
- ;
+ void do_int(int n) { std::cout << "push " << n << std::endl; }
+ void do_add() { std::cout << "add\n"; }
+ void do_subt() { std::cout << "subtract\n"; }
+ void do_mult() { std::cout << "mult\n"; }
+ void do_div() { std::cout << "divide\n"; }
+ void do_neg() { std::cout << "negate\n"; }
}
- rule<Iterator, space_type> expression, term, factor;
-};
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our calculator grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct calculator : qi::grammar<Iterator, ascii::space_type>
+ {
+ calculator() : calculator::base_type(expression)
+ {
+ using qi::uint_;
+
+ expression =
+ term
+ >> *( ('+' >> term [&do_add])
+ | ('-' >> term [&do_subt])
+ )
+ ;
+
+ term =
+ factor
+ >> *( ('*' >> factor [&do_mult])
+ | ('/' >> factor [&do_div])
+ )
+ ;
+
+ factor =
+ uint_ [&do_int]
+ | '(' >> expression >> ')'
+ | ('-' >> factor [&do_neg])
+ | ('+' >> factor)
+ ;
+ }
+
+ qi::rule<Iterator, ascii::space_type> expression, term, factor;
+ };
+}
///////////////////////////////////////////////////////////////////////////////
// Main program
@@ -82,8 +86,9 @@
std::cout << "/////////////////////////////////////////////////////////\n\n";
std::cout << "Type an expression...or [q or Q] to quit\n\n";
+ using boost::spirit::ascii::space;
typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
+ typedef client::calculator<iterator_type> calculator;
calculator calc; // Our grammar
Modified: trunk/libs/spirit/example/qi/calc2_ast.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc2_ast.cpp (original)
+++ trunk/libs/spirit/example/qi/calc2_ast.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -8,13 +8,14 @@
//
// A Calculator example demonstrating generation of AST
//
-// [ JDG April 28, 2002 ]
+// [ JDG April 28, 2008 ]
//
///////////////////////////////////////////////////////////////////////////////
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/variant/recursive_variant.hpp>
+#include <boost/variant/apply_visitor.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_function.hpp>
@@ -22,142 +23,180 @@
#include <vector>
#include <string>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our AST
-///////////////////////////////////////////////////////////////////////////////
-struct binary_op;
-struct unary_op;
-struct nil {};
-
-struct expression_ast
+namespace client
{
- typedef
- boost::variant<
- nil // can't happen!
- , unsigned int
- , boost::recursive_wrapper<expression_ast>
- , boost::recursive_wrapper<binary_op>
- , boost::recursive_wrapper<unary_op>
- >
- type;
-
- expression_ast()
- : expr(nil()) {}
-
- template <typename Expr>
- expression_ast(Expr const& expr)
- : expr(expr) {}
-
- expression_ast& operator+=(expression_ast const& rhs);
- expression_ast& operator-=(expression_ast const& rhs);
- expression_ast& operator*=(expression_ast const& rhs);
- expression_ast& operator/=(expression_ast const& rhs);
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
- type expr;
-};
+ ///////////////////////////////////////////////////////////////////////////
+ // Our AST
+ ///////////////////////////////////////////////////////////////////////////
+ struct binary_op;
+ struct unary_op;
+ struct nil {};
-struct binary_op
-{
- binary_op(
- char op
- , expression_ast const& left
- , expression_ast const& right)
- : op(op), left(left), right(right) {}
-
- char op;
- expression_ast left;
- expression_ast right;
-};
+ struct expression_ast
+ {
+ typedef
+ boost::variant<
+ nil // can't happen!
+ , unsigned int
+ , boost::recursive_wrapper<expression_ast>
+ , boost::recursive_wrapper<binary_op>
+ , boost::recursive_wrapper<unary_op>
+ >
+ type;
+
+ expression_ast()
+ : expr(nil()) {}
+
+ template <typename Expr>
+ expression_ast(Expr const& expr)
+ : expr(expr) {}
+
+ expression_ast& operator+=(expression_ast const& rhs);
+ expression_ast& operator-=(expression_ast const& rhs);
+ expression_ast& operator*=(expression_ast const& rhs);
+ expression_ast& operator/=(expression_ast const& rhs);
-struct unary_op
-{
- unary_op(
- char op
- , expression_ast const& subject)
- : op(op), subject(subject) {}
-
- char op;
- expression_ast subject;
-};
+ type expr;
+ };
-expression_ast& expression_ast::operator+=(expression_ast const& rhs)
-{
- expr = binary_op('+', expr, rhs);
- return *this;
-}
+ struct binary_op
+ {
+ binary_op(
+ char op
+ , expression_ast const& left
+ , expression_ast const& right)
+ : op(op), left(left), right(right) {}
+
+ char op;
+ expression_ast left;
+ expression_ast right;
+ };
-expression_ast& expression_ast::operator-=(expression_ast const& rhs)
-{
- expr = binary_op('-', expr, rhs);
- return *this;
-}
+ struct unary_op
+ {
+ unary_op(
+ char op
+ , expression_ast const& subject)
+ : op(op), subject(subject) {}
+
+ char op;
+ expression_ast subject;
+ };
-expression_ast& expression_ast::operator*=(expression_ast const& rhs)
-{
- expr = binary_op('*', expr, rhs);
- return *this;
-}
+ expression_ast& expression_ast::operator+=(expression_ast const& rhs)
+ {
+ expr = binary_op('+', expr, rhs);
+ return *this;
+ }
-expression_ast& expression_ast::operator/=(expression_ast const& rhs)
-{
- expr = binary_op('/', expr, rhs);
- return *this;
-}
+ expression_ast& expression_ast::operator-=(expression_ast const& rhs)
+ {
+ expr = binary_op('-', expr, rhs);
+ return *this;
+ }
-// We should be using expression_ast::operator-. There's a bug
-// in phoenix type deduction mechanism that prevents us from
-// doing so. Phoenix will be switching to BOOST_TYPEOF. In the
-// meantime, we will use a phoenix::function below:
-struct negate_expr
-{
- template <typename T>
- struct result { typedef T type; };
+ expression_ast& expression_ast::operator*=(expression_ast const& rhs)
+ {
+ expr = binary_op('*', expr, rhs);
+ return *this;
+ }
- expression_ast operator()(expression_ast const& expr) const
+ expression_ast& expression_ast::operator/=(expression_ast const& rhs)
{
- return expression_ast(unary_op('-', expr));
+ expr = binary_op('/', expr, rhs);
+ return *this;
}
-};
-boost::phoenix::function<negate_expr> neg;
+ // We should be using expression_ast::operator-. There's a bug
+ // in phoenix type deduction mechanism that prevents us from
+ // doing so. Phoenix will be switching to BOOST_TYPEOF. In the
+ // meantime, we will use a phoenix::function below:
+ struct negate_expr
+ {
+ template <typename T>
+ struct result { typedef T type; };
+
+ expression_ast operator()(expression_ast const& expr) const
+ {
+ return expression_ast(unary_op('-', expr));
+ }
+ };
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator grammar
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : grammar<Iterator, expression_ast(), space_type>
-{
- calculator() : calculator::base_type(expression)
+ boost::phoenix::function<negate_expr> neg;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Walk the tree
+ ///////////////////////////////////////////////////////////////////////////
+ struct ast_print
{
- expression =
- term [_val = _1]
- >> *( ('+' >> term [_val += _1])
- | ('-' >> term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' >> factor [_val *= _1])
- | ('/' >> factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' >> expression [_val = _1] >> ')'
- | ('-' >> factor [_val = neg(_1)])
- | ('+' >> factor [_val = _1])
- ;
- }
+ typedef void result_type;
+
+ void operator()(qi::info::nil) const {}
+ void operator()(int n) const { std::cout << n; }
- rule<Iterator, expression_ast(), space_type> expression, term, factor;
-};
+ void operator()(expression_ast const& ast) const
+ {
+ boost::apply_visitor(*this, ast.expr);
+ }
+
+ void operator()(binary_op const& expr) const
+ {
+ std::cout << "op:" << expr.op << "(";
+ boost::apply_visitor(*this, expr.left.expr);
+ std::cout << ", ";
+ boost::apply_visitor(*this, expr.right.expr);
+ std::cout << ')';
+ }
+
+ void operator()(unary_op const& expr) const
+ {
+ std::cout << "op:" << expr.op << "(";
+ boost::apply_visitor(*this, expr.subject.expr);
+ std::cout << ')';
+ }
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our calculator grammar
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct calculator : qi::grammar<Iterator, expression_ast(), ascii::space_type>
+ {
+ calculator() : calculator::base_type(expression)
+ {
+ using qi::_val;
+ using qi::_1;
+ using qi::uint_;
+
+ expression =
+ term [_val = _1]
+ >> *( ('+' >> term [_val += _1])
+ | ('-' >> term [_val -= _1])
+ )
+ ;
+
+ term =
+ factor [_val = _1]
+ >> *( ('*' >> factor [_val *= _1])
+ | ('/' >> factor [_val /= _1])
+ )
+ ;
+
+ factor =
+ uint_ [_val = _1]
+ | '(' >> expression [_val = _1] >> ')'
+ | ('-' >> factor [_val = neg(_1)])
+ | ('+' >> factor [_val = _1])
+ ;
+ }
+
+ qi::rule<Iterator, expression_ast(), ascii::space_type>
+ expression, term, factor;
+ };
+}
///////////////////////////////////////////////////////////////////////////////
// Main program
@@ -170,8 +209,12 @@
std::cout << "/////////////////////////////////////////////////////////\n\n";
std::cout << "Type an expression...or [q or Q] to quit\n\n";
+ using boost::spirit::ascii::space;
+ using client::expression_ast;
+ using client::ast_print;
+
typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
+ typedef client::calculator<iterator_type> calculator;
calculator calc; // Our grammar
@@ -183,13 +226,16 @@
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, space);
+ expression_ast ast;
+ ast_print printer;
+ bool r = phrase_parse(iter, end, calc, space, ast);
if (r && iter == end)
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
- std::cout << "-------------------------\n";
+ printer(ast);
+ std::cout << "\n-------------------------\n";
}
else
{
Modified: trunk/libs/spirit/example/qi/calc3.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc3.cpp (original)
+++ trunk/libs/spirit/example/qi/calc3.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -22,43 +22,48 @@
#include <iostream>
#include <string>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator grammar
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : grammar<Iterator, int(), space_type>
+namespace client
{
- calculator() : calculator::base_type(expression)
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our calculator grammar
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct calculator : qi::grammar<Iterator, int(), ascii::space_type>
{
- expression =
- term [_val = _1]
- >> *( ('+' >> term [_val += _1])
- | ('-' >> term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' >> factor [_val *= _1])
- | ('/' >> factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' >> expression [_val = _1] >> ')'
- | ('-' >> factor [_val = -_1])
- | ('+' >> factor [_val = _1])
- ;
- }
+ calculator() : calculator::base_type(expression)
+ {
+ using qi::_val;
+ using qi::_1;
+ using qi::uint_;
+
+ expression =
+ term [_val = _1]
+ >> *( ('+' >> term [_val += _1])
+ | ('-' >> term [_val -= _1])
+ )
+ ;
+
+ term =
+ factor [_val = _1]
+ >> *( ('*' >> factor [_val *= _1])
+ | ('/' >> factor [_val /= _1])
+ )
+ ;
+
+ factor =
+ uint_ [_val = _1]
+ | '(' >> expression [_val = _1] >> ')'
+ | ('-' >> factor [_val = -_1])
+ | ('+' >> factor [_val = _1])
+ ;
+ }
- rule<Iterator, int(), space_type> expression, term, factor;
-};
+ qi::rule<Iterator, int(), ascii::space_type> expression, term, factor;
+ };
+}
///////////////////////////////////////////////////////////////////////////////
// Main program
@@ -71,8 +76,9 @@
std::cout << "/////////////////////////////////////////////////////////\n\n";
std::cout << "Type an expression...or [q or Q] to quit\n\n";
+ using boost::spirit::ascii::space;
typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
+ typedef client::calculator<iterator_type> calculator;
calculator calc; // Our grammar
@@ -85,7 +91,7 @@
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, result, space);
+ bool r = phrase_parse(iter, end, calc, space, result);
if (r && iter == end)
{
Deleted: trunk/libs/spirit/example/qi/calc3_lexer.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc3_lexer.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,203 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
- Copyright (c) 2001-2009 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)
-=============================================================================*/
-///////////////////////////////////////////////////////////////////////////////
-//
-// A calculator example demonstrating the grammar and semantic actions
-// using phoenix to do the actual expression evaluation. The parser is
-// essentially an "interpreter" that evaluates expressions on the fly.
-//
-// Additionally this examples shows how to build and use a lexer based on
-// Ben Hansons Lexertl (http://www.benhanson.net/lexertl.html). This way the
-// parser matches the grammar against the tokens generated by the lexer
-// component and not against the input character stream.
-//
-// Even if the benefits of using a lexer for this small calculator grammar may
-// not outweight the corresponding overhead, we provide this example because
-// it allows to concentrate on the essentials without having to understand
-// the semantics first.
-//
-// [ JDG June 29, 2002 ] spirit1
-// [ JDG March 5, 2007 ] spirit2
-//
-///////////////////////////////////////////////////////////////////////////////
-
-#include <boost/config/warning_disable.hpp>
-#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
-#include <boost/spirit/include/phoenix_operator.hpp>
-
-#include <iostream>
-#include <string>
-
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::lex;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our token definition
-// This class is used to define all the tokens to be recognized by the lexer.
-///////////////////////////////////////////////////////////////////////////////
-template <typename Lexer>
-struct calculator_tokens : lexer_def<Lexer>
-{
- template <typename Self>
- void def (Self& self)
- {
- // unsigned integer token definition
- ui = "[1-9][0-9]*";
-
- // whitespace token definitions
- ws = "[ \\t\\f\\v]+";
- c_comment = "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/";
-
- // build token set
- skipper = ws | c_comment; // += is allowed as well
-
- // associate the tokens and the token set with the lexer
- // default lexer state
- self = token_def<>('+') | '-' | '*' | '/' | '(' | ')';
- self += ui; // still default state
-
- // The token_set 'skipper' get's assigned to a separate lexer state
- // which allows to use it separately from the main tokenization
- // (it is used as the skipper parser below)
- self("SKIPPER") = skipper; // lexer state "SKIPPER"
- }
-
- // This are the tokens to be recognized by the lexer.
- token_def<unsigned int> ui; // matched tokens will have a unsigned int
- token_def<> ws, c_comment; // attribute will not be used
-
- // This is the only token set explicitly defined by this lexer because it
- // needs to be accessible from the outside (used as skip parser below).
- typename Lexer::token_set skipper;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator grammar
-//
-// The difference to the original example (calc3.cpp) is that we are
-// specifying a second template parameter referring to the lexer. Further, we
-// use a defined tokenset from above as the skip parser.
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator, typename Lexer>
-struct calculator : grammar<Iterator, int(), typename Lexer::token_set>
-{
- template <typename TokenDef>
- calculator(TokenDef const& tok)
- : calculator::base_type(expression)
- {
- // grammar
- expression =
- term [_val = _1]
- >> *( ('+' >> term [_val += _1])
- | ('-' >> term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' >> factor [_val *= _1])
- | ('/' >> factor [_val /= _1])
- )
- ;
-
- factor =
- tok.ui [_val = _1]
- | '(' >> expression [_val = _1] >> ')'
- | ('-' >> factor [_val = -_1])
- | ('+' >> factor [_val = _1])
- ;
- }
-
- rule<Iterator, int(), typename Lexer::token_set> expression, term, factor;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// Main program
-///////////////////////////////////////////////////////////////////////////////
-int
-main()
-{
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Expression parser...\n\n";
- std::cout << "/////////////////////////////////////////////////////////\n\n";
- std::cout << "Type an expression...or [q or Q] to quit\n\n";
-
- // iterator type used to expose the underlying input stream
- typedef std::string::const_iterator base_iterator_type;
-
- // This is the lexer token type to use. The second template parameter lists
- // all attribute types used for token_def's during token definition (see
- // calculator_tokens<> above). Here we use the predefined lexertl token
- // type, but any compatible token type may be used.
- typedef lexertl_token<
- base_iterator_type, boost::mpl::vector<unsigned int>
- > token_type;
-
- // This is the lexer type to use to tokenize the input.
- // Here we use the lexertl based lexer engine.
- typedef lexertl_lexer<token_type> lexer_type;
-
- // This is the token definition type (derived from the given lexer type).
- typedef calculator_tokens<lexer_type> calculator_tokens;
-
- // this is the iterator type exposed by the lexer
- typedef lexer<calculator_tokens>::iterator_type iterator_type;
-
- // this is the type of the grammar to parse
- typedef calculator<iterator_type, lexer_type> calculator;
-
- // now we use the types defined above to create the lexer and grammar
- // object instances needed to invoke the parsing process
- calculator_tokens tokens; // Our token definition
- calculator calc(tokens); // Our grammar definition
-
- lexer<calculator_tokens> lex(tokens); // Our lexer
-
- // get input line by line and feed the parser to evaluate the expressions
- // read in from the input
- std::string str;
- int result;
- while (std::getline(std::cin, str))
- {
- if (str.empty() || str[0] == 'q' || str[0] == 'Q')
- break;
-
- // At this point we generate the iterator pair used to expose the
- // tokenized input stream.
- iterator_type iter = lex.begin(str.begin(), str.end());
- iterator_type end = lex.end();
-
- // Parsing is done based on the the token stream, not the character
- // stream read from the input.
- // Note, how we use the token_set defined above as the skip parser.
- bool r = phrase_parse(iter, end, calc, result, tokens.skipper);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "result = " << result << std::endl;
- std::cout << "-------------------------\n";
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- }
- }
-
- std::cout << "Bye... :-) \n\n";
- return 0;
-}
-
-
Modified: trunk/libs/spirit/example/qi/calc4.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc4.cpp (original)
+++ trunk/libs/spirit/example/qi/calc4.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -21,62 +21,69 @@
#include <iostream>
#include <string>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-using boost::phoenix::val;
-using boost::phoenix::construct;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator grammar
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : grammar<Iterator, int(), space_type>
+namespace client
{
- calculator() : calculator::base_type(expression)
+ namespace qi = boost::spirit::qi;
+ namespace phoenix = boost::phoenix;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our calculator grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct calculator : qi::grammar<Iterator, int(), ascii::space_type>
{
- expression =
- term [_val = _1]
- >> *( ('+' > term [_val += _1])
- | ('-' > term [_val -= _1])
- )
- ;
-
- term =
- factor [_val = _1]
- >> *( ('*' > factor [_val *= _1])
- | ('/' > factor [_val /= _1])
- )
- ;
-
- factor =
- uint_ [_val = _1]
- | '(' > expression [_val = _1] > ')'
- | ('-' > factor [_val = -_1])
- | ('+' > factor [_val = _1])
- ;
-
- expression.name("expression");
- term.name("term");
- factor.name("factor");
-
- on_error<fail>
- (
- expression
- , std::cout
- << val("Error! Expecting ")
- << _4 // what failed?
- << val(" here: \"")
- << construct<std::string>(_3, _2) // iterators to error-pos, end
- << val("\"")
- << std::endl
- );
- }
+ calculator() : calculator::base_type(expression)
+ {
+ using namespace qi::labels;
+ using qi::uint_;
+ using qi::on_error;
+ using qi::fail;
+
+ using phoenix::construct;
+ using phoenix::val;
+
+ expression =
+ term [_val = _1]
+ >> *( ('+' > term [_val += _1])
+ | ('-' > term [_val -= _1])
+ )
+ ;
+
+ term =
+ factor [_val = _1]
+ >> *( ('*' > factor [_val *= _1])
+ | ('/' > factor [_val /= _1])
+ )
+ ;
+
+ factor =
+ uint_ [_val = _1]
+ | '(' > expression [_val = _1] > ')'
+ | ('-' > factor [_val = -_1])
+ | ('+' > factor [_val = _1])
+ ;
+
+ expression.name("expression");
+ term.name("term");
+ factor.name("factor");
+
+ on_error<fail>
+ (
+ expression
+ , std::cout
+ << val("Error! Expecting ")
+ << _4 // what failed?
+ << val(" here: \"")
+ << construct<std::string>(_3, _2) // iterators to error-pos, end
+ << val("\"")
+ << std::endl
+ );
+ }
- rule<Iterator, int(), space_type> expression, term, factor;
-};
+ qi::rule<Iterator, int(), ascii::space_type> expression, term, factor;
+ };
+}
///////////////////////////////////////////////////////////////////////////////
// Main program
@@ -89,10 +96,10 @@
std::cout << "/////////////////////////////////////////////////////////\n\n";
std::cout << "Type an expression...or [q or Q] to quit\n\n";
+ using boost::spirit::ascii::space;
typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
+ typedef client::calculator<iterator_type> calculator;
- calculator def; // Our grammar definition
calculator calc; // Our grammar
std::string str;
@@ -104,7 +111,7 @@
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, calc, result, space);
+ bool r = phrase_parse(iter, end, calc, space, result);
if (r && iter == end)
{
Added: trunk/libs/spirit/example/qi/calc4_debug.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/example/qi/calc4_debug.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,140 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 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)
+=============================================================================*/
+///////////////////////////////////////////////////////////////////////////////
+//
+// Same as cal4, but with debugging enabled.
+//
+// [ JDG June 29, 2002 ] spirit1
+// [ JDG March 5, 2007 ] spirit2
+//
+///////////////////////////////////////////////////////////////////////////////
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_object.hpp>
+
+#include <iostream>
+#include <string>
+
+namespace client
+{
+ namespace qi = boost::spirit::qi;
+ namespace phoenix = boost::phoenix;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our calculator grammar
+ ///////////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct calculator : qi::grammar<Iterator, int(), ascii::space_type>
+ {
+ calculator() : calculator::base_type(expression)
+ {
+ using namespace qi::labels;
+ using qi::uint_;
+ using qi::on_error;
+ using qi::fail;
+ using qi::debug;
+
+ using phoenix::construct;
+ using phoenix::val;
+
+ expression =
+ term [_val = _1]
+ >> *( ('+' > term [_val += _1])
+ | ('-' > term [_val -= _1])
+ )
+ ;
+
+ term =
+ factor [_val = _1]
+ >> *( ('*' > factor [_val *= _1])
+ | ('/' > factor [_val /= _1])
+ )
+ ;
+
+ factor =
+ uint_ [_val = _1]
+ | '(' > expression [_val = _1] > ')'
+ | ('-' > factor [_val = -_1])
+ | ('+' > factor [_val = _1])
+ ;
+
+ expression.name("expression");
+ term.name("term");
+ factor.name("factor");
+
+ on_error<fail>
+ (
+ expression
+ , std::cout
+ << val("Error! Expecting ")
+ << _4 // what failed?
+ << val(" here: \"")
+ << construct<std::string>(_3, _2) // iterators to error-pos, end
+ << val("\"")
+ << std::endl
+ );
+
+ debug(expression);
+ debug(term);
+ debug(factor);
+ }
+
+ qi::rule<Iterator, int(), ascii::space_type> expression, term, factor;
+ };
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Main program
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "Expression parser...\n\n";
+ std::cout << "/////////////////////////////////////////////////////////\n\n";
+ std::cout << "Type an expression...or [q or Q] to quit\n\n";
+
+ using boost::spirit::ascii::space;
+ typedef std::string::const_iterator iterator_type;
+ typedef client::calculator<iterator_type> calculator;
+
+ calculator calc; // Our grammar
+
+ std::string str;
+ int result;
+ while (std::getline(std::cin, str))
+ {
+ if (str.empty() || str[0] == 'q' || str[0] == 'Q')
+ break;
+
+ std::string::const_iterator iter = str.begin();
+ std::string::const_iterator end = str.end();
+ bool r = phrase_parse(iter, end, calc, space, result);
+
+ if (r && iter == end)
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "result = " << result << std::endl;
+ std::cout << "-------------------------\n";
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ }
+ }
+
+ std::cout << "Bye... :-) \n\n";
+ return 0;
+}
+
+
Modified: trunk/libs/spirit/example/qi/calc5.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc5.cpp (original)
+++ trunk/libs/spirit/example/qi/calc5.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -28,163 +28,170 @@
#include <string>
#include <vector>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-using boost::phoenix::ref;
-using boost::phoenix::push_back;
-using boost::phoenix::val;
-using boost::phoenix::construct;
-
-///////////////////////////////////////////////////////////////////////////////
-// The Virtual Machine
-///////////////////////////////////////////////////////////////////////////////
-enum byte_code
+namespace client
{
- op_neg, // negate the top stack entry
- op_add, // add top two stack entries
- op_sub, // subtract top two stack entries
- op_mul, // multiply top two stack entries
- op_div, // divide top two stack entries
- op_int, // push constant integer into the stack
-};
-
-class vmachine
-{
-public:
-
- vmachine(unsigned stackSize = 4096)
- : stack(stackSize)
- , stack_ptr(stack.begin())
- {
- }
+ namespace qi = boost::spirit::qi;
+ namespace phoenix = boost::phoenix;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // The Virtual Machine
+ ///////////////////////////////////////////////////////////////////////////
+ enum byte_code
+ {
+ op_neg, // negate the top stack entry
+ op_add, // add top two stack entries
+ op_sub, // subtract top two stack entries
+ op_mul, // multiply top two stack entries
+ op_div, // divide top two stack entries
+ op_int, // push constant integer into the stack
+ };
+
+ class vmachine
+ {
+ public:
+
+ vmachine(unsigned stackSize = 4096)
+ : stack(stackSize)
+ , stack_ptr(stack.begin())
+ {
+ }
- int top() const { return stack_ptr[-1]; };
- void execute(std::vector<int> const& code);
+ int top() const { return stack_ptr[-1]; };
+ void execute(std::vector<int> const& code);
-private:
+ private:
- std::vector<int> stack;
- std::vector<int>::iterator stack_ptr;
-};
+ std::vector<int> stack;
+ std::vector<int>::iterator stack_ptr;
+ };
-void vmachine::execute(std::vector<int> const& code)
-{
- std::vector<int>::const_iterator pc = code.begin();
- stack_ptr = stack.begin();
-
- while (pc != code.end())
+ void vmachine::execute(std::vector<int> const& code)
{
- switch (*pc++)
+ std::vector<int>::const_iterator pc = code.begin();
+ stack_ptr = stack.begin();
+
+ while (pc != code.end())
{
- case op_neg:
- stack_ptr[-1] = -stack_ptr[-1];
- break;
-
- case op_add:
- --stack_ptr;
- stack_ptr[-1] += stack_ptr[0];
- break;
-
- case op_sub:
- --stack_ptr;
- stack_ptr[-1] -= stack_ptr[0];
- break;
-
- case op_mul:
- --stack_ptr;
- stack_ptr[-1] *= stack_ptr[0];
- break;
-
- case op_div:
- --stack_ptr;
- stack_ptr[-1] /= stack_ptr[0];
- break;
-
- case op_int:
- *stack_ptr++ = *pc++;
- break;
+ switch (*pc++)
+ {
+ case op_neg:
+ stack_ptr[-1] = -stack_ptr[-1];
+ break;
+
+ case op_add:
+ --stack_ptr;
+ stack_ptr[-1] += stack_ptr[0];
+ break;
+
+ case op_sub:
+ --stack_ptr;
+ stack_ptr[-1] -= stack_ptr[0];
+ break;
+
+ case op_mul:
+ --stack_ptr;
+ stack_ptr[-1] *= stack_ptr[0];
+ break;
+
+ case op_div:
+ --stack_ptr;
+ stack_ptr[-1] /= stack_ptr[0];
+ break;
+
+ case op_int:
+ *stack_ptr++ = *pc++;
+ break;
+ }
}
}
-}
-///////////////////////////////////////////////////////////////////////////////
-// Our calculator grammar and compiler
-///////////////////////////////////////////////////////////////////////////////
-template <typename Iterator>
-struct calculator : grammar<Iterator, space_type>
-{
- calculator(std::vector<int>& code)
- : calculator::base_type(expression)
- , code(code)
- {
- expression =
- term
- >> *( ('+' > term [push_back(ref(code), op_add)])
- | ('-' > term [push_back(ref(code), op_sub)])
- )
- ;
-
- term =
- factor
- >> *( ('*' > factor [push_back(ref(code), op_mul)])
- | ('/' > factor [push_back(ref(code), op_div)])
- )
- ;
-
- factor =
- uint_ [
- push_back(ref(code), op_int),
- push_back(ref(code), _1)
- ]
- | '(' > expression > ')'
- | ('-' > factor [push_back(ref(code), op_neg)])
- | ('+' > factor)
- ;
-
- expression.name("expression");
- term.name("term");
- factor.name("factor");
-
- on_error<fail>
- (
- expression
- , std::cout
- << val("Error! Expecting ")
- << _4 // what failed?
- << val(" here: \"")
- << construct<std::string>(_3, _2) // iterators to error-pos, end
- << val("\"")
- << std::endl
- );
- }
+ ///////////////////////////////////////////////////////////////////////////
+ // Our calculator grammar and compiler
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Iterator>
+ struct calculator : qi::grammar<Iterator, ascii::space_type>
+ {
+ calculator(std::vector<int>& code)
+ : calculator::base_type(expression)
+ , code(code)
+ {
+ using namespace qi::labels;
+ using qi::uint_;
+ using qi::on_error;
+ using qi::fail;
+
+ using phoenix::val;
+ using phoenix::ref;
+ using phoenix::push_back;
+ using phoenix::construct;
+
+ expression =
+ term
+ >> *( ('+' > term [push_back(ref(code), op_add)])
+ | ('-' > term [push_back(ref(code), op_sub)])
+ )
+ ;
+
+ term =
+ factor
+ >> *( ('*' > factor [push_back(ref(code), op_mul)])
+ | ('/' > factor [push_back(ref(code), op_div)])
+ )
+ ;
+
+ factor =
+ uint_ [
+ push_back(ref(code), op_int),
+ push_back(ref(code), _1)
+ ]
+ | '(' > expression > ')'
+ | ('-' > factor [push_back(ref(code), op_neg)])
+ | ('+' > factor)
+ ;
+
+ expression.name("expression");
+ term.name("term");
+ factor.name("factor");
+
+ on_error<fail>
+ (
+ expression
+ , std::cout
+ << val("Error! Expecting ")
+ << _4 // what failed?
+ << val(" here: \"")
+ << construct<std::string>(_3, _2) // iterators to error-pos, end
+ << val("\"")
+ << std::endl
+ );
+ }
- rule<Iterator, space_type> expression, term, factor;
- std::vector<int>& code;
-};
+ qi::rule<Iterator, ascii::space_type> expression, term, factor;
+ std::vector<int>& code;
+ };
+
+ template <typename Grammar>
+ bool compile(Grammar const& calc, std::string const& expr)
+ {
+ std::string::const_iterator iter = expr.begin();
+ std::string::const_iterator end = expr.end();
+ bool r = phrase_parse(iter, end, calc, ascii::space);
-template <typename Grammar>
-bool compile(Grammar const& calc, std::string const& expr)
-{
- std::string::const_iterator iter = expr.begin();
- std::string::const_iterator end = expr.end();
- bool r = phrase_parse(iter, end, calc, space);
-
- if (r && iter == end)
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing succeeded\n";
- std::cout << "-------------------------\n";
- return true;
- }
- else
- {
- std::cout << "-------------------------\n";
- std::cout << "Parsing failed\n";
- std::cout << "-------------------------\n";
- return false;
+ if (r && iter == end)
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing succeeded\n";
+ std::cout << "-------------------------\n";
+ return true;
+ }
+ else
+ {
+ std::cout << "-------------------------\n";
+ std::cout << "Parsing failed\n";
+ std::cout << "-------------------------\n";
+ return false;
+ }
}
}
@@ -200,9 +207,9 @@
std::cout << "Type an expression...or [q or Q] to quit\n\n";
typedef std::string::const_iterator iterator_type;
- typedef calculator<iterator_type> calculator;
+ typedef client::calculator<iterator_type> calculator;
- vmachine mach; // Our virtual machine
+ client::vmachine mach; // Our virtual machine
std::vector<int> code; // Our VM code
calculator calc(code); // Our grammar
@@ -213,7 +220,7 @@
break;
code.clear();
- if (::compile(calc, str))
+ if (client::compile(calc, str))
{
mach.execute(code);
std::cout << "\n\nresult = " << mach.top() << std::endl;
Modified: trunk/libs/spirit/example/qi/calc6/calc6.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc6/calc6.cpp (original)
+++ trunk/libs/spirit/example/qi/calc6/calc6.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -21,6 +21,8 @@
template <typename Grammar>
bool compile(Grammar const& calc, std::string const& expr)
{
+ using ascii::space;
+
std::string::const_iterator iter = expr.begin();
std::string::const_iterator end = expr.end();
bool r = phrase_parse(iter, end, calc, space);
Modified: trunk/libs/spirit/example/qi/calc6/calc6.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc6/calc6.hpp (original)
+++ trunk/libs/spirit/example/qi/calc6/calc6.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -18,14 +18,14 @@
#include <string>
#include <vector>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
using boost::phoenix::function;
using boost::phoenix::ref;
+using boost::spirit::qi::unused_type;
+
+namespace qi = boost::spirit::qi;
+namespace ascii = boost::spirit::ascii;
+
///////////////////////////////////////////////////////////////////////////////
// The Virtual Machine
///////////////////////////////////////////////////////////////////////////////
@@ -105,7 +105,7 @@
template <typename Iterator>
void operator()(
- std::string const& what
+ qi::info const& what
, Iterator err_pos, Iterator last) const
{
std::cout
@@ -125,16 +125,16 @@
// Our expression grammar and compiler
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
-struct expression : grammar<Iterator, space_type>
+struct expression : qi::grammar<Iterator, ascii::space_type>
{
- expression(std::vector<int>& code, symbols<char, int>& vars);
+ expression(std::vector<int>& code, qi::symbols<char, int>& vars);
- rule<Iterator, space_type>
+ qi::rule<Iterator, ascii::space_type>
expr, additive_expr, multiplicative_expr
, unary_expr, primary_expr, variable;
std::vector<int>& code;
- symbols<char, int>& vars;
+ qi::symbols<char, int>& vars;
function<compile_op> op;
};
@@ -146,7 +146,7 @@
template <typename, typename>
struct result { typedef void type; };
- var_adder(symbols<char, int>& vars)
+ var_adder(qi::symbols<char, int>& vars)
: vars(vars)
{
}
@@ -156,24 +156,24 @@
vars.add(var.begin(), var.end(), nvars++);
};
- symbols<char, int>& vars;
+ qi::symbols<char, int>& vars;
};
template <typename Iterator>
-struct statement : grammar<Iterator, space_type>
+struct statement : qi::grammar<Iterator, ascii::space_type>
{
statement(std::vector<int>& code);
std::vector<int>& code;
- symbols<char, int> vars;
+ qi::symbols<char, int> vars;
int nvars;
expression<Iterator> expr;
- rule<Iterator, space_type> start, var_decl;
- rule<Iterator, std::string(), space_type> identifier;
- rule<Iterator, int(), space_type> var_ref;
- rule<Iterator, locals<int>, space_type> assignment;
- rule<Iterator, void(int), space_type> assignment_rhs;
+ qi::rule<Iterator, ascii::space_type> start, var_decl;
+ qi::rule<Iterator, std::string(), ascii::space_type> identifier;
+ qi::rule<Iterator, int(), ascii::space_type> var_ref;
+ qi::rule<Iterator, qi::locals<int>, ascii::space_type> assignment;
+ qi::rule<Iterator, void(int), ascii::space_type> assignment_rhs;
function<var_adder> add_var;
function<compile_op> op;
Modified: trunk/libs/spirit/example/qi/calc6/calc6a.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc6/calc6a.cpp (original)
+++ trunk/libs/spirit/example/qi/calc6/calc6a.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/calc6/calc6b.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc6/calc6b.cpp (original)
+++ trunk/libs/spirit/example/qi/calc6/calc6b.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -11,7 +11,7 @@
void instantiate_expression()
{
typedef std::string::const_iterator iterator_type;
- symbols<char, int> vars;
+ qi::symbols<char, int> vars;
std::vector<int> code;
expression<iterator_type> g(code, vars);
}
Modified: trunk/libs/spirit/example/qi/calc6/calc6b.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc6/calc6b.hpp (original)
+++ trunk/libs/spirit/example/qi/calc6/calc6b.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -13,12 +13,19 @@
// Our expression grammar and compiler
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
-expression<Iterator>::expression(std::vector<int>& code, symbols<char, int>& vars)
+expression<Iterator>::expression(std::vector<int>& code, qi::symbols<char, int>& vars)
: expression::base_type(expr)
, code(code)
, vars(vars)
, op(code)
{
+ using qi::lexeme;
+ using qi::uint_;
+ using namespace qi::labels;
+ using qi::on_error;
+ using qi::fail;
+ using ascii::alnum;
+
expr =
additive_expr.alias()
;
Modified: trunk/libs/spirit/example/qi/calc6/calc6c.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc6/calc6c.cpp (original)
+++ trunk/libs/spirit/example/qi/calc6/calc6c.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/calc6/calc6c.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc6/calc6c.hpp (original)
+++ trunk/libs/spirit/example/qi/calc6/calc6c.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -21,6 +21,15 @@
, add_var(vars)
, op(code)
{
+ using qi::lexeme;
+ using qi::lit;
+ using qi::raw;
+ using namespace qi::labels;
+ using qi::on_error;
+ using qi::fail;
+ using ascii::alnum;
+ using ascii::alpha;
+
identifier %=
raw[lexeme[alpha >> *(alnum | '_')]]
;
@@ -48,7 +57,7 @@
assignment_rhs =
expr
- > char_(';') [op(op_store, _r1)]
+ > lit(';') [op(op_store, _r1)]
;
start = +(var_decl | assignment);
@@ -62,4 +71,4 @@
on_error<fail>(start, error_handler(_4, _3, _2));
}
-#endif
\ No newline at end of file
+#endif
Modified: trunk/libs/spirit/example/qi/calc7/calc7.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc7/calc7.cpp (original)
+++ trunk/libs/spirit/example/qi/calc7/calc7.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -17,6 +17,8 @@
template <typename Grammar>
bool compile(Grammar const& calc, std::string const& expr)
{
+ using ascii::space;
+
std::string::const_iterator iter = expr.begin();
std::string::const_iterator end = expr.end();
bool r = phrase_parse(iter, end, calc, space);
Modified: trunk/libs/spirit/example/qi/calc7/calc7.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc7/calc7.hpp (original)
+++ trunk/libs/spirit/example/qi/calc7/calc7.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -18,15 +18,15 @@
#include <string>
#include <vector>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
using boost::phoenix::function;
using boost::phoenix::ref;
using boost::phoenix::size;
+using boost::spirit::qi::unused_type;
+
+namespace qi = boost::spirit::qi;
+namespace ascii = boost::spirit::ascii;
+
///////////////////////////////////////////////////////////////////////////////
// The Virtual Machine
///////////////////////////////////////////////////////////////////////////////
@@ -124,7 +124,7 @@
template <typename Iterator>
void operator()(
- std::string const& what
+ qi::info const& what
, Iterator err_pos, Iterator last) const
{
std::cout
@@ -144,18 +144,18 @@
// Our expression grammar and compiler
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
-struct expression : grammar<Iterator, space_type>
+struct expression : qi::grammar<Iterator, ascii::space_type>
{
- expression(std::vector<int>& code, symbols<char, int>& vars);
+ expression(std::vector<int>& code, qi::symbols<char, int>& vars);
- rule<Iterator, space_type>
+ qi::rule<Iterator, ascii::space_type>
expr, equality_expr, relational_expr
, logical_expr, additive_expr, multiplicative_expr
, unary_expr, primary_expr, variable
;
std::vector<int>& code;
- symbols<char, int>& vars;
+ qi::symbols<char, int>& vars;
function<compile_op> op;
};
@@ -167,7 +167,7 @@
template <typename, typename>
struct result { typedef void type; };
- var_adder(symbols<char, int>& vars)
+ var_adder(qi::symbols<char, int>& vars)
: vars(vars)
{
}
@@ -177,29 +177,29 @@
vars.add(var.begin(), var.end(), nvars++);
};
- symbols<char, int>& vars;
+ qi::symbols<char, int>& vars;
};
template <typename Iterator>
-struct statement : grammar<Iterator, space_type>
+struct statement : qi::grammar<Iterator, ascii::space_type>
{
statement(std::vector<int>& code);
std::vector<int>& code;
- symbols<char, int> vars;
+ qi::symbols<char, int> vars;
int nvars;
expression<Iterator> expr;
- rule<Iterator, space_type>
+ qi::rule<Iterator, ascii::space_type>
statement_, statement_list, var_decl, compound_statement
;
- rule<Iterator, locals<int>, space_type> if_statement;
- rule<Iterator, locals<int, int>, space_type> while_statement;
- rule<Iterator, std::string(), space_type> identifier;
- rule<Iterator, int(), space_type> var_ref;
- rule<Iterator, locals<int>, space_type> assignment;
- rule<Iterator, void(int), space_type> assignment_rhs;
+ qi::rule<Iterator, qi::locals<int>, ascii::space_type> if_statement;
+ qi::rule<Iterator, qi::locals<int, int>, ascii::space_type> while_statement;
+ qi::rule<Iterator, std::string(), ascii::space_type> identifier;
+ qi::rule<Iterator, int(), ascii::space_type> var_ref;
+ qi::rule<Iterator, qi::locals<int>, ascii::space_type> assignment;
+ qi::rule<Iterator, void(int), ascii::space_type> assignment_rhs;
function<var_adder> add_var;
function<compile_op> op;
Modified: trunk/libs/spirit/example/qi/calc7/calc7a.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc7/calc7a.cpp (original)
+++ trunk/libs/spirit/example/qi/calc7/calc7a.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/calc7/calc7b.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc7/calc7b.cpp (original)
+++ trunk/libs/spirit/example/qi/calc7/calc7b.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -11,7 +11,7 @@
void instantiate_expression()
{
typedef std::string::const_iterator iterator_type;
- symbols<char, int> vars;
+ qi::symbols<char, int> vars;
std::vector<int> code;
expression<iterator_type> g(code, vars);
}
Modified: trunk/libs/spirit/example/qi/calc7/calc7b.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc7/calc7b.hpp (original)
+++ trunk/libs/spirit/example/qi/calc7/calc7b.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -13,12 +13,20 @@
// Our expression grammar and compiler
///////////////////////////////////////////////////////////////////////////////
template <typename Iterator>
-expression<Iterator>::expression(std::vector<int>& code, symbols<char, int>& vars)
+expression<Iterator>::expression(std::vector<int>& code, qi::symbols<char, int>& vars)
: expression::base_type(expr)
, code(code)
, vars(vars)
, op(code)
{
+ using qi::lexeme;
+ using qi::lit;
+ using qi::uint_;
+ using namespace qi::labels;
+ using qi::on_error;
+ using qi::fail;
+ using ascii::alnum;
+
expr =
equality_expr.alias()
;
Modified: trunk/libs/spirit/example/qi/calc7/calc7c.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc7/calc7c.cpp (original)
+++ trunk/libs/spirit/example/qi/calc7/calc7c.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/calc7/calc7c.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/calc7/calc7c.hpp (original)
+++ trunk/libs/spirit/example/qi/calc7/calc7c.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -21,6 +21,15 @@
, add_var(vars)
, op(code)
{
+ using qi::lexeme;
+ using qi::lit;
+ using qi::raw;
+ using namespace qi::labels;
+ using qi::on_error;
+ using qi::fail;
+ using ascii::alnum;
+ using ascii::alpha;
+
identifier %=
raw[lexeme[alpha >> *(alnum | '_')]]
;
@@ -48,7 +57,7 @@
assignment_rhs =
expr
- > char_(';') [op(op_store, _r1)]
+ > lit(';') [op(op_store, _r1)]
;
if_statement =
Modified: trunk/libs/spirit/example/qi/complex_number.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/complex_number.cpp (original)
+++ trunk/libs/spirit/example/qi/complex_number.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2002-2007 Joel de Guzman
+ Copyright (c) 2002-2009 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)
@@ -22,37 +22,40 @@
#include <string>
#include <complex>
-using namespace boost::phoenix;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
///////////////////////////////////////////////////////////////////////////////
// Our complex number parser/compiler
///////////////////////////////////////////////////////////////////////////////
//[tutorial_complex_number
-template <typename Iterator>
-bool parse_complex(Iterator first, Iterator last, std::complex<double>& c)
+namespace client
{
- double rN = 0.0;
- double iN = 0.0;
- bool r = phrase_parse(first, last,
-
- // Begin grammar
- (
- '(' >> double_[ref(rN) = _1]
- >> -(',' >> double_[ref(iN) = _1]) >> ')'
- | double_[ref(rN) = _1]
- ),
- // End grammar
-
- space);
-
- if (!r || first != last) // fail if we did not get a full match
- return false;
- c = std::complex<double>(rN, iN);
- return r;
+ template <typename Iterator>
+ bool parse_complex(Iterator first, Iterator last, std::complex<double>& c)
+ {
+ using boost::spirit::qi::double_;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::phrase_parse;
+ using boost::spirit::ascii::space;
+ using boost::phoenix::ref;
+
+ double rN = 0.0;
+ double iN = 0.0;
+ bool r = phrase_parse(first, last,
+
+ // Begin grammar
+ (
+ '(' >> double_[ref(rN) = _1]
+ >> -(',' >> double_[ref(iN) = _1]) >> ')'
+ | double_[ref(rN) = _1]
+ ),
+ // End grammar
+
+ space);
+
+ if (!r || first != last) // fail if we did not get a full match
+ return false;
+ c = std::complex<double>(rN, iN);
+ return r;
+ }
}
//]
@@ -76,7 +79,7 @@
break;
std::complex<double> c;
- if (parse_complex(str.begin(), str.end(), c))
+ if (client::parse_complex(str.begin(), str.end(), c))
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
Modified: trunk/libs/spirit/example/qi/employee.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/employee.cpp (original)
+++ trunk/libs/spirit/example/qi/employee.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2002-2007 Joel de Guzman
+ Copyright (c) 2002-2009 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)
@@ -25,30 +25,32 @@
#include <string>
#include <complex>
-using namespace boost::phoenix;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our employee struct
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_employee_struct
-struct employee
+namespace client
{
- int age;
- std::string surname;
- std::string forename;
- double salary;
-};
-//]
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our employee struct
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_employee_struct
+ struct employee
+ {
+ int age;
+ std::string surname;
+ std::string forename;
+ double salary;
+ };
+ //]
+}
// We need to tell fusion about our employee struct
-// to make it a first-class fusion citizen
+// to make it a first-class fusion citizen. This has to
+// be in global scope.
+
//[tutorial_employee_adapt_struct
BOOST_FUSION_ADAPT_STRUCT(
- employee,
+ client::employee,
(int, age)
(std::string, surname)
(std::string, forename)
@@ -56,32 +58,41 @@
)
//]
-///////////////////////////////////////////////////////////////////////////////
-// Our employee parser
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_employee_parser
-template <typename Iterator>
-struct employee_parser : grammar<Iterator, employee(), space_type>
+namespace client
{
- employee_parser() : employee_parser::base_type(start)
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our employee parser
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_employee_parser
+ template <typename Iterator>
+ struct employee_parser : qi::grammar<Iterator, employee(), ascii::space_type>
{
- quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
-
- start %=
- lit("employee")
- >> '{'
- >> int_ >> ','
- >> quoted_string >> ','
- >> quoted_string >> ','
- >> double_
- >> '}'
- ;
- }
+ employee_parser() : employee_parser::base_type(start)
+ {
+ using qi::int_;
+ using qi::lit;
+ using qi::double_;
+ using qi::lexeme;
+ using ascii::char_;
+
+ quoted_string %= lexeme['"' >> +(char_ - '"') >> '"'];
+
+ start %=
+ lit("employee")
+ >> '{'
+ >> int_ >> ','
+ >> quoted_string >> ','
+ >> quoted_string >> ','
+ >> double_
+ >> '}'
+ ;
+ }
- rule<Iterator, std::string(), space_type> quoted_string;
- rule<Iterator, employee(), space_type> start;
-};
-//]
+ qi::rule<Iterator, std::string(), ascii::space_type> quoted_string;
+ qi::rule<Iterator, employee(), ascii::space_type> start;
+ };
+ //]
+}
////////////////////////////////////////////////////////////////////////////
// Main program
@@ -98,8 +109,9 @@
<< "employee{age, \"surname\", \"forename\", salary } \n";
std::cout << "Type [q or Q] to quit\n\n";
+ using boost::spirit::ascii::space;
typedef std::string::const_iterator iterator_type;
- typedef employee_parser<iterator_type> employee_parser;
+ typedef client::employee_parser<iterator_type> employee_parser;
employee_parser g; // Our grammar
std::string str;
@@ -108,10 +120,10 @@
if (str.empty() || str[0] == 'q' || str[0] == 'Q')
break;
- employee emp;
+ client::employee emp;
std::string::const_iterator iter = str.begin();
std::string::const_iterator end = str.end();
- bool r = phrase_parse(iter, end, g, emp, space);
+ bool r = phrase_parse(iter, end, g, space, emp);
if (r && iter == end)
{
Modified: trunk/libs/spirit/example/qi/mini_c/mini_c.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_c.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_c.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -85,7 +85,7 @@
{
std::string fmain("main");
std::string::iterator fbegin = fmain.begin();
- function_info* f = prog.functions.lookup()->find(fbegin, fmain.end());
+ function_info* f = prog.functions.lookup->find(fbegin, fmain.end());
if (f == 0)
{
std::cerr << "Error: main function not defined" << std::endl;
Modified: trunk/libs/spirit/example/qi/mini_c/mini_c.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_c.hpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_c.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -20,15 +20,14 @@
#include <string>
#include <vector>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
using boost::phoenix::function;
using boost::phoenix::ref;
using boost::phoenix::size;
+using namespace boost::spirit;
+using namespace boost::spirit::qi;
+using namespace boost::spirit::ascii;
+
///////////////////////////////////////////////////////////////////////////////
// The Virtual Machine
///////////////////////////////////////////////////////////////////////////////
@@ -152,7 +151,7 @@
template <typename Iterator>
void operator()(
- std::string const& what
+ info const& what
, Iterator err_pos, Iterator last) const
{
std::cout
Modified: trunk/libs/spirit/example/qi/mini_c/mini_ca.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_ca.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_ca.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/mini_c/mini_cb.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cb.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cb.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cb.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -96,7 +96,7 @@
expr [++_b]
>> *(',' > expr [++_b])
)
- > char_(')') [op(_a, _b, pass)]
+ > lit(')') [op(_a, _b, pass)]
;
expr.name("expression");
@@ -110,7 +110,7 @@
variable.name("variable");
function_call.name("function-call");
- on_error<fail>(expr, error_handler(_4, _3, _2));
+ on_error<fail>(expr, ::error_handler(_4, _3, _2)); // $$$ fix!
}
#endif
Modified: trunk/libs/spirit/example/qi/mini_c/mini_cc.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cc.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cc.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cc.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -50,7 +50,7 @@
assignment_rhs =
expr
- > char_(';') [op(op_store, _r1)]
+ > lit(';') [op(op_store, _r1)]
;
if_statement =
@@ -137,7 +137,7 @@
statement_.name("statement");
statement_list.name("statement-list");
- on_error<fail>(statement_list, error_handler(_4, _3, _2));
+ on_error<fail>(statement_list, ::error_handler(_4, _3, _2));
}
#endif
Modified: trunk/libs/spirit/example/qi/mini_c/mini_cd.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cd.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cd.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp (original)
+++ trunk/libs/spirit/example/qi/mini_c/mini_cd.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -42,7 +42,7 @@
>> *(',' > identifier [add_var(_1)])
)
> ')'
- > char_('{') [
+ > lit('{') [
_b = size(ref(code)),
add_function(
_a // function name
@@ -52,7 +52,7 @@
op(op_stk_adj, 0) // adjust this later
]
> statement
- > char_('}') [state_reset(_b)]
+ > lit('}') [state_reset(_b)]
;
start =
@@ -63,7 +63,7 @@
function.name("function");
start.name("program");
- on_error<fail>(start, error_handler(_4, _3, _2));
+ on_error<fail>(start, ::error_handler(_4, _3, _2));
}
#endif
Modified: trunk/libs/spirit/example/qi/mini_xml1.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_xml1.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_xml1.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -27,147 +27,156 @@
#include <string>
#include <vector>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-namespace fusion = boost::fusion;
-namespace phoenix = boost::phoenix;
-
-using phoenix::at_c;
-using phoenix::push_back;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our mini XML tree representation
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_xml1_structures
-struct mini_xml;
-
-typedef
- boost::variant<
- boost::recursive_wrapper<mini_xml>
- , std::string
- >
-mini_xml_node;
-
-struct mini_xml
+namespace client
{
- std::string name; // tag name
- std::vector<mini_xml_node> children; // children
-};
-//]
+ namespace fusion = boost::fusion;
+ namespace phoenix = boost::phoenix;
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our mini XML tree representation
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_xml1_structures
+ struct mini_xml;
+
+ typedef
+ boost::variant<
+ boost::recursive_wrapper<mini_xml>
+ , std::string
+ >
+ mini_xml_node;
+
+ struct mini_xml
+ {
+ std::string name; // tag name
+ std::vector<mini_xml_node> children; // children
+ };
+ //]
+}
// We need to tell fusion about our mini_xml struct
// to make it a first-class fusion citizen
//[tutorial_xml1_adapt_structures
BOOST_FUSION_ADAPT_STRUCT(
- mini_xml,
+ client::mini_xml,
(std::string, name)
- (std::vector<mini_xml_node>, children)
+ (std::vector<client::mini_xml_node>, children)
)
//]
-///////////////////////////////////////////////////////////////////////////////
-// Print out the mini xml tree
-///////////////////////////////////////////////////////////////////////////////
-int const tabsize = 4;
-
-void tab(int indent)
+namespace client
{
- for (int i = 0; i < indent; ++i)
- std::cout << ' ';
+ ///////////////////////////////////////////////////////////////////////////
+ // Print out the mini xml tree
+ ///////////////////////////////////////////////////////////////////////////
+ int const tabsize = 4;
+
+ void tab(int indent)
+ {
+ for (int i = 0; i < indent; ++i)
+ std::cout << ' ';
+ }
+
+ struct mini_xml_printer
+ {
+ mini_xml_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const;
+
+ int indent;
+ };
+
+ struct mini_xml_node_printer : boost::static_visitor<>
+ {
+ mini_xml_node_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const
+ {
+ mini_xml_printer(indent+tabsize)(xml);
+ }
+
+ void operator()(std::string const& text) const
+ {
+ tab(indent+tabsize);
+ std::cout << "text: \"" << text << '"' << std::endl;
+ }
+
+ int indent;
+ };
+
+ void mini_xml_printer::operator()(mini_xml const& xml) const
+ {
+ tab(indent);
+ std::cout << "tag: " << xml.name << std::endl;
+ tab(indent);
+ std::cout << '{' << std::endl;
+
+ BOOST_FOREACH(mini_xml_node const& node, xml.children)
+ {
+ boost::apply_visitor(mini_xml_node_printer(indent), node);
+ }
+
+ tab(indent);
+ std::cout << '}' << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our mini XML grammar definition
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_xml1_grammar
+ template <typename Iterator>
+ struct mini_xml_grammar : qi::grammar<Iterator, mini_xml(), ascii::space_type>
+ {
+ mini_xml_grammar() : mini_xml_grammar::base_type(xml)
+ {
+ using qi::lit;
+ using qi::lexeme;
+ using ascii::char_;
+ using ascii::string;
+ using namespace qi::labels;
+
+ using phoenix::at_c;
+ using phoenix::push_back;
+
+ text = lexeme[+(char_ - '<') [_val += _1]];
+ node = (xml | text) [_val = _1];
+
+ start_tag =
+ '<'
+ >> !lit('/')
+ >> lexeme[+(char_ - '>') [_val += _1]]
+ >> '>'
+ ;
+
+ end_tag =
+ "</"
+ >> string(_r1)
+ >> '>'
+ ;
+
+ xml =
+ start_tag [at_c<0>(_val) = _1]
+ >> *node [push_back(at_c<1>(_val), _1)]
+ >> end_tag(at_c<0>(_val))
+ ;
+ }
+
+ qi::rule<Iterator, mini_xml(), ascii::space_type> xml;
+ qi::rule<Iterator, mini_xml_node(), ascii::space_type> node;
+ qi::rule<Iterator, std::string(), ascii::space_type> text;
+ qi::rule<Iterator, std::string(), ascii::space_type> start_tag;
+ qi::rule<Iterator, void(std::string), ascii::space_type> end_tag;
+ };
+ //]
}
-struct mini_xml_printer
-{
- mini_xml_printer(int indent = 0)
- : indent(indent)
- {
- }
-
- void operator()(mini_xml const& xml) const;
-
- int indent;
-};
-
-struct mini_xml_node_printer : boost::static_visitor<>
-{
- mini_xml_node_printer(int indent = 0)
- : indent(indent)
- {
- }
-
- void operator()(mini_xml const& xml) const
- {
- mini_xml_printer(indent+tabsize)(xml);
- }
-
- void operator()(std::string const& text) const
- {
- tab(indent+tabsize);
- std::cout << "text: \"" << text << '"' << std::endl;
- }
-
- int indent;
-};
-
-void mini_xml_printer::operator()(mini_xml const& xml) const
-{
- tab(indent);
- std::cout << "tag: " << xml.name << std::endl;
- tab(indent);
- std::cout << '{' << std::endl;
-
- BOOST_FOREACH(mini_xml_node const& node, xml.children)
- {
- boost::apply_visitor(mini_xml_node_printer(indent), node);
- }
-
- tab(indent);
- std::cout << '}' << std::endl;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Our mini XML grammar definition
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_xml1_grammar
-template <typename Iterator>
-struct mini_xml_grammar : grammar<Iterator, mini_xml(), space_type>
-{
- mini_xml_grammar() : mini_xml_grammar::base_type(xml)
- {
- text = lexeme[+(char_ - '<') [_val += _1]];
- node = (xml | text) [_val = _1];
-
- start_tag =
- '<'
- >> !char_('/')
- >> lexeme[+(char_ - '>') [_val += _1]]
- >> '>'
- ;
-
- end_tag =
- "</"
- >> lit(_r1)
- >> '>'
- ;
-
- xml =
- start_tag [at_c<0>(_val) = _1]
- >> *node [push_back(at_c<1>(_val), _1)]
- >> end_tag(at_c<0>(_val))
- ;
- }
-
- rule<Iterator, mini_xml(), space_type> xml;
- rule<Iterator, mini_xml_node(), space_type> node;
- rule<Iterator, std::string(), space_type> text;
- rule<Iterator, std::string(), space_type> start_tag;
- rule<Iterator, void(std::string), space_type> end_tag;
-};
-//]
-
///////////////////////////////////////////////////////////////////////////////
// Main program
///////////////////////////////////////////////////////////////////////////////
@@ -200,20 +209,21 @@
std::istream_iterator<char>(),
std::back_inserter(storage));
- typedef mini_xml_grammar<std::string::const_iterator> mini_xml_grammar;
+ typedef client::mini_xml_grammar<std::string::const_iterator> mini_xml_grammar;
mini_xml_grammar xml; // Our grammar
- mini_xml ast; // our tree
+ client::mini_xml ast; // Our tree
+ using boost::spirit::ascii::space;
std::string::const_iterator iter = storage.begin();
std::string::const_iterator end = storage.end();
- bool r = phrase_parse(iter, end, xml, ast, space);
+ bool r = phrase_parse(iter, end, xml, space, ast);
if (r && iter == end)
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
std::cout << "-------------------------\n";
- mini_xml_printer printer;
+ client::mini_xml_printer printer;
printer(ast);
return 0;
}
Modified: trunk/libs/spirit/example/qi/mini_xml2.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_xml2.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_xml2.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -27,145 +27,151 @@
#include <string>
#include <vector>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-namespace fusion = boost::fusion;
-namespace phoenix = boost::phoenix;
-
-using phoenix::at_c;
-using phoenix::push_back;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our mini XML tree representation
-///////////////////////////////////////////////////////////////////////////////
-struct mini_xml;
-
-typedef
- boost::variant<
- boost::recursive_wrapper<mini_xml>
- , std::string
- >
-mini_xml_node;
-
-struct mini_xml
+namespace client
{
- std::string name; // tag name
- std::vector<mini_xml_node> children; // children
-};
+ namespace fusion = boost::fusion;
+ namespace phoenix = boost::phoenix;
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our mini XML tree representation
+ ///////////////////////////////////////////////////////////////////////////
+ struct mini_xml;
+
+ typedef
+ boost::variant<
+ boost::recursive_wrapper<mini_xml>
+ , std::string
+ >
+ mini_xml_node;
+
+ struct mini_xml
+ {
+ std::string name; // tag name
+ std::vector<mini_xml_node> children; // children
+ };
+}
// We need to tell fusion about our mini_xml struct
// to make it a first-class fusion citizen
BOOST_FUSION_ADAPT_STRUCT(
- mini_xml,
+ client::mini_xml,
(std::string, name)
- (std::vector<mini_xml_node>, children)
+ (std::vector<client::mini_xml_node>, children)
)
-///////////////////////////////////////////////////////////////////////////////
-// Print out the mini xml tree
-///////////////////////////////////////////////////////////////////////////////
-int const tabsize = 4;
-
-void tab(int indent)
+namespace client
{
- for (int i = 0; i < indent; ++i)
- std::cout << ' ';
+ ///////////////////////////////////////////////////////////////////////////
+ // Print out the mini xml tree
+ ///////////////////////////////////////////////////////////////////////////
+ int const tabsize = 4;
+
+ void tab(int indent)
+ {
+ for (int i = 0; i < indent; ++i)
+ std::cout << ' ';
+ }
+
+ struct mini_xml_printer
+ {
+ mini_xml_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const;
+
+ int indent;
+ };
+
+ struct mini_xml_node_printer : boost::static_visitor<>
+ {
+ mini_xml_node_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const
+ {
+ mini_xml_printer(indent+tabsize)(xml);
+ }
+
+ void operator()(std::string const& text) const
+ {
+ tab(indent+tabsize);
+ std::cout << "text: \"" << text << '"' << std::endl;
+ }
+
+ int indent;
+ };
+
+ void mini_xml_printer::operator()(mini_xml const& xml) const
+ {
+ tab(indent);
+ std::cout << "tag: " << xml.name << std::endl;
+ tab(indent);
+ std::cout << '{' << std::endl;
+
+ BOOST_FOREACH(mini_xml_node const& node, xml.children)
+ {
+ boost::apply_visitor(mini_xml_node_printer(indent), node);
+ }
+
+ tab(indent);
+ std::cout << '}' << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our mini XML grammar definition
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_xml2_grammar
+ template <typename Iterator>
+ struct mini_xml_grammar
+ : qi::grammar<Iterator, mini_xml(), qi::locals<std::string>, ascii::space_type>
+ {
+ mini_xml_grammar()
+ : mini_xml_grammar::base_type(xml)
+ {
+ using qi::lit;
+ using qi::lexeme;
+ using ascii::char_;
+ using ascii::string;
+ using namespace qi::labels;
+
+ text %= lexeme[+(char_ - '<')];
+ node %= xml | text;
+
+ start_tag %=
+ '<'
+ >> !lit('/')
+ >> lexeme[+(char_ - '>')]
+ >> '>'
+ ;
+
+ end_tag =
+ "</"
+ >> string(_r1)
+ >> '>'
+ ;
+
+ xml %=
+ start_tag[_a = _1]
+ >> *node
+ >> end_tag(_a)
+ ;
+ }
+
+ qi::rule<Iterator, mini_xml(), qi::locals<std::string>, ascii::space_type> xml;
+ qi::rule<Iterator, mini_xml_node(), ascii::space_type> node;
+ qi::rule<Iterator, std::string(), ascii::space_type> text;
+ qi::rule<Iterator, std::string(), ascii::space_type> start_tag;
+ qi::rule<Iterator, void(std::string), ascii::space_type> end_tag;
+ };
+ //]
}
-struct mini_xml_printer
-{
- mini_xml_printer(int indent = 0)
- : indent(indent)
- {
- }
-
- void operator()(mini_xml const& xml) const;
-
- int indent;
-};
-
-struct mini_xml_node_printer : boost::static_visitor<>
-{
- mini_xml_node_printer(int indent = 0)
- : indent(indent)
- {
- }
-
- void operator()(mini_xml const& xml) const
- {
- mini_xml_printer(indent+tabsize)(xml);
- }
-
- void operator()(std::string const& text) const
- {
- tab(indent+tabsize);
- std::cout << "text: \"" << text << '"' << std::endl;
- }
-
- int indent;
-};
-
-void mini_xml_printer::operator()(mini_xml const& xml) const
-{
- tab(indent);
- std::cout << "tag: " << xml.name << std::endl;
- tab(indent);
- std::cout << '{' << std::endl;
-
- BOOST_FOREACH(mini_xml_node const& node, xml.children)
- {
- boost::apply_visitor(mini_xml_node_printer(indent), node);
- }
-
- tab(indent);
- std::cout << '}' << std::endl;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Our mini XML grammar definition
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_xml2_grammar
-template <typename Iterator>
-struct mini_xml_grammar
- : grammar<Iterator, mini_xml(), locals<std::string>, space_type>
-{
- mini_xml_grammar()
- : mini_xml_grammar::base_type(xml)
- {
- text %= lexeme[+(char_ - '<')];
- node %= xml | text;
-
- start_tag %=
- '<'
- >> !char_('/')
- >> lexeme[+(char_ - '>')]
- >> '>'
- ;
-
- end_tag =
- "</"
- >> lit(_r1)
- >> '>'
- ;
-
- xml %=
- start_tag[_a = _1]
- >> *node
- >> end_tag(_a)
- ;
- }
-
- rule<Iterator, mini_xml(), locals<std::string>, space_type> xml;
- rule<Iterator, mini_xml_node(), space_type> node;
- rule<Iterator, std::string(), space_type> text;
- rule<Iterator, std::string(), space_type> start_tag;
- rule<Iterator, void(std::string), space_type> end_tag;
-};
-//]
-
///////////////////////////////////////////////////////////////////////////////
// Main program
///////////////////////////////////////////////////////////////////////////////
@@ -198,20 +204,21 @@
std::istream_iterator<char>(),
std::back_inserter(storage));
- typedef mini_xml_grammar<std::string::const_iterator> mini_xml_grammar;
+ typedef client::mini_xml_grammar<std::string::const_iterator> mini_xml_grammar;
mini_xml_grammar xml; // Our grammar
- mini_xml ast; // our tree
+ client::mini_xml ast; // Our tree
+ using boost::spirit::ascii::space;
std::string::const_iterator iter = storage.begin();
std::string::const_iterator end = storage.end();
- bool r = phrase_parse(iter, end, xml, ast, space);
+ bool r = phrase_parse(iter, end, xml, space, ast);
if (r && iter == end)
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
std::cout << "-------------------------\n";
- mini_xml_printer printer;
+ client::mini_xml_printer printer;
printer(ast);
return 0;
}
Modified: trunk/libs/spirit/example/qi/mini_xml3.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/mini_xml3.cpp (original)
+++ trunk/libs/spirit/example/qi/mini_xml3.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -28,165 +28,174 @@
#include <string>
#include <vector>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-namespace fusion = boost::fusion;
-namespace phoenix = boost::phoenix;
-
-using phoenix::at_c;
-using phoenix::push_back;
-using phoenix::val;
-using phoenix::construct;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our mini XML tree representation
-///////////////////////////////////////////////////////////////////////////////
-struct mini_xml;
-
-typedef
- boost::variant<
- boost::recursive_wrapper<mini_xml>
- , std::string
- >
-mini_xml_node;
-
-struct mini_xml
+namespace client
{
- std::string name; // tag name
- std::vector<mini_xml_node> children; // children
-};
+ namespace fusion = boost::fusion;
+ namespace phoenix = boost::phoenix;
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our mini XML tree representation
+ ///////////////////////////////////////////////////////////////////////////
+ struct mini_xml;
+
+ typedef
+ boost::variant<
+ boost::recursive_wrapper<mini_xml>
+ , std::string
+ >
+ mini_xml_node;
+
+ struct mini_xml
+ {
+ std::string name; // tag name
+ std::vector<mini_xml_node> children; // children
+ };
+}
// We need to tell fusion about our mini_xml struct
// to make it a first-class fusion citizen
BOOST_FUSION_ADAPT_STRUCT(
- mini_xml,
+ client::mini_xml,
(std::string, name)
- (std::vector<mini_xml_node>, children)
+ (std::vector<client::mini_xml_node>, children)
)
-///////////////////////////////////////////////////////////////////////////////
-// Print out the mini xml tree
-///////////////////////////////////////////////////////////////////////////////
-int const tabsize = 4;
-
-void tab(int indent)
+namespace client
{
- for (int i = 0; i < indent; ++i)
- std::cout << ' ';
+ ///////////////////////////////////////////////////////////////////////////
+ // Print out the mini xml tree
+ ///////////////////////////////////////////////////////////////////////////
+ int const tabsize = 4;
+
+ void tab(int indent)
+ {
+ for (int i = 0; i < indent; ++i)
+ std::cout << ' ';
+ }
+
+ struct mini_xml_printer
+ {
+ mini_xml_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const;
+
+ int indent;
+ };
+
+ struct mini_xml_node_printer : boost::static_visitor<>
+ {
+ mini_xml_node_printer(int indent = 0)
+ : indent(indent)
+ {
+ }
+
+ void operator()(mini_xml const& xml) const
+ {
+ mini_xml_printer(indent+tabsize)(xml);
+ }
+
+ void operator()(std::string const& text) const
+ {
+ tab(indent+tabsize);
+ std::cout << "text: \"" << text << '"' << std::endl;
+ }
+
+ int indent;
+ };
+
+ void mini_xml_printer::operator()(mini_xml const& xml) const
+ {
+ tab(indent);
+ std::cout << "tag: " << xml.name << std::endl;
+ tab(indent);
+ std::cout << '{' << std::endl;
+
+ BOOST_FOREACH(mini_xml_node const& node, xml.children)
+ {
+ boost::apply_visitor(mini_xml_node_printer(indent), node);
+ }
+
+ tab(indent);
+ std::cout << '}' << std::endl;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our mini XML grammar definition
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_xml3_grammar
+ template <typename Iterator>
+ struct mini_xml_grammar
+ : qi::grammar<Iterator, mini_xml(), qi::locals<std::string>, ascii::space_type>
+ {
+ mini_xml_grammar()
+ : mini_xml_grammar::base_type(xml, "xml")
+ {
+ using qi::lit;
+ using qi::lexeme;
+ using qi::on_error;
+ using qi::fail;
+ using ascii::char_;
+ using ascii::string;
+ using namespace qi::labels;
+
+ using phoenix::construct;
+ using phoenix::val;
+
+ text %= lexeme[+(char_ - '<')];
+ node %= xml | text;
+
+ start_tag %=
+ '<'
+ >> !lit('/')
+ > lexeme[+(char_ - '>')]
+ > '>'
+ ;
+
+ end_tag =
+ "</"
+ > string(_r1)
+ > '>'
+ ;
+
+ xml %=
+ start_tag[_a = _1]
+ > *node
+ > end_tag(_a)
+ ;
+
+ xml.name("xml");
+ node.name("node");
+ text.name("text");
+ start_tag.name("start_tag");
+ end_tag.name("end_tag");
+
+ on_error<fail>
+ (
+ xml
+ , std::cout
+ << val("Error! Expecting ")
+ << _4 // what failed?
+ << val(" here: \"")
+ << construct<std::string>(_3, _2) // iterators to error-pos, end
+ << val("\"")
+ << std::endl
+ );
+ }
+
+ qi::rule<Iterator, mini_xml(), qi::locals<std::string>, ascii::space_type> xml;
+ qi::rule<Iterator, mini_xml_node(), ascii::space_type> node;
+ qi::rule<Iterator, std::string(), ascii::space_type> text;
+ qi::rule<Iterator, std::string(), ascii::space_type> start_tag;
+ qi::rule<Iterator, void(std::string), ascii::space_type> end_tag;
+ };
+ //]
}
-struct mini_xml_printer
-{
- mini_xml_printer(int indent = 0)
- : indent(indent)
- {
- }
-
- void operator()(mini_xml const& xml) const;
-
- int indent;
-};
-
-struct mini_xml_node_printer : boost::static_visitor<>
-{
- mini_xml_node_printer(int indent = 0)
- : indent(indent)
- {
- }
-
- void operator()(mini_xml const& xml) const
- {
- mini_xml_printer(indent+tabsize)(xml);
- }
-
- void operator()(std::string const& text) const
- {
- tab(indent+tabsize);
- std::cout << "text: \"" << text << '"' << std::endl;
- }
-
- int indent;
-};
-
-void mini_xml_printer::operator()(mini_xml const& xml) const
-{
- tab(indent);
- std::cout << "tag: " << xml.name << std::endl;
- tab(indent);
- std::cout << '{' << std::endl;
-
- BOOST_FOREACH(mini_xml_node const& node, xml.children)
- {
- boost::apply_visitor(mini_xml_node_printer(indent), node);
- }
-
- tab(indent);
- std::cout << '}' << std::endl;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Our mini XML grammar definition
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_xml3_grammar
-template <typename Iterator>
-struct mini_xml_grammar
- : grammar<Iterator, mini_xml(), locals<std::string>, space_type>
-{
- mini_xml_grammar()
- : mini_xml_grammar::base_type(xml, "xml")
- {
- text %= lexeme[+(char_ - '<')];
- node %= xml | text;
-
- start_tag %=
- '<'
- >> !char_('/')
- > lexeme[+(char_ - '>')]
- > '>'
- ;
-
- end_tag =
- "</"
- > lit(_r1)
- > '>'
- ;
-
- xml %=
- start_tag[_a = _1]
- > *node
- > end_tag(_a)
- ;
-
- xml.name("xml");
- node.name("node");
- text.name("text");
- start_tag.name("start_tag");
- end_tag.name("end_tag");
-
- on_error<fail>
- (
- xml
- , std::cout
- << val("Error! Expecting ")
- << _4 // what failed?
- << val(" here: \"")
- << construct<std::string>(_3, _2) // iterators to error-pos, end
- << val("\"")
- << std::endl
- );
- }
-
- rule<Iterator, mini_xml(), locals<std::string>, space_type> xml;
- rule<Iterator, mini_xml_node(), space_type> node;
- rule<Iterator, std::string(), space_type> text;
- rule<Iterator, std::string(), space_type> start_tag;
- rule<Iterator, void(std::string), space_type> end_tag;
-};
-//]
-
///////////////////////////////////////////////////////////////////////////////
// Main program
///////////////////////////////////////////////////////////////////////////////
@@ -219,20 +228,21 @@
std::istream_iterator<char>(),
std::back_inserter(storage));
- typedef mini_xml_grammar<std::string::const_iterator> mini_xml_grammar;
+ typedef client::mini_xml_grammar<std::string::const_iterator> mini_xml_grammar;
mini_xml_grammar xml; // Our grammar
- mini_xml ast; // our tree
+ client::mini_xml ast; // Our tree
+ using boost::spirit::ascii::space;
std::string::const_iterator iter = storage.begin();
std::string::const_iterator end = storage.end();
- bool r = phrase_parse(iter, end, xml, ast, space);
+ bool r = phrase_parse(iter, end, xml, space, ast);
if (r && iter == end)
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
std::cout << "-------------------------\n";
- mini_xml_printer printer;
+ client::mini_xml_printer printer;
printer(ast);
return 0;
}
Modified: trunk/libs/spirit/example/qi/num_list1.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/num_list1.cpp (original)
+++ trunk/libs/spirit/example/qi/num_list1.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2002-2007 Joel de Guzman
+ Copyright (c) 2002-2009 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)
@@ -21,30 +21,34 @@
#include <string>
#include <vector>
-using namespace boost::phoenix;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our number list parser
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_numlist1
-template <typename Iterator>
-bool parse_numbers(Iterator first, Iterator last)
+namespace client
{
- bool r = phrase_parse(
- first, /*< start iterator >*/
- last, /*< end iterator >*/
- double_ >> *(',' >> double_), /*< the parser >*/
- space /*< the skip-parser >*/
- );
- if (first != last) // fail if we did not get a full match
- return false;
- return r;
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our number list parser
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_numlist1
+ template <typename Iterator>
+ bool parse_numbers(Iterator first, Iterator last)
+ {
+ using qi::double_;
+ using qi::phrase_parse;
+ using ascii::space;
+
+ bool r = phrase_parse(
+ first, /*< start iterator >*/
+ last, /*< end iterator >*/
+ double_ >> *(',' >> double_), /*< the parser >*/
+ space /*< the skip-parser >*/
+ );
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
}
-//]
////////////////////////////////////////////////////////////////////////////
// Main program
@@ -65,7 +69,7 @@
if (str.empty() || str[0] == 'q' || str[0] == 'Q')
break;
- if (parse_numbers(str.begin(), str.end()))
+ if (client::parse_numbers(str.begin(), str.end()))
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
Modified: trunk/libs/spirit/example/qi/num_list2.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/num_list2.cpp (original)
+++ trunk/libs/spirit/example/qi/num_list2.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2002-2007 Joel de Guzman
+ Copyright (c) 2002-2009 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)
@@ -24,36 +24,44 @@
#include <string>
#include <vector>
-using namespace boost::phoenix;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our number list compiler
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_numlist2
-template <typename Iterator>
-bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
+namespace client
{
- bool r = phrase_parse(first, last,
-
- // Begin grammar
- (
- double_[push_back(ref(v), _1)]
- >> *(',' >> double_[push_back(ref(v), _1)])
- )
- ,
- // End grammar
-
- space);
-
- if (first != last) // fail if we did not get a full match
- return false;
- return r;
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+ namespace phoenix = boost::phoenix;
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our number list compiler
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_numlist2
+ template <typename Iterator>
+ bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
+ {
+ using qi::double_;
+ using qi::phrase_parse;
+ using qi::_1;
+ using ascii::space;
+ using phoenix::push_back;
+ using phoenix::ref;
+
+ bool r = phrase_parse(first, last,
+
+ // Begin grammar
+ (
+ double_[push_back(ref(v), _1)]
+ >> *(',' >> double_[push_back(ref(v), _1)])
+ )
+ ,
+ // End grammar
+
+ space);
+
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
}
-//]
////////////////////////////////////////////////////////////////////////////
// Main program
@@ -76,7 +84,7 @@
break;
std::vector<double> v;
- if (parse_numbers(str.begin(), str.end(), v))
+ if (client::parse_numbers(str.begin(), str.end(), v))
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
Modified: trunk/libs/spirit/example/qi/num_list3.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/num_list3.cpp (original)
+++ trunk/libs/spirit/example/qi/num_list3.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2002-2007 Joel de Guzman
+ Copyright (c) 2002-2009 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)
@@ -24,35 +24,43 @@
#include <string>
#include <vector>
-using namespace boost::phoenix;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our number list compiler
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_numlist3
-template <typename Iterator>
-bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
+namespace client
{
- bool r = phrase_parse(first, last,
-
- // Begin grammar
- (
- double_[push_back(ref(v), _1)] % ','
- )
- ,
- // End grammar
-
- space);
-
- if (first != last) // fail if we did not get a full match
- return false;
- return r;
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+ namespace phoenix = boost::phoenix;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Our number list compiler
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_numlist3
+ template <typename Iterator>
+ bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
+ {
+ using qi::double_;
+ using qi::phrase_parse;
+ using qi::_1;
+ using ascii::space;
+ using phoenix::push_back;
+ using phoenix::ref;
+
+ bool r = phrase_parse(first, last,
+
+ // Begin grammar
+ (
+ double_[push_back(ref(v), _1)] % ','
+ )
+ ,
+ // End grammar
+
+ space);
+
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
}
-//]
////////////////////////////////////////////////////////////////////////////
// Main program
@@ -75,7 +83,7 @@
break;
std::vector<double> v;
- if (parse_numbers(str.begin(), str.end(), v))
+ if (client::parse_numbers(str.begin(), str.end(), v))
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
Modified: trunk/libs/spirit/example/qi/num_list4.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/num_list4.cpp (original)
+++ trunk/libs/spirit/example/qi/num_list4.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2002-2007 Joel de Guzman
+ Copyright (c) 2002-2009 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)
@@ -24,35 +24,40 @@
#include <string>
#include <vector>
-using namespace boost::phoenix;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-
-///////////////////////////////////////////////////////////////////////////////
-// Our number list compiler
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_numlist4
-template <typename Iterator>
-bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
+namespace client
{
- bool r = phrase_parse(first, last,
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
- // Begin grammar
- (
- double_ % ','
- )
- ,
- // End grammar
-
- v, space);
-
- if (first != last) // fail if we did not get a full match
- return false;
- return r;
+ ///////////////////////////////////////////////////////////////////////////
+ // Our number list compiler
+ ///////////////////////////////////////////////////////////////////////////
+ //[tutorial_numlist4
+ template <typename Iterator>
+ bool parse_numbers(Iterator first, Iterator last, std::vector<double>& v)
+ {
+ using qi::double_;
+ using qi::phrase_parse;
+ using qi::_1;
+ using ascii::space;
+
+ bool r = phrase_parse(first, last,
+
+ // Begin grammar
+ (
+ double_ % ','
+ )
+ ,
+ // End grammar
+
+ space, v);
+
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
}
-//]
////////////////////////////////////////////////////////////////////////////
// Main program
@@ -75,7 +80,7 @@
break;
std::vector<double> v;
- if (parse_numbers(str.begin(), str.end(), v))
+ if (client::parse_numbers(str.begin(), str.end(), v))
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
Modified: trunk/libs/spirit/example/qi/roman.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/roman.cpp (original)
+++ trunk/libs/spirit/example/qi/roman.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -21,113 +21,119 @@
#include <iostream>
#include <string>
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-using boost::phoenix::ref;
-
-///////////////////////////////////////////////////////////////////////////////
-// Parse roman hundreds (100..900) numerals using the symbol table.
-// Notice that the data associated with each slot is the parser's attribute
-// (which is passed to attached semantic actions).
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_roman_hundreds
-struct hundreds_ : symbols<char, unsigned>
+namespace client
{
- hundreds_()
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman hundreds (100..900) numerals using the symbol table.
+ // Notice that the data associated with each slot is the parser's attribute
+ // (which is passed to attached semantic actions).
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_hundreds
+ struct hundreds_ : qi::symbols<char, unsigned>
{
- add
- ("C" , 100)
- ("CC" , 200)
- ("CCC" , 300)
- ("CD" , 400)
- ("D" , 500)
- ("DC" , 600)
- ("DCC" , 700)
- ("DCCC" , 800)
- ("CM" , 900)
- ;
- }
+ hundreds_()
+ {
+ add
+ ("C" , 100)
+ ("CC" , 200)
+ ("CCC" , 300)
+ ("CD" , 400)
+ ("D" , 500)
+ ("DC" , 600)
+ ("DCC" , 700)
+ ("DCCC" , 800)
+ ("CM" , 900)
+ ;
+ }
-} hundreds;
-//]
+ } hundreds;
+ //]
-///////////////////////////////////////////////////////////////////////////////
-// Parse roman tens (10..90) numerals using the symbol table.
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_roman_tens
-struct tens_ : symbols<char, unsigned>
-{
- tens_()
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman tens (10..90) numerals using the symbol table.
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_tens
+ struct tens_ : qi::symbols<char, unsigned>
{
- add
- ("X" , 10)
- ("XX" , 20)
- ("XXX" , 30)
- ("XL" , 40)
- ("L" , 50)
- ("LX" , 60)
- ("LXX" , 70)
- ("LXXX" , 80)
- ("XC" , 90)
- ;
- }
+ tens_()
+ {
+ add
+ ("X" , 10)
+ ("XX" , 20)
+ ("XXX" , 30)
+ ("XL" , 40)
+ ("L" , 50)
+ ("LX" , 60)
+ ("LXX" , 70)
+ ("LXXX" , 80)
+ ("XC" , 90)
+ ;
+ }
-} tens;
-//]
+ } tens;
+ //]
-///////////////////////////////////////////////////////////////////////////////
-// Parse roman ones (1..9) numerals using the symbol table.
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_roman_ones
-struct ones_ : symbols<char, unsigned>
-{
- ones_()
+ ///////////////////////////////////////////////////////////////////////////////
+ // Parse roman ones (1..9) numerals using the symbol table.
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_ones
+ struct ones_ : qi::symbols<char, unsigned>
{
- add
- ("I" , 1)
- ("II" , 2)
- ("III" , 3)
- ("IV" , 4)
- ("V" , 5)
- ("VI" , 6)
- ("VII" , 7)
- ("VIII" , 8)
- ("IX" , 9)
- ;
- }
+ ones_()
+ {
+ add
+ ("I" , 1)
+ ("II" , 2)
+ ("III" , 3)
+ ("IV" , 4)
+ ("V" , 5)
+ ("VI" , 6)
+ ("VII" , 7)
+ ("VIII" , 8)
+ ("IX" , 9)
+ ;
+ }
-} ones;
-//]
+ } ones;
+ //]
-///////////////////////////////////////////////////////////////////////////////
-// roman (numerals) grammar
-//
-// Note the use of the || operator. The expression
-// a || b reads match a or b and in sequence. Try
-// defining the roman numerals grammar in YACC or
-// PCCTS. Spirit rules! :-)
-///////////////////////////////////////////////////////////////////////////////
-//[tutorial_roman_grammar
-template <typename Iterator>
-struct roman : grammar<Iterator, unsigned()>
-{
- roman() : roman::base_type(start)
+ ///////////////////////////////////////////////////////////////////////////////
+ // roman (numerals) grammar
+ //
+ // Note the use of the || operator. The expression
+ // a || b reads match a or b and in sequence. Try
+ // defining the roman numerals grammar in YACC or
+ // PCCTS. Spirit rules! :-)
+ ///////////////////////////////////////////////////////////////////////////////
+ //[tutorial_roman_grammar
+ template <typename Iterator>
+ struct roman : qi::grammar<Iterator, unsigned()>
{
- start = eps [_val = 0] >>
- (
- +char_('M') [_val += 1000]
- || hundreds [_val += _1]
- || tens [_val += _1]
- || ones [_val += _1]
- )
- ;
- }
+ roman() : roman::base_type(start)
+ {
+ using qi::eps;
+ using qi::lit;
+ using qi::_val;
+ using qi::_1;
+ using ascii::char_;
+
+ start = eps [_val = 0] >>
+ (
+ +lit('M') [_val += 1000]
+ || hundreds [_val += _1]
+ || tens [_val += _1]
+ || ones [_val += _1]
+ )
+ ;
+ }
- rule<Iterator, unsigned()> start;
-};
-//]
+ qi::rule<Iterator, unsigned()> start;
+ };
+ //]
+}
///////////////////////////////////////////////////////////////////////////////
// Main program
@@ -141,7 +147,7 @@
std::cout << "Type a Roman Numeral ...or [q or Q] to quit\n\n";
typedef std::string::const_iterator iterator_type;
- typedef roman<iterator_type> roman;
+ typedef client::roman<iterator_type> roman;
roman roman_parser; // Our grammar
Modified: trunk/libs/spirit/example/qi/sum.cpp
==============================================================================
--- trunk/libs/spirit/example/qi/sum.cpp (original)
+++ trunk/libs/spirit/example/qi/sum.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2002-2007 Joel de Guzman
+ Copyright (c) 2002-2009 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)
@@ -22,38 +22,44 @@
#include <string>
//]
-//[tutorial_adder_using
-using namespace boost::phoenix;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
-//]
-
-///////////////////////////////////////////////////////////////////////////////
-// Our adder
-///////////////////////////////////////////////////////////////////////////////
-
-//[tutorial_adder
-template <typename Iterator>
-bool adder(Iterator first, Iterator last, double& n)
+namespace client
{
- bool r = phrase_parse(first, last,
+ //[tutorial_adder_using
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+ namespace phoenix = boost::phoenix;
+
+ using qi::double_;
+ using qi::_1;
+ using ascii::space;
+ using phoenix::ref;
+ //]
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Our adder
+ ///////////////////////////////////////////////////////////////////////////
+
+ //[tutorial_adder
+ template <typename Iterator>
+ bool adder(Iterator first, Iterator last, double& n)
+ {
+ bool r = qi::phrase_parse(first, last,
- // Begin grammar
- (
- double_[ref(n) = _1] >> *(',' >> double_[ref(n) += _1])
- )
- ,
- // End grammar
-
- space);
-
- if (first != last) // fail if we did not get a full match
- return false;
- return r;
+ // Begin grammar
+ (
+ double_[ref(n) = _1] >> *(',' >> double_[ref(n) += _1])
+ )
+ ,
+ // End grammar
+
+ space);
+
+ if (first != last) // fail if we did not get a full match
+ return false;
+ return r;
+ }
+ //]
}
-//]
////////////////////////////////////////////////////////////////////////////
// Main program
@@ -76,7 +82,7 @@
break;
double n;
- if (adder(str.begin(), str.end(), n))
+ if (client::adder(str.begin(), str.end(), n))
{
std::cout << "-------------------------\n";
std::cout << "Parsing succeeded\n";
Modified: trunk/libs/spirit/test/CMakeLists.txt
==============================================================================
--- trunk/libs/spirit/test/CMakeLists.txt (original)
+++ trunk/libs/spirit/test/CMakeLists.txt 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,3 +1,11 @@
+# Copyright (c) 2001-2009 Joel de Guzman
+# Copyright (c) 2001-2009 Hartmut Kaiser
+#
+# Use, modification and distribution is subject to 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)
+#==============================================================================
+
boost_additional_test_dependencies(spirit BOOST_DEPENDS test variant function_types intrusive lambda assign iostreams math random dynamic_bitset fusion)
message(STATUS "Boost/libs/spirit/test needs GCC C++ -ftemplate-depth-300 flag")
@@ -7,57 +15,63 @@
SET(test_compile_flags "-ftemplate-depth-300")
ENDIF(CMAKE_COMPILER_IS_GNUCC)
+# run Qi tests
boost_test_run(qi_actions qi/actions.cpp COMPILE_FLAGS ${test_compile_flags} BOOST_LIB spirit COMPILE_FLAGS ${test_compile_flags} )
+boost_test_run(qi_alternative qi/alternative.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_and_predicate qi/and_predicate.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_binary qi/binary.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_char qi/char.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_char_class qi/char_class.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_lit qi/lit.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_int qi/int.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_uint qi/uint.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_real qi/real.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_difference qi/difference.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_end qi/end.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_eps qi/eps.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_none qi/none.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_expect qi/expect.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_grammar qi/grammar.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_int qi/int.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_kleene qi/kleene.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_lazy qi/lazy.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_tst qi/tst.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_symbols qi/symbols.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_range_run qi/range_run.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_no_case qi/no_case.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_lexeme qi/lexeme.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_raw qi/raw.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_sequence qi/sequence.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_alternative qi/alternative.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_sequential_or qi/sequential_or.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_permutation qi/permutation.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_difference qi/difference.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_uint qi/uint.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_lit qi/lit.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_list qi/list.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_match_manip qi/match_manip.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_match_manip_attr qi/match_manip_attr.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_no_case qi/no_case.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_not_predicate qi/not_predicate.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_optional qi/optional.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_kleene qi/kleene.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_parse_attr qi/parse_attr.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_permutation qi/permutation.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_plus qi/plus.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_and_predicate qi/and_predicate.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_not_predicate qi/not_predicate.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_expect qi/expect.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_range_run qi/range_run.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_raw qi/raw.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_real qi/real.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_repeat qi/repeat.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(qi_rule qi/rule.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_grammar qi/grammar.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_functor qi/functor.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_match_manip qi/match_manip.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_binary qi/binary.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_debug qi/debug.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(qi_end qi/end.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_sequence qi/sequence.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_sequential_or qi/sequential_or.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_skip qi/skip.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_symbols qi/symbols.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_terminal_ex qi/terminal_ex.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_tst qi/tst.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(qi_uint qi/uint.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_compile_fail(qi_grammar_fail qi/grammar_fail.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_compile_fail(qi_rule_fail qi/rule_fail.cpp COMPILE_FLAGS ${test_compile_flags})
+# boost_test_compile_fail(qi_grammar_fail qi/grammar_fail.cpp COMPILE_FLAGS ${test_compile_flags})
+# boost_test_compile_fail(qi_rule_fail qi/rule_fail.cpp COMPILE_FLAGS ${test_compile_flags})
- # run Karma tests
+# run Karma tests
boost_test_run(karma_actions karma/actions.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_actions ]
+boost_test_run(karma_and_attribute karma/and_attribute.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_actions ]
boost_test_run(karma_alternative karma/alternative.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_alternative ]
boost_test_run(karma_binary karma/binary.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_binary ]
boost_test_run(karma_case_handling karma/case_handling.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_center_alignment karma/center_alignment.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_char karma/char.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_char ]
-boost_test_run(karma_delimieter karma/delimiter.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(karma_delimiter karma/delimiter.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_eol karma/eol.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_eol ]
boost_test_run(karma_eps karma/eps.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_eps ]
boost_test_run(karma_format_manip karma/format_manip.cpp COMPILE_FLAGS ${test_compile_flags})
-boost_test_run(karma_functor karma/functor.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_functor ]
+boost_test_run(karma_format_manip_attr karma/format_manip_attr.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(karma_generate_attr karma/generate_attr.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_grammar karma/grammar.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_grammar ]
boost_test_run(karma_int_numerics karma/int_numerics.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_kleene karma/kleene.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_kleene ]
@@ -65,23 +79,21 @@
boost_test_run(karma_left_alignment karma/left_alignment.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_list karma/list.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_list ]
boost_test_run(karma_lit karma/lit.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_lit ]
-boost_test_run(karma_none karma/none.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_none ]
+boost_test_run(karma_maxwidth karma/maxwidth.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_lit ]
boost_test_run(karma_optional karma/optional.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_optional ]
boost_test_run(karma_pattern karma/pattern.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(karma_pattern2 karma/pattern2.cpp COMPILE_FLAGS ${test_compile_flags})
+boost_test_run(karma_plus karma/plus.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_real_numerics karma/real_numerics.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_right_alignment karma/right_alignment.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(karma_sequence karma/sequence.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_sequence ]
+boost_test_run(karma_stream karma/stream.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_sequence ]
+boost_test_run(karma_tricky_alignment karma/tricky_alignment.cpp COMPILE_FLAGS ${test_compile_flags}) # : : : : karma_sequence ]
boost_test_compile_fail(karma_grammar_fail karma/grammar_fail.cpp COMPILE_FLAGS ${test_compile_flags}) # : : karma_grammar_fail ]
boost_test_compile_fail(karma_rule_fail karma/rule_fail.cpp COMPILE_FLAGS ${test_compile_flags}) # : : karma_rule_fail ]
- # run support tests
-boost_test_run(support_hold_any support/hold_any.cpp COMPILE_FLAGS ${test_compile_flags})
-# the multi_pass tests are not completed yet
-# [ run support/multi_pass_compile.cpp COMPILE_FLAGS ${test_compile_flags} : : : : ]
-# [ run support/multi_pass.cpp COMPILE_FLAGS ${test_compile_flags} : : : : ]
-
- # run lexer tests
+# run lexer tests
boost_test_run(lex_lexertl1 lex/lexertl1.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(lex_lexertl2 lex/lexertl2.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(lex_lexertl3 lex/lexertl3.cpp COMPILE_FLAGS ${test_compile_flags})
@@ -89,6 +101,12 @@
boost_test_run(lex_lexertl5 lex/lexertl5.cpp COMPILE_FLAGS ${test_compile_flags})
boost_test_run(lex_state_switcher_test lex/state_switcher_test.cpp COMPILE_FLAGS ${test_compile_flags})
+# run support tests
+# boost_test_run(support_hold_any support/hold_any.cpp COMPILE_FLAGS ${test_compile_flags})
+# the multi_pass tests are not completed yet
+# [ run support/multi_pass_compile.cpp COMPILE_FLAGS ${test_compile_flags} : : : : ]
+# [ run support/multi_pass.cpp COMPILE_FLAGS ${test_compile_flags} : : : : ]
+
Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,15 +1,21 @@
#==============================================================================
-# Copyright (c) 2001-2007 Joel de Guzman
-# Copyright (c) 2001-2008 Hartmut Kaiser
+# Copyright (c) 2001-2009 Joel de Guzman
+# Copyright (c) 2001-2009 Joel de Guzman
+# Copyright (c) 2001-2009 Hartmut Kaiser
#
# Use, modification and distribution is subject to 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)
#==============================================================================
-project # spirit_v2-tests
- : requirements
+project spirit_v2x/test
+ : requirements
+ <include>.
<toolset>gcc:<cxxflags>-ftemplate-depth-300
<toolset>darwin:<cxxflags>-ftemplate-depth-300
+ <toolset>gcc:<linkflags>-Wl,--enable-auto-import
+ <toolset>darwin:<linkflags>-Wl,--enable-auto-import
+ :
+ :
;
# bring in rules for testing
@@ -25,13 +31,13 @@
[ run qi/binary.cpp : : : : ]
[ run qi/char.cpp : : : : ]
[ run qi/char_class.cpp : : : : ]
- [ run qi/confix.cpp : : : : ]
- [ run qi/debug.cpp : : : : ]
+ #[ run qi/confix.cpp : : : : ]
+ #[ run qi/debug.cpp : : : : ]
[ run qi/difference.cpp : : : : ]
[ run qi/end.cpp : : : : ]
[ run qi/eps.cpp : : : : ]
[ run qi/expect.cpp : : : : ]
- [ run qi/functor.cpp : : : : ]
+ #[ run qi/functor.cpp : : : : ]
[ run qi/grammar.cpp : : : : ]
[ run qi/int.cpp : : : : ]
[ run qi/kleene.cpp : : : : ]
@@ -39,39 +45,43 @@
[ run qi/lexeme.cpp : : : : ]
[ run qi/lit.cpp : : : : ]
[ run qi/list.cpp : : : : ]
+ [ run qi/match_manip.cpp : : : : ]
+ [ run qi/match_manip_attr.cpp : : : : ]
[ run qi/no_case.cpp : : : : ]
- [ run qi/none.cpp : : : : ]
[ run qi/not_predicate.cpp : : : : ]
[ run qi/optional.cpp : : : : ]
+ [ run qi/parse_attr.cpp : : : : ]
[ run qi/permutation.cpp : : : : ]
[ run qi/plus.cpp : : : : ]
[ run qi/range_run.cpp : : : : ]
[ run qi/raw.cpp : : : : ]
[ run qi/real.cpp : : : : ]
+ [ run qi/repeat.cpp : : : : ]
[ run qi/rule.cpp : : : : ]
[ run qi/sequence.cpp : : : : ]
[ run qi/sequential_or.cpp : : : : ]
+ [ run qi/skip.cpp : : : : ]
[ run qi/symbols.cpp : : : : ]
+ [ run qi/terminal_ex.cpp : : : : ]
[ run qi/tst.cpp : : : : ]
[ run qi/uint.cpp : : : : ]
- [ run qi/match_manip.cpp : : : : ]
-
- [ compile-fail qi/grammar_fail.cpp : : ]
- [ compile-fail qi/rule_fail.cpp : : ]
# run Karma tests
[ run karma/actions.cpp : : : : karma_actions ]
+ [ run karma/and_attribute.cpp : : : : karma_and_attribute ]
[ run karma/alternative.cpp : : : : karma_alternative ]
[ run karma/binary.cpp : : : : karma_binary ]
[ run karma/case_handling.cpp : : : : ]
[ run karma/center_alignment.cpp : : : : ]
[ run karma/char.cpp : : : : karma_char ]
- [ run karma/confix.cpp : : : : karma_confix ]
+# [ run karma/confix.cpp : : : : karma_confix ]
[ run karma/delimiter.cpp : : : : ]
[ run karma/eol.cpp : : : : karma_eol ]
[ run karma/eps.cpp : : : : karma_eps ]
[ run karma/format_manip.cpp : : : : ]
- [ run karma/functor.cpp : : : : karma_functor ]
+ [ run karma/format_manip_attr.cpp : : : : ]
+# [ run karma/functor.cpp : : : : karma_functor ]
+ [ run karma/generate_attr.cpp : : : : ]
[ run karma/grammar.cpp : : : : karma_grammar ]
[ run karma/int_numerics.cpp : : : : ]
[ run karma/kleene.cpp : : : : karma_kleene ]
@@ -79,24 +89,21 @@
[ run karma/left_alignment.cpp : : : : ]
[ run karma/list.cpp : : : : karma_list ]
[ run karma/lit.cpp : : : : karma_lit ]
- [ run karma/none.cpp : : : : karma_none ]
+ [ run karma/maxwidth.cpp : : : : ]
[ run karma/optional.cpp : : : : karma_optional ]
[ run karma/pattern.cpp : : : : karma_pattern ]
[ run karma/pattern2.cpp : : : : karma_pattern2 ]
+ [ run karma/plus.cpp : : : : karma_plus ]
[ run karma/real_numerics.cpp : : : : ]
[ run karma/right_alignment.cpp : : : : ]
[ run karma/sequence.cpp : : : : karma_sequence ]
+ [ run karma/stream.cpp : : : : karma_stream ]
+ [ run karma/tricky_alignment.cpp : : : : ]
[ compile-fail karma/grammar_fail.cpp : : karma_grammar_fail ]
[ compile-fail karma/rule_fail.cpp : : karma_rule_fail ]
- # run support tests
- [ run support/hold_any.cpp : : : : ]
-# the multi_pass tests are not completed yet
-# [ run support/multi_pass_compile.cpp : : : : ]
-# [ run support/multi_pass.cpp : : : : ]
-
- # run lexer tests
+ # run Lex tests
[ run lex/lexertl1.cpp : : : : ]
[ run lex/lexertl2.cpp : : : : ]
[ run lex/lexertl3.cpp : : : : ]
@@ -108,4 +115,3 @@
}
-
Modified: trunk/libs/spirit/test/karma/actions.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/actions.cpp (original)
+++ trunk/libs/spirit/test/karma/actions.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
/*=============================================================================
- Copyright (c) 2001-2008 Hartmut Kaiser
- Copyright (c) 2001-2008 Joel de Guzman
+ Copyright (c) 2001-2009 Hartmut Kaiser
+ Copyright (c) 2001-2009 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)
@@ -9,16 +9,19 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/karma.hpp>
-#include <boost/lambda/lambda.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_action.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_operator.hpp>
#include <boost/bind.hpp>
-#include <boost/function_output_iterator.hpp>
+#include <boost/lambda/lambda.hpp>
#include <sstream>
#include "test.hpp"
using namespace spirit_test;
-using namespace boost::spirit;
+using boost::spirit::unused_type;
void read1(int& i)
{
@@ -35,6 +38,12 @@
i = 42;
}
+void read3_fail(int& i, unused_type, bool& pass)
+{
+ i = 42;
+ pass = false;
+}
+
struct read_action
{
void operator()(int& i, unused_type, unused_type) const
@@ -46,32 +55,68 @@
///////////////////////////////////////////////////////////////////////////////
int main()
{
- using namespace boost::spirit::ascii;
+ using boost::spirit::karma::int_;
+ {
+ BOOST_TEST(test("42", int_[&read1]));
+ BOOST_TEST(test_delimited("42 ", int_[&read1], ' '));
+ BOOST_TEST(test("42", int_[&read2]));
+ BOOST_TEST(test_delimited("42 ", int_[&read2], ' '));
+ BOOST_TEST(test("42", int_[&read3]));
+ BOOST_TEST(test_delimited("42 ", int_[&read3], ' '));
+ BOOST_TEST(!test("42", int_[&read3_fail]));
+ BOOST_TEST(!test_delimited("42 ", int_[&read3_fail], ' '));
+ }
+
+ {
+ BOOST_TEST(test("42", int_[read_action()]));
+ BOOST_TEST(test_delimited("42 ", int_[read_action()], ' '));
+ }
+
+ {
+ BOOST_TEST(test("42", int_[boost::bind(&read1, _1)]));
+ BOOST_TEST(test_delimited("42 ", int_[boost::bind(&read1, _1)], ' '));
+ BOOST_TEST(test("42", int_[boost::bind(&read2, _1, _2)]));
+ BOOST_TEST(test_delimited("42 ", int_[boost::bind(&read2, _1, _2)], ' '));
+ BOOST_TEST(test("42", int_[boost::bind(&read3, _1, _2, _3)]));
+ BOOST_TEST(test_delimited("42 ", int_[boost::bind(&read3, _1, _2, _3)], ' '));
+ }
+
+ {
+ namespace lambda = boost::lambda;
+ {
+ std::stringstream strm("42");
+ BOOST_TEST(test("42", int_[strm >> lambda::_1]));
+ }
+ {
+ std::stringstream strm("42");
+ BOOST_TEST(test_delimited("42 ", int_[strm >> lambda::_1], ' '));
+ }
+ }
{
BOOST_TEST(test("{42}", '{' << int_[&read1] << '}'));
- BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read1] << '}', space));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read1] << '}', ' '));
BOOST_TEST(test("{42}", '{' << int_[&read2] << '}'));
- BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read2] << '}', space));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read2] << '}', ' '));
BOOST_TEST(test("{42}", '{' << int_[&read3] << '}'));
- BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read3] << '}', space));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[&read3] << '}', ' '));
}
{
BOOST_TEST(test("{42}", '{' << int_[read_action()] << '}'));
- BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[read_action()] << '}', space));
+ BOOST_TEST(test_delimited("{ 42 } ", '{' << int_[read_action()] << '}', ' '));
}
{
BOOST_TEST(test("{42}", '{' << int_[boost::bind(&read1, _1)] << '}'));
BOOST_TEST(test_delimited("{ 42 } ",
- '{' << int_[boost::bind(&read1, _1)] << '}', space));
+ '{' << int_[boost::bind(&read1, _1)] << '}', ' '));
BOOST_TEST(test("{42}", '{' << int_[boost::bind(&read2, _1, _2)] << '}'));
BOOST_TEST(test_delimited("{ 42 } ",
- '{' << int_[boost::bind(&read2, _1, _2)] << '}', space));
+ '{' << int_[boost::bind(&read2, _1, _2)] << '}', ' '));
BOOST_TEST(test("{42}", '{' << int_[boost::bind(&read3, _1, _2, _3)] << '}'));
BOOST_TEST(test_delimited("{ 42 } ",
- '{' << int_[boost::bind(&read3, _1, _2, _3)] << '}', space));
+ '{' << int_[boost::bind(&read3, _1, _2, _3)] << '}', ' '));
}
{
@@ -83,7 +128,7 @@
{
std::stringstream strm("42");
BOOST_TEST(test_delimited("{ 42 } ",
- '{' << int_[strm >> lambda::_1] << '}', space));
+ '{' << int_[strm >> lambda::_1] << '}', ' '));
}
}
Modified: trunk/libs/spirit/test/karma/alternative.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/alternative.cpp (original)
+++ trunk/libs/spirit/test/karma/alternative.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -25,65 +25,89 @@
{
using namespace boost;
using namespace boost::spirit;
-
+ using namespace boost::spirit::ascii;
+
+ {
+ BOOST_TEST(test("x", char_('x') | char_('i')));
+ BOOST_TEST(test("xi", char_('x') << char_('i') | char_('i')));
+ BOOST_TEST(test("i", char_('i') | char_('x') << char_('i')));
+
+ variant<int, char> v (10);
+ BOOST_TEST(test("10", char_ | int_, v));
+ BOOST_TEST(test("10", int_ | char_, v));
+ BOOST_TEST(test("a", char_('a') | char_ | int_, v));
+ BOOST_TEST(test("a", char_ | char_('a') | int_, v));
+ BOOST_TEST(test("10", int_ | char_('a') | char_, v));
+
+ v = 'c';
+ BOOST_TEST(test("c", char_ | int_, v));
+ BOOST_TEST(test("a", char_('a') | char_ | int_, v));
+ BOOST_TEST(test("c", char_ | char_('a') | int_, v));
+ BOOST_TEST(test("a", int_ | char_('a') | char_, v));
+ BOOST_TEST(test("c", int_ | char_ | char_('a'), v));
+ }
+
+ {
+ // test if alternatives with all components having unused
+ // attribute generate first alternative
+ fusion::vector<char, char> v('a', 'b');
+ BOOST_TEST(test("axb", char_ << (char_('x') | char_('i')) << char_, v));
+ BOOST_TEST(test("axib",
+ char_ << (char_('x') << char_('i') | char_('i')) << char_, v));
+ }
+
{
- {
- BOOST_TEST(test("x", char_('x') | char_('i')));
- BOOST_TEST(test("xi", char_('x') << char_('i') | char_('i')));
-
- variant<int, char> v (10);
- BOOST_TEST(test("10", char_ | int_, v));
- BOOST_TEST(test("a", char_('a') | char_ | int_, v));
-
- v = 'c';
- BOOST_TEST(test("c", char_ | int_, v));
- BOOST_TEST(test("a", char_('a') | char_ | int_, v));
- }
-
- {
- // test if alternatives with all components having unused
- // parameter return attributes them self
- fusion::vector<char, char> v('a', 'b');
- BOOST_TEST(test("axb", char_ << (char_('x') | char_('i')) << char_, v));
- BOOST_TEST(test("axib",
- char_ << (char_('x') << char_('i') | char_('i')) << char_, v));
- }
-
- {
- BOOST_TEST(test_delimited("x ", char_('x') | char_('i'), char_(' ')));
- BOOST_TEST(test_delimited("x i ",
- char_('x') << char_('i') | char_('i'), char_(' ')));
-
- variant<int, char> v (10);
- BOOST_TEST(test_delimited("10 ", char_ | int_, v, char_(' ')));
-
- v = 'c';
- BOOST_TEST(test_delimited("c ", char_ | int_, v, char_(' ')));
- }
-
- {
- // if nothing matches, the first explicit alternative will be chosen
- variant<double, char const*> v (10.0);
- BOOST_TEST(test("11", char_ | int_(11), v));
- BOOST_TEST(test("10.0", double_ | int_(11), v));
- BOOST_TEST(!test("", char_ | int_, v));
-
- v = "c";
- BOOST_TEST(test("11", char_ | int_(11), v));
- BOOST_TEST(test("11", double_ | int_(11), v));
- BOOST_TEST(!test("", char_ | int_, v));
- }
-
- {
- // if nothing matches, the first explicit alternative will be chosen
- variant<double, char const*> v (10.0);
- BOOST_TEST(test_delimited("11 ", char_ | int_(11), v, char_(' ')));
-
- v = "c";
- BOOST_TEST(test_delimited("11 ", char_ | int_(11), v, char_(' ')));
- }
+ BOOST_TEST(test_delimited("x ", char_('x') | char_('i'), char_(' ')));
+ BOOST_TEST(test_delimited("x i ",
+ char_('x') << char_('i') | char_('i'), char_(' ')));
+ BOOST_TEST(test_delimited("i ",
+ char_('i') | char_('x') << char_('i'), char_(' ')));
+
+ variant<int, char> v (10);
+ BOOST_TEST(test_delimited("10 ", char_ | int_, v, char_(' ')));
+ BOOST_TEST(test_delimited("10 ", int_ | char_, v, char_(' ')));
+ BOOST_TEST(test_delimited("a ", char_('a') | char_ | int_, v, char_(' ')));
+ BOOST_TEST(test_delimited("a ", char_ | char_('a') | int_, v, char_(' ')));
+ BOOST_TEST(test_delimited("10 ", int_ | char_('a') | char_, v, char_(' ')));
+
+ v = 'c';
+ BOOST_TEST(test_delimited("c ", char_ | int_, v, char_(' ')));
+ BOOST_TEST(test_delimited("a ", char_('a') | char_ | int_, v, char_(' ')));
+ BOOST_TEST(test_delimited("c ", char_ | char_('a') | int_, v, char_(' ')));
+ BOOST_TEST(test_delimited("a ", int_ | char_('a') | char_, v, char_(' ')));
+ BOOST_TEST(test_delimited("c ", int_ | char_ | char_('a'), v, char_(' ')));
}
-
+
+ {
+ // if nothing matches, the first explicit alternative will be chosen
+ variant<double, char const*> v (10.0);
+ BOOST_TEST(test("11", char_ | int_(11), v));
+ BOOST_TEST(test("11", int_(11) | char_ , v));
+ BOOST_TEST(test("10.0", double_ | int_(11), v));
+ BOOST_TEST(test("11", int_(11) | double_, v));
+ BOOST_TEST(!test("", char_ | int_, v));
+
+ v = "c";
+ BOOST_TEST(test("11", char_ | int_(11), v));
+ BOOST_TEST(test("11", double_ | int_(11), v));
+ BOOST_TEST(!test("", char_ | int_, v));
+ }
+
+ {
+ // if nothing matches, the first explicit alternative will be chosen
+ variant<double, char const*> v (10.0);
+ BOOST_TEST(test_delimited("11 ", char_ | int_(11), v, char_(' ')));
+ BOOST_TEST(test_delimited("11 ", int_(11) | char_ , v, char_(' ')));
+ BOOST_TEST(test_delimited("10.0 ", double_ | int_(11), v, char_(' ')));
+ BOOST_TEST(test_delimited("11 ", int_(11) | double_, v, char_(' ')));
+ BOOST_TEST(!test_delimited("", char_ | int_, v, char_(' ')));
+
+ v = "c";
+ BOOST_TEST(test_delimited("11 ", char_ | int_(11), v, char_(' ')));
+ BOOST_TEST(test_delimited("11 ", double_ | int_(11), v, char_(' ')));
+ BOOST_TEST(!test_delimited("", char_ | int_, v, char_(' ')));
+ }
+
return boost::report_errors();
}
Added: trunk/libs/spirit/test/karma/and_attribute.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/and_attribute.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,27 @@
+// Copyright (c) 2001-2007 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>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_operator.hpp>
+
+#include <iostream>
+#include "test.hpp"
+
+int
+main()
+{
+ using namespace spirit_test;
+ using namespace boost::spirit;
+
+ {
+ BOOST_TEST(test("1", int_(1) << &(int_(2) << &int_(3) << int_(4))));
+ }
+
+ return boost::report_errors();
+}
Modified: trunk/libs/spirit/test/karma/binary.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/binary.cpp (original)
+++ trunk/libs/spirit/test/karma/binary.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -6,7 +6,6 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/karma_binary.hpp>
#include <boost/spirit/include/karma_generate.hpp>
@@ -20,11 +19,10 @@
{
using namespace boost::spirit;
using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
{ // test native endian binaries
#ifdef BOOST_LITTLE_ENDIAN
- BOOST_TEST(binary_test("\x01", 1, byte, 0x01));
+ BOOST_TEST(binary_test("\x01", 1, byte_, 0x01));
BOOST_TEST(binary_test("\x01\x02", 2, word, 0x0201));
BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword, 0x04030201));
#ifdef BOOST_HAS_LONG_LONG
@@ -32,7 +30,7 @@
0x0807060504030201LL));
#endif
- BOOST_TEST(binary_test_delimited("\x01\x00\x00\x00", 4, byte, 0x01, pad(4)));
+ BOOST_TEST(binary_test_delimited("\x01\x00\x00\x00", 4, byte_, 0x01, pad(4)));
BOOST_TEST(binary_test_delimited("\x01\x02\x00\x00", 4, word, 0x0201, pad(4)));
BOOST_TEST(binary_test_delimited("\x01\x02\x03\x04", 4, dword, 0x04030201, pad(4)));
#ifdef BOOST_HAS_LONG_LONG
@@ -42,7 +40,7 @@
#else // BOOST_LITTLE_ENDIAN
- BOOST_TEST(binary_test("\x01", 1, byte, 0x01));
+ BOOST_TEST(binary_test("\x01", 1, byte_, 0x01));
BOOST_TEST(binary_test("\x01\x02", 2, word, 0x0102));
BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword, 0x01020304));
#ifdef BOOST_HAS_LONG_LONG
@@ -50,7 +48,7 @@
0x0102030405060708LL));
#endif
- BOOST_TEST(binary_test_delimited("\x01\x00\x00\x00", 4, byte, 0x01, pad(4)));
+ BOOST_TEST(binary_test_delimited("\x01\x00\x00\x00", 4, byte_, 0x01, pad(4)));
BOOST_TEST(binary_test_delimited("\x01\x02\x00\x00", 4, word, 0x0102, pad(4)));
BOOST_TEST(binary_test_delimited("\x01\x02\x03\x04", 4, dword, 0x01020304, pad(4)));
#ifdef BOOST_HAS_LONG_LONG
@@ -62,7 +60,7 @@
{ // test native endian binaries
#ifdef BOOST_LITTLE_ENDIAN
- BOOST_TEST(binary_test("\x01", 1, byte(0x01)));
+ BOOST_TEST(binary_test("\x01", 1, byte_(0x01)));
BOOST_TEST(binary_test("\x01\x02", 2, word(0x0201)));
BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword(0x04030201)));
#ifdef BOOST_HAS_LONG_LONG
@@ -70,7 +68,7 @@
qword(0x0807060504030201LL)));
#endif
#else
- BOOST_TEST(binary_test("\x01", 1, byte(0x01)));
+ BOOST_TEST(binary_test("\x01", 1, byte_(0x01)));
BOOST_TEST(binary_test("\x01\x02", 2, word(0x0102)));
BOOST_TEST(binary_test("\x01\x02\x03\x04", 4, dword(0x01020304)));
#ifdef BOOST_HAS_LONG_LONG
@@ -86,6 +84,8 @@
#ifdef BOOST_HAS_LONG_LONG
BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, big_qword,
0x0102030405060708LL));
+ BOOST_TEST(binary_test_delimited("\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00",
+ 10, big_qword, 0x0102030405060708LL, pad(10)));
#endif
}
@@ -95,6 +95,8 @@
#ifdef BOOST_HAS_LONG_LONG
BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8,
big_qword(0x0102030405060708LL)));
+ BOOST_TEST(binary_test_delimited("\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00",
+ 10, big_qword(0x0102030405060708LL), pad(10)));
#endif
}
@@ -104,6 +106,8 @@
#ifdef BOOST_HAS_LONG_LONG
BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8, little_qword,
0x0807060504030201LL));
+ BOOST_TEST(binary_test_delimited("\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00",
+ 10, little_qword, 0x0807060504030201LL, pad(10)));
#endif
}
@@ -113,6 +117,8 @@
#ifdef BOOST_HAS_LONG_LONG
BOOST_TEST(binary_test("\x01\x02\x03\x04\x05\x06\x07\x08", 8,
little_qword(0x0807060504030201LL)));
+ BOOST_TEST(binary_test_delimited("\x01\x02\x03\x04\x05\x06\x07\x08\x00\x00",
+ 10, little_qword(0x0807060504030201LL), pad(10)));
#endif
}
Modified: trunk/libs/spirit/test/karma/case_handling.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/case_handling.cpp (original)
+++ trunk/libs/spirit/test/karma/case_handling.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -23,11 +23,9 @@
{
using namespace boost::spirit::ascii;
-
+
BOOST_TEST(test("x", lower['X']));
BOOST_TEST(test("x", lower['x']));
- BOOST_TEST(test(L"x", lower[L'X']));
- BOOST_TEST(test(L"x", lower[L'x']));
BOOST_TEST(test("x", lower[char_], 'X'));
BOOST_TEST(test("x", lower[char_], 'x'));
@@ -36,141 +34,225 @@
BOOST_TEST(test(" ", lower[space]));
BOOST_TEST(test("\t", lower[space], '\t'));
- BOOST_TEST(test("\t", lower[space('\t')]));
-
+
BOOST_TEST(test("x", lower[lower['X']]));
BOOST_TEST(test("x", lower[lower['x']]));
- BOOST_TEST(test(L"x", lower[lower[L'X']]));
- BOOST_TEST(test(L"x", lower[lower[L'x']]));
BOOST_TEST(test("x", lower[lower[char_]], 'X'));
BOOST_TEST(test("x", lower[lower[char_]], 'x'));
BOOST_TEST(test("x", lower[lower[char_('X')]]));
BOOST_TEST(test("x", lower[lower[char_('x')]]));
-
+
BOOST_TEST(test(" ", lower[lower[space]]));
BOOST_TEST(test("\t", lower[lower[space]], '\t'));
- BOOST_TEST(test("\t", lower[lower[space('\t')]]));
BOOST_TEST(test("X", upper[lower['X']]));
BOOST_TEST(test("X", upper[lower['x']]));
- BOOST_TEST(test(L"X", upper[lower[L'X']]));
- BOOST_TEST(test(L"X", upper[lower[L'x']]));
BOOST_TEST(test("X", upper[lower[char_]], 'X'));
BOOST_TEST(test("X", upper[lower[char_]], 'x'));
BOOST_TEST(test("X", upper[lower[char_('X')]]));
BOOST_TEST(test("X", upper[lower[char_('x')]]));
-
+
BOOST_TEST(test(" ", upper[lower[space]]));
BOOST_TEST(test("\t", upper[lower[space]], '\t'));
- BOOST_TEST(test("\t", upper[lower[space('\t')]]));
BOOST_TEST(test("X", upper['X']));
BOOST_TEST(test("X", upper['x']));
- BOOST_TEST(test(L"X", upper[L'X']));
- BOOST_TEST(test(L"X", upper[L'x']));
BOOST_TEST(test("X", upper[char_], 'X'));
BOOST_TEST(test("X", upper[char_], 'x'));
BOOST_TEST(test("X", upper[char_('X')]));
BOOST_TEST(test("X", upper[char_('x')]));
-
+
BOOST_TEST(test(" ", upper[space]));
BOOST_TEST(test("\t", upper[space], '\t'));
- BOOST_TEST(test("\t", upper[space('\t')]));
BOOST_TEST(test("x", lower[upper['X']]));
BOOST_TEST(test("x", lower[upper['x']]));
- BOOST_TEST(test(L"x", lower[upper[L'X']]));
- BOOST_TEST(test(L"x", lower[upper[L'x']]));
BOOST_TEST(test("x", lower[upper[char_]], 'X'));
BOOST_TEST(test("x", lower[upper[char_]], 'x'));
BOOST_TEST(test("x", lower[upper[char_('X')]]));
BOOST_TEST(test("x", lower[upper[char_('x')]]));
-
+
BOOST_TEST(test(" ", lower[upper[space]]));
BOOST_TEST(test("\t", lower[upper[space]], '\t'));
- BOOST_TEST(test("\t", lower[upper[space('\t')]]));
BOOST_TEST(test("X", upper[upper['X']]));
BOOST_TEST(test("X", upper[upper['x']]));
- BOOST_TEST(test(L"X", upper[upper[L'X']]));
- BOOST_TEST(test(L"X", upper[upper[L'x']]));
BOOST_TEST(test("X", upper[upper[char_]], 'X'));
BOOST_TEST(test("X", upper[upper[char_]], 'x'));
BOOST_TEST(test("X", upper[upper[char_('X')]]));
BOOST_TEST(test("X", upper[upper[char_('x')]]));
-
+
BOOST_TEST(test(" ", upper[upper[space]]));
BOOST_TEST(test("\t", upper[upper[space]], '\t'));
- BOOST_TEST(test("\t", upper[upper[space('\t')]]));
+ }
+
+ {
+ using namespace boost::spirit::standard_wide;
+
+ BOOST_TEST(test(L"x", lower[L'X']));
+ BOOST_TEST(test(L"x", lower[L'x']));
+
+ BOOST_TEST(test(L"x", lower[char_], L'X'));
+ BOOST_TEST(test(L"x", lower[char_], L'x'));
+ BOOST_TEST(test(L"x", lower[char_(L'X')]));
+ BOOST_TEST(test(L"x", lower[char_(L'x')]));
+
+ BOOST_TEST(test(L" ", lower[space]));
+ BOOST_TEST(test(L"\t", lower[space], L'\t'));
+
+ BOOST_TEST(test(L"x", lower[lower[L'X']]));
+ BOOST_TEST(test(L"x", lower[lower[L'x']]));
+
+ BOOST_TEST(test(L"x", lower[lower[char_]], L'X'));
+ BOOST_TEST(test(L"x", lower[lower[char_]], L'x'));
+ BOOST_TEST(test(L"x", lower[lower[char_(L'X')]]));
+ BOOST_TEST(test(L"x", lower[lower[char_(L'x')]]));
+
+ BOOST_TEST(test(L" ", lower[lower[space]]));
+ BOOST_TEST(test(L"\t", lower[lower[space]], L'\t'));
+
+ BOOST_TEST(test(L"X", upper[lower[L'X']]));
+ BOOST_TEST(test(L"X", upper[lower[L'x']]));
+
+ BOOST_TEST(test(L"X", upper[lower[char_]], L'X'));
+ BOOST_TEST(test(L"X", upper[lower[char_]], L'x'));
+ BOOST_TEST(test(L"X", upper[lower[char_(L'X')]]));
+ BOOST_TEST(test(L"X", upper[lower[char_(L'x')]]));
+
+ BOOST_TEST(test(L" ", upper[lower[space]]));
+ BOOST_TEST(test(L"\t", upper[lower[space]], L'\t'));
+
+ BOOST_TEST(test(L"X", upper[L'X']));
+ BOOST_TEST(test(L"X", upper[L'x']));
+
+ BOOST_TEST(test(L"X", upper[char_], L'X'));
+ BOOST_TEST(test(L"X", upper[char_], L'x'));
+ BOOST_TEST(test(L"X", upper[char_(L'X')]));
+ BOOST_TEST(test(L"X", upper[char_(L'x')]));
+
+ BOOST_TEST(test(L" ", upper[space]));
+ BOOST_TEST(test(L"\t", upper[space], L'\t'));
+
+ BOOST_TEST(test(L"x", lower[upper[L'X']]));
+ BOOST_TEST(test(L"x", lower[upper[L'x']]));
+
+ BOOST_TEST(test(L"x", lower[upper[char_]], L'X'));
+ BOOST_TEST(test(L"x", lower[upper[char_]], L'x'));
+ BOOST_TEST(test(L"x", lower[upper[char_(L'X')]]));
+ BOOST_TEST(test(L"x", lower[upper[char_(L'x')]]));
+
+ BOOST_TEST(test(L" ", lower[upper[space]]));
+ BOOST_TEST(test(L"\t", lower[upper[space]], L'\t'));
+
+ BOOST_TEST(test(L"X", upper[upper[L'X']]));
+ BOOST_TEST(test(L"X", upper[upper[L'x']]));
+
+ BOOST_TEST(test(L"X", upper[upper[char_]], L'X'));
+ BOOST_TEST(test(L"X", upper[upper[char_]], L'x'));
+ BOOST_TEST(test(L"X", upper[upper[char_(L'X')]]));
+ BOOST_TEST(test(L"X", upper[upper[char_(L'x')]]));
+
+ BOOST_TEST(test(L" ", upper[upper[space]]));
+ BOOST_TEST(test(L"\t", upper[upper[space]], L'\t'));
+ }
+
+ {
+ using namespace boost::spirit::iso8859_1;
+
+ BOOST_TEST(test("ä", lower['Ä']));
+ BOOST_TEST(test("ä", lower['ä']));
+
+ BOOST_TEST(test("Ä", upper['Ä']));
+ BOOST_TEST(test("Ä", upper['ä']));
}
{
using namespace boost::spirit::ascii;
-
+
BOOST_TEST(test("a1- ", lower["a1- "]));
BOOST_TEST(test("a1- ", lower["a1- "]));
BOOST_TEST(test("a1- ", lower["a1- "]));
BOOST_TEST(test("a1- ", lower["A1- "]));
-
- BOOST_TEST(test("a1- ", lower[lit], "a1- "));
- BOOST_TEST(test("a1- ", lower[lit], "A1- "));
+
+ BOOST_TEST(test("a1- ", lower[string], "a1- "));
+ BOOST_TEST(test("a1- ", lower[string], "A1- "));
BOOST_TEST(test("a1- ", lower[lit("a1- ")]));
BOOST_TEST(test("a1- ", lower[lit("A1- ")]));
+ BOOST_TEST(test("a1- ", lower[string("a1- ")]));
+ BOOST_TEST(test("a1- ", lower[string("A1- ")]));
BOOST_TEST(test("a1- ", lower[lower["a1- "]]));
BOOST_TEST(test("a1- ", lower[lower["a1- "]]));
BOOST_TEST(test("a1- ", lower[lower["a1- "]]));
BOOST_TEST(test("a1- ", lower[lower["A1- "]]));
-
- BOOST_TEST(test("a1- ", lower[lower[lit]], "a1- "));
- BOOST_TEST(test("a1- ", lower[lower[lit]], "A1- "));
+
+ BOOST_TEST(test("a1- ", lower[lower[string]], "a1- "));
+ BOOST_TEST(test("a1- ", lower[lower[string]], "A1- "));
BOOST_TEST(test("a1- ", lower[lower[lit("a1- ")]]));
BOOST_TEST(test("a1- ", lower[lower[lit("A1- ")]]));
-
+ BOOST_TEST(test("a1- ", lower[lower[string("a1- ")]]));
+ BOOST_TEST(test("a1- ", lower[lower[string("A1- ")]]));
+
BOOST_TEST(test("A1- ", upper[lower["a1- "]]));
BOOST_TEST(test("A1- ", upper[lower["a1- "]]));
BOOST_TEST(test("A1- ", upper[lower["a1- "]]));
BOOST_TEST(test("A1- ", upper[lower["A1- "]]));
-
- BOOST_TEST(test("A1- ", upper[lower[lit]], "a1- "));
- BOOST_TEST(test("A1- ", upper[lower[lit]], "A1- "));
+
+ BOOST_TEST(test("A1- ", upper[lower[string]], "a1- "));
+ BOOST_TEST(test("A1- ", upper[lower[string]], "A1- "));
BOOST_TEST(test("A1- ", upper[lower[lit("a1- ")]]));
BOOST_TEST(test("A1- ", upper[lower[lit("A1- ")]]));
-
+ BOOST_TEST(test("A1- ", upper[lower[string("a1- ")]]));
+ BOOST_TEST(test("A1- ", upper[lower[string("A1- ")]]));
+
BOOST_TEST(test("A1- ", upper["a1- "]));
BOOST_TEST(test("A1- ", upper["a1- "]));
BOOST_TEST(test("A1- ", upper["a1- "]));
BOOST_TEST(test("A1- ", upper["A1- "]));
-
- BOOST_TEST(test("A1- ", upper[lit], "a1- "));
- BOOST_TEST(test("A1- ", upper[lit], "A1- "));
+
+ BOOST_TEST(test("A1- ", upper[string], "a1- "));
+ BOOST_TEST(test("A1- ", upper[string], "A1- "));
BOOST_TEST(test("A1- ", upper[lit("a1- ")]));
BOOST_TEST(test("A1- ", upper[lit("A1- ")]));
-
+
BOOST_TEST(test("a1- ", lower[upper["a1- "]]));
BOOST_TEST(test("a1- ", lower[upper["a1- "]]));
BOOST_TEST(test("a1- ", lower[upper["a1- "]]));
BOOST_TEST(test("a1- ", lower[upper["A1- "]]));
-
- BOOST_TEST(test("a1- ", lower[upper[lit]], "a1- "));
- BOOST_TEST(test("a1- ", lower[upper[lit]], "A1- "));
+
+ BOOST_TEST(test("a1- ", lower[upper[string]], "a1- "));
+ BOOST_TEST(test("a1- ", lower[upper[string]], "A1- "));
BOOST_TEST(test("a1- ", lower[upper[lit("a1- ")]]));
BOOST_TEST(test("a1- ", lower[upper[lit("A1- ")]]));
-
+ BOOST_TEST(test("a1- ", lower[upper[string("a1- ")]]));
+ BOOST_TEST(test("a1- ", lower[upper[string("A1- ")]]));
+
BOOST_TEST(test("A1- ", upper[upper["a1- "]]));
BOOST_TEST(test("A1- ", upper[upper["a1- "]]));
BOOST_TEST(test("A1- ", upper[upper["a1- "]]));
BOOST_TEST(test("A1- ", upper[upper["A1- "]]));
-
- BOOST_TEST(test("A1- ", upper[upper[lit]], "a1- "));
- BOOST_TEST(test("A1- ", upper[upper[lit]], "A1- "));
+
+ BOOST_TEST(test("A1- ", upper[upper[string]], "a1- "));
+ BOOST_TEST(test("A1- ", upper[upper[string]], "A1- "));
BOOST_TEST(test("A1- ", upper[upper[lit("a1- ")]]));
BOOST_TEST(test("A1- ", upper[upper[lit("A1- ")]]));
+ BOOST_TEST(test("A1- ", upper[upper[string("a1- ")]]));
+ BOOST_TEST(test("A1- ", upper[upper[string("A1- ")]]));
+ }
+
+ {
+ using namespace boost::spirit::iso8859_1;
+
+ BOOST_TEST(test("ää", lower["Ää"]));
+ BOOST_TEST(test("ää", lower["Ää"]));
+
+ BOOST_TEST(test("ÄÄ", upper["Ää"]));
+ BOOST_TEST(test("ÄÄ", upper["Ää"]));
}
return boost::report_errors();
Modified: trunk/libs/spirit/test/karma/center_alignment.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/center_alignment.cpp (original)
+++ trunk/libs/spirit/test/karma/center_alignment.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -17,13 +17,13 @@
#include "test.hpp"
-using namespace spirit_test;
-
///////////////////////////////////////////////////////////////////////////////
int
main()
{
+ using namespace spirit_test;
using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
{
BOOST_TEST(test(" x ", center[char_('x')]));
@@ -45,18 +45,21 @@
BOOST_TEST(test(" x ", center(11)[char_('x')]));
BOOST_TEST(test(" abc ", center[lit("abc")]));
- BOOST_TEST(test(" abc ", center[lit], "abc"));
+ BOOST_TEST(test(" abc ", center[string], "abc"));
BOOST_TEST(test(" abc ", center(10)[lit("abc")]));
- BOOST_TEST(test(" abc ", center(10)[lit], "abc"));
+ BOOST_TEST(test(" abc ", center(10)[string], "abc"));
BOOST_TEST(test(" abc ", center(10)["abc"]));
+ BOOST_TEST(test(" abc ", center(11)[lit("abc")]));
+ BOOST_TEST(test(" ab ", center(11)[lit("ab")]));
+
BOOST_TEST(test("****abc***", center(10, char_('*'))[lit("abc")]));
- BOOST_TEST(test("****abc***", center(10, '*')[lit], "abc"));
+ BOOST_TEST(test("****abc***", center(10, '*')[string], "abc"));
BOOST_TEST(test("****abc***", center(10, '*')["abc"]));
BOOST_TEST(test("****abc***", center(char_('*'))[lit("abc")]));
- BOOST_TEST(test("****abc***", center(char_('*'))[lit], "abc"));
+ BOOST_TEST(test("****abc***", center(char_('*'))[string], "abc"));
BOOST_TEST(test("****abc***", center(char_('*'))["abc"]));
BOOST_TEST(test(" abc ", center(11)[lit("abc")]));
Modified: trunk/libs/spirit/test/karma/char.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/char.cpp (original)
+++ trunk/libs/spirit/test/karma/char.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -8,7 +8,6 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_generate.hpp>
#include <boost/spirit/include/karma_action.hpp>
@@ -27,50 +26,59 @@
{
using namespace boost::spirit;
using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
-
+
{
using namespace boost::spirit::ascii;
-
- BOOST_TEST(test(" ", space));
- BOOST_TEST(test(L" ", space));
- BOOST_TEST(!test("\t", space));
- BOOST_TEST(!test(L"\t", space));
-
- BOOST_TEST(test(" ", space(' ')));
- BOOST_TEST(test(L" ", space(L' ')));
- BOOST_TEST(test("\t", space('\t')));
- BOOST_TEST(test(L"\t", space(L'\t')));
-
- BOOST_TEST(test(" ", space(' '), '\t'));
- BOOST_TEST(test(L" ", space(' '), L'\t'));
- BOOST_TEST(test("\t", space('\t'), ' '));
- BOOST_TEST(test(L"\t", space('\t'), L' '));
-
- BOOST_TEST(test(" ", space, ' '));
- BOOST_TEST(test(L" ", space, L' '));
- BOOST_TEST(test("\t", space, '\t'));
- BOOST_TEST(test(L"\t", space, L'\t'));
- }
-
- {
+
BOOST_TEST(test("x", 'x'));
BOOST_TEST(test(L"x", L'x'));
BOOST_TEST(!test("x", 'y'));
BOOST_TEST(!test(L"x", L'y'));
-
+
+ BOOST_TEST(test("x", "x"));
+ BOOST_TEST(test(L"x", L"x"));
+ BOOST_TEST(!test("x", "y"));
+ BOOST_TEST(!test(L"x", L"y"));
+
BOOST_TEST(test("x", char_, 'x'));
BOOST_TEST(test(L"x", char_, L'x'));
BOOST_TEST(!test("x", char_, 'y'));
BOOST_TEST(!test(L"x", char_, L'y'));
-
+
BOOST_TEST(test("x", char_('x')));
BOOST_TEST(!test("x", char_('y')));
+
+ BOOST_TEST(test("x", char_("x")));
+
+#if defined(KARMA_FAIL_COMPILATION)
+ BOOST_TEST(test("x", char_)); // anychar without a parameter doesn't make any sense
+#endif
+ }
+
+ {
+ using namespace boost::spirit::standard_wide;
+
+ BOOST_TEST(test(L"x", 'x'));
+ BOOST_TEST(test(L"x", L'x'));
+ BOOST_TEST(!test(L"x", 'y'));
+ BOOST_TEST(!test(L"x", L'y'));
+
+ BOOST_TEST(test(L"x", "x"));
+ BOOST_TEST(test(L"x", L"x"));
+ BOOST_TEST(!test(L"x", "y"));
+ BOOST_TEST(!test(L"x", L"y"));
+
+ BOOST_TEST(test(L"x", char_, 'x'));
+ BOOST_TEST(test(L"x", char_, L'x'));
+ BOOST_TEST(!test(L"x", char_, 'y'));
+ BOOST_TEST(!test(L"x", char_, L'y'));
+
+ BOOST_TEST(test(L"x", char_('x')));
BOOST_TEST(test(L"x", char_(L'x')));
+ BOOST_TEST(!test(L"x", char_('y')));
BOOST_TEST(!test(L"x", char_(L'y')));
-// BOOST_TEST(test("x", char_("x")));
-// BOOST_TEST(test(L"x", char_(L"x")));
+ BOOST_TEST(test(L"x", char_(L"x")));
#if defined(KARMA_FAIL_COMPILATION)
BOOST_TEST(test("x", char_)); // anychar without a parameter doesn't make any sense
@@ -78,74 +86,95 @@
}
{
- BOOST_TEST(test(L"x", L'x'));
- BOOST_TEST(test(L"x", 'x'));
+ using namespace boost::spirit::ascii;
- BOOST_TEST(test(L"x", wchar, L'x'));
- BOOST_TEST(test(L"x", wchar, 'x'));
+ BOOST_TEST(test(" ", space));
+ BOOST_TEST(test(L" ", space));
+ BOOST_TEST(!test("\t", space));
+ BOOST_TEST(!test(L"\t", space));
+
+ BOOST_TEST(test(" ", space, ' '));
+ BOOST_TEST(test(L" ", space, L' '));
+ BOOST_TEST(test("\t", space, '\t'));
+ BOOST_TEST(test(L"\t", space, L'\t'));
+ }
+
+ {
+ using namespace boost::spirit::standard_wide;
- BOOST_TEST(test(L"x", wchar(L'x')));
- BOOST_TEST(test(L"x", wchar('x')));
+ BOOST_TEST(test(" ", space));
+ BOOST_TEST(test(L" ", space));
+ BOOST_TEST(!test("\t", space));
+ BOOST_TEST(!test(L"\t", space));
+
+ BOOST_TEST(test(" ", space, ' '));
+ BOOST_TEST(test(L" ", space, L' '));
+ BOOST_TEST(test("\t", space, '\t'));
+ BOOST_TEST(test(L"\t", space, L'\t'));
}
-
+
{
using namespace boost::spirit::ascii;
-
+
BOOST_TEST(test_delimited("x ", 'x', ' '));
BOOST_TEST(test_delimited(L"x ", L'x', L' '));
BOOST_TEST(!test_delimited("x ", 'y', ' '));
BOOST_TEST(!test_delimited(L"x ", L'y', L' '));
- BOOST_TEST(test_delimited("x ", 'x', space));
- BOOST_TEST(test_delimited(L"x ", L'x', space(L' ')));
- BOOST_TEST(!test_delimited("x ", 'y', space));
- BOOST_TEST(!test_delimited(L"x ", L'y', space(L' ')));
-
- BOOST_TEST(test_delimited("x ", char_, 'x', space));
- BOOST_TEST(test_delimited(L"x ", char_, L'x', space(L' ')));
- BOOST_TEST(!test_delimited("x ", char_, 'y', space));
- BOOST_TEST(!test_delimited(L"x ", char_, L'y', space(L' ')));
-
- BOOST_TEST(test_delimited("x ", char_('x'), space));
- BOOST_TEST(!test_delimited("x ", char_('y'), space(L' ')));
- BOOST_TEST(test_delimited(L"x ", char_(L'x'), space));
- BOOST_TEST(!test_delimited(L"x ", char_(L'y'), space(L' ')));
-
-// BOOST_TEST(test_delimited("x ", char_("x"), space));
+ BOOST_TEST(test_delimited("x ", 'x', ' '));
+ BOOST_TEST(test_delimited(L"x ", L'x', L' '));
+ BOOST_TEST(!test_delimited("x ", 'y', ' '));
+ BOOST_TEST(!test_delimited(L"x ", L'y', L' '));
-#if defined(KARMA_FAIL_COMPILATION)
- BOOST_TEST(test_delimited("x ", char_, space)); // anychar without a parameter doesn't make any sense
-#endif
- }
-
- {
- BOOST_TEST(test_delimited(L"x ", L'x', wchar(' ')));
- BOOST_TEST(test_delimited(L"x ", 'x', wchar(' ')));
+ BOOST_TEST(test_delimited("x ", char_, 'x', ' '));
+ BOOST_TEST(test_delimited(L"x ", char_, L'x', L' '));
+ BOOST_TEST(!test_delimited("x ", char_, 'y', ' '));
+ BOOST_TEST(!test_delimited(L"x ", char_, L'y', L' '));
+
+ BOOST_TEST(test_delimited("x ", char_('x'), ' '));
+ BOOST_TEST(!test_delimited("x ", char_('y'), ' '));
- BOOST_TEST(test_delimited(L"x ", wchar, L'x', wchar(' ')));
- BOOST_TEST(test_delimited(L"x ", wchar, 'x', wchar(' ')));
+ BOOST_TEST(test_delimited("x ", char_("x"), ' '));
- BOOST_TEST(test_delimited(L"x ", wchar(L'x'), wchar(' ')));
- BOOST_TEST(test_delimited(L"x ", wchar('x'), wchar(' ')));
-
#if defined(KARMA_FAIL_COMPILATION)
- BOOST_TEST(test_delimited("x ", char_, space)); // anychar without a parameter doesn't make any sense
+ BOOST_TEST(test_delimited("x ", char_, ' ')); // anychar without a parameter doesn't make any sense
#endif
}
-
+
+ { // pre-delimiting
+ {
+ std::string generated;
+ std::back_insert_iterator<std::string> it(generated);
+ BOOST_TEST(karma::generate_delimited(it, '_', '^'
+ , karma::delimit_flag::predelimit));
+ BOOST_TEST(generated == "^_^");
+ }
+ {
+ using namespace boost::spirit::standard_wide;
+ std::basic_string<wchar_t> generated;
+ std::back_insert_iterator<std::basic_string<wchar_t> > it(generated);
+ BOOST_TEST(karma::generate_delimited(it, char_, L'.'
+ , karma::delimit_flag::predelimit, L'x'));
+ BOOST_TEST(generated == L".x.");
+ }
+ }
+
// action tests
{
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test("x", char_[_1 = val('x')]));
- BOOST_TEST(test(L"x", wchar[_1 = val(L'x')]));
BOOST_TEST(!test("x", char_[_1 = val('y')]));
- BOOST_TEST(!test(L"x", wchar[_1 = val(L'y')]));
}
{ // lazy chars
+ namespace ascii = boost::spirit::ascii;
+ namespace wide = boost::spirit::standard_wide;
using namespace boost::phoenix;
- BOOST_TEST((test("x", char_(val('x')))));
- BOOST_TEST((test(L"x", char_(val(L'x')))));
+
+ BOOST_TEST((test("x", ascii::char_(val('x')))));
+ BOOST_TEST((test(L"x", wide::char_(val(L'x')))));
}
return boost::report_errors();
Modified: trunk/libs/spirit/test/karma/delimiter.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/delimiter.cpp (original)
+++ trunk/libs/spirit/test/karma/delimiter.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -22,7 +22,8 @@
main()
{
using namespace boost::spirit;
-
+ using namespace boost::spirit::ascii;
+
{
BOOST_TEST(test("a b ", delimit[char_('a') << 'b']));
BOOST_TEST(test("a*b*", delimit('*')[char_('a') << 'b']));
@@ -40,7 +41,7 @@
BOOST_TEST(test_delimited("a b*c*d ",
char_('a') << delimit('*')[char_('b') << 'c'] << 'd', char_(' ')));
}
-
+
{
BOOST_TEST(test("ab", verbatim[char_('a') << 'b']));
BOOST_TEST(test("abcd",
@@ -51,6 +52,15 @@
BOOST_TEST(test_delimited("a bc d ",
char_('a') << verbatim[char_('b') << 'c'] << 'd', char_(' ')));
}
-
+
+ {
+ // The doubled delimiters at the end are generated by the 'b' generator
+ // and the verbatim[] directive. Currently, there is no easy way to
+ // avoid this.
+ BOOST_TEST(test("a b ", delimit[verbatim[delimit[char_('a') << 'b']]]));
+ BOOST_TEST(test_delimited("a*b**",
+ verbatim[delimit[char_('a') << 'b']], char_('*')));
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/eps.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/eps.cpp (original)
+++ trunk/libs/spirit/test/karma/eps.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -5,7 +5,12 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
+
#include <boost/spirit/include/karma_auxiliary.hpp>
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <iostream>
@@ -14,19 +19,41 @@
int
main()
{
- using spirit_test::test;
+ using namespace spirit_test;
using namespace boost::spirit;
{
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test("", eps));
+ BOOST_TEST(test_delimited(" ", eps, space));
+
+ BOOST_TEST(!test("", !eps));
+ BOOST_TEST(!test_delimited(" ", !eps, space));
}
- { // test action
+ { // test direct argument
+ using namespace boost::phoenix;
+
+ BOOST_TEST(test("", eps(true)));
+ BOOST_TEST(!test("", eps(false)));
+ }
+ { // test action
using namespace boost::phoenix;
+
BOOST_TEST(test("", eps(val(true))));
BOOST_TEST(!test("", eps(val(false))));
}
+ { // test no delimiter when argument is false
+ using namespace boost::spirit::ascii;
+
+ std::string generated;
+ std::back_insert_iterator<std::string> outit(generated);
+ BOOST_TEST(!karma::generate_delimited(outit, eps(false), space));
+ BOOST_TEST(generated.empty());
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/format_manip.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/format_manip.cpp (original)
+++ trunk/libs/spirit/test/karma/format_manip.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -24,30 +24,20 @@
template <typename Char, typename Expr>
bool test(Char const *expected, Expr const& xpr)
{
- namespace spirit = boost::spirit;
- typedef
- spirit::traits::is_component<spirit::karma::domain, Expr>
- is_component;
-
- // report invalid expression error as early as possible
- BOOST_MPL_ASSERT_MSG(is_component::value,
- xpr_is_not_convertible_to_a_generator, ());
-
- typedef
- typename spirit::result_of::as_component<spirit::karma::domain, Expr>::type
- component;
- typedef typename component::director director;
-
- component c = spirit::as_component(spirit::karma::domain(), xpr);
+ // Report invalid expression error as early as possible.
+ // If you got an error_invalid_expression error message here,
+ // then the expression (expr) is not a valid spirit karma expression.
+ BOOST_SPIRIT_ASSERT_MATCH(boost::spirit::karma::domain, Expr)
std::ostringstream ostrm;
- ostrm << c;
+ ostrm << boost::spirit::compile<boost::spirit::karma::domain>(xpr);
return ostrm.good() && ostrm.str() == expected;
}
-template <typename Char, typename Expr, typename Parameter, typename Delimiter>
+template <typename Char, typename Expr, typename Copy, typename Delimiter
+ , typename Attribute>
bool test(Char const *expected,
- boost::spirit::karma::detail::format_manip<Expr, Parameter, Delimiter> const& fm)
+ boost::spirit::karma::detail::format_manip<Expr, Copy, Delimiter, Attribute> const& fm)
{
std::ostringstream ostrm;
ostrm << fm;
@@ -60,7 +50,6 @@
{
using namespace boost::spirit;
using namespace boost::spirit::ascii;
- using namespace boost::spirit::arg_names;
using namespace boost::spirit::karma;
namespace fusion = boost::fusion;
@@ -68,6 +57,9 @@
{
BOOST_TEST(test( "a",
+ char_('a')
+ ));
+ BOOST_TEST(test( "a",
char_[_1 = val('a')]
));
BOOST_TEST(test( "a",
@@ -80,10 +72,10 @@
format(char_, 'a')
));
BOOST_TEST(test( "a ",
- format_delimited(char_, 'a', space)
+ format_delimited(char_, space, 'a')
));
}
-
+
{
BOOST_TEST(test( "ab",
char_[_1 = val('a')] << char_[_1 = val('b')]
@@ -94,17 +86,17 @@
BOOST_TEST(test( "a b ",
format_delimited(char_[_1 = val('a')] << char_[_1 = val('b')], space)
));
-
+
fusion::vector<char, char> t('a', 'b');
BOOST_TEST(test( "ab",
format(char_ << char_, t)
));
BOOST_TEST(test( "a b ",
- format_delimited(char_ << char_, t, space)
+ format_delimited(char_ << char_, space, t)
));
}
-
+
{
BOOST_TEST(test( "abc",
char_[_1 = 'a'] << char_[_1 = 'b'] << char_[_1 = 'c']
@@ -122,7 +114,7 @@
format(char_ << char_ << char_, t)
));
BOOST_TEST(test( "a b c ",
- format_delimited(char_ << char_ << char_, t, space)
+ format_delimited(char_ << char_ << char_, space, t)
));
}
@@ -137,7 +129,7 @@
format(char_ << int_, t)
));
BOOST_TEST(test( "a 2 ",
- format_delimited(char_ << int_, t, space)
+ format_delimited(char_ << int_, space, t)
));
}
@@ -147,7 +139,7 @@
// output all elements of a vector
std::vector<char> v;
v += 'a', 'b', 'c';
-
+
BOOST_TEST(test( "abc",
(*char_)[_1 = v]
));
@@ -155,7 +147,7 @@
format(*char_, v)
));
BOOST_TEST(test( "a b c ",
- format_delimited(*char_, v, space)
+ format_delimited(*char_, space, v)
));
// output a comma separated list of vector elements
@@ -172,13 +164,13 @@
format(char_ % ',', v)
));
BOOST_TEST(test( "a , b , c ",
- format_delimited(char_ % ',', v, space)
+ format_delimited(char_ % ',', space, v)
));
// output all elements of a list
std::list<char> l;
l += 'a', 'b', 'c';
-
+
// BOOST_TEST(test( "abc",
// (*char_)[_1 = l]
// ));
@@ -192,7 +184,7 @@
format(*char_, l)
));
BOOST_TEST(test( "a b c ",
- format_delimited(*char_, l, space)
+ format_delimited(*char_, space, l)
));
}
Added: trunk/libs/spirit/test/karma/format_manip_attr.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/format_manip_attr.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,171 @@
+// Copyright (c) 2001-2009 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)
+
+//#define KARMA_FAIL_COMPILATION
+
+#define SPIRIT_ARGUMENTS_LIMIT 10
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_directive.hpp>
+#include <boost/spirit/include/karma_operator.hpp>
+#include <boost/spirit/include/karma_action.hpp>
+
+#include "test_manip_attr.hpp"
+
+using namespace spirit_test;
+
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ using namespace boost::spirit;
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test("1", char_, '1'));
+ BOOST_TEST(test("12", char_ << char_, '1', '2'));
+ BOOST_TEST(test("123", char_ << char_ << char_, '1', '2', '3'));
+ BOOST_TEST(test("1234"
+ , char_ << char_ << char_ << char_
+ , '1', '2', '3', '4'));
+ BOOST_TEST(test("12345"
+ , char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5'));
+ BOOST_TEST(test("123456"
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test("1234567"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test("12345678"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test("123456789"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test("1234567890"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test_delimited("1 ", char_, space, '1'));
+ BOOST_TEST(test_delimited("1 2 "
+ , char_ << char_, space, '1', '2'));
+ BOOST_TEST(test_delimited("1 2 3 "
+ , char_ << char_ << char_, space, '1', '2', '3'));
+ BOOST_TEST(test_delimited("1 2 3 4 "
+ , char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 "
+ , char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 "
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 8 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 8 9 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 8 9 0 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::karma::delimit_flag;
+
+ BOOST_TEST(test_predelimited(" 1 ", char_, space
+ , delimit_flag::predelimit, '1'));
+ BOOST_TEST(test_predelimited(" 1 2 "
+ , char_ << char_, space, delimit_flag::predelimit
+ , '1', '2'));
+ BOOST_TEST(test_predelimited(" 1 2 3 "
+ , char_ << char_ << char_, space
+ , delimit_flag::predelimit, '1', '2', '3'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 "
+ , char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit, '1', '2', '3', '4'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 "
+ , char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 "
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 8 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 8 9 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 8 9 0 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::karma::delimit_flag;
+
+ BOOST_TEST(test_predelimited("1 ", char_, space
+ , delimit_flag::dont_predelimit, '1'));
+ BOOST_TEST(test_predelimited("1 2 "
+ , char_ << char_, space, delimit_flag::dont_predelimit
+ , '1', '2'));
+ BOOST_TEST(test_predelimited("1 2 3 "
+ , char_ << char_ << char_, space
+ , delimit_flag::dont_predelimit, '1', '2', '3'));
+ BOOST_TEST(test_predelimited("1 2 3 4 "
+ , char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit, '1', '2', '3', '4'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 "
+ , char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 "
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 8 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 8 9 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 8 9 0 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ return boost::report_errors();
+}
+
Added: trunk/libs/spirit/test/karma/generate_attr.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/generate_attr.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,169 @@
+// Copyright (c) 2001-2009 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)
+
+//#define KARMA_FAIL_COMPILATION
+
+#define SPIRIT_ARGUMENTS_LIMIT 10
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_operator.hpp>
+#include <boost/spirit/include/karma_generate_attr.hpp>
+
+#include "test_attr.hpp"
+
+using namespace spirit_test;
+
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ using namespace boost::spirit;
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test("1", char_, '1'));
+ BOOST_TEST(test("12", char_ << char_, '1', '2'));
+ BOOST_TEST(test("123", char_ << char_ << char_, '1', '2', '3'));
+ BOOST_TEST(test("1234"
+ , char_ << char_ << char_ << char_
+ , '1', '2', '3', '4'));
+ BOOST_TEST(test("12345"
+ , char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5'));
+ BOOST_TEST(test("123456"
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test("1234567"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test("12345678"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test("123456789"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test("1234567890"
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test_delimited("1 ", char_, space, '1'));
+ BOOST_TEST(test_delimited("1 2 "
+ , char_ << char_, space, '1', '2'));
+ BOOST_TEST(test_delimited("1 2 3 "
+ , char_ << char_ << char_, space, '1', '2', '3'));
+ BOOST_TEST(test_delimited("1 2 3 4 "
+ , char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 "
+ , char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 "
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 8 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 8 9 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_delimited("1 2 3 4 5 6 7 8 9 0 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::karma::delimit_flag;
+
+ BOOST_TEST(test_predelimited(" 1 ", char_, space
+ , delimit_flag::predelimit, '1'));
+ BOOST_TEST(test_predelimited(" 1 2 "
+ , char_ << char_, space, delimit_flag::predelimit
+ , '1', '2'));
+ BOOST_TEST(test_predelimited(" 1 2 3 "
+ , char_ << char_ << char_, space
+ , delimit_flag::predelimit, '1', '2', '3'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 "
+ , char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit, '1', '2', '3', '4'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 "
+ , char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 "
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 8 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 8 9 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_predelimited(" 1 2 3 4 5 6 7 8 9 0 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::karma::delimit_flag;
+
+ BOOST_TEST(test_predelimited("1 ", char_, space
+ , delimit_flag::dont_predelimit, '1'));
+ BOOST_TEST(test_predelimited("1 2 "
+ , char_ << char_, space, delimit_flag::dont_predelimit
+ , '1', '2'));
+ BOOST_TEST(test_predelimited("1 2 3 "
+ , char_ << char_ << char_, space
+ , delimit_flag::dont_predelimit, '1', '2', '3'));
+ BOOST_TEST(test_predelimited("1 2 3 4 "
+ , char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit, '1', '2', '3', '4'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 "
+ , char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 "
+ , char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 8 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 8 9 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_predelimited("1 2 3 4 5 6 7 8 9 0 "
+ , char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_ << char_
+ , space, delimit_flag::dont_predelimit
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ return boost::report_errors();
+}
+
Modified: trunk/libs/spirit/test/karma/grammar.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/grammar.cpp (original)
+++ trunk/libs/spirit/test/karma/grammar.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -6,9 +6,6 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-// include this first to make rules have placeholders (e.g. r._1)
-#include <boost/spirit/include/support_argument.hpp>
-
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_string.hpp>
@@ -52,7 +49,6 @@
}
{ // direct access to the rules
-
num_list def;
BOOST_TEST(test_delimited("123 ", def.num1, space));
BOOST_TEST(test_delimited("123 , 456 , 789 ", def.start, 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 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -6,6 +6,7 @@
=============================================================================*/
#include <boost/config/warning_disable.hpp>
+
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_string.hpp>
@@ -19,29 +20,27 @@
using namespace boost::spirit::karma;
using namespace boost::spirit::ascii;
-struct num_list : grammar<char const*, rule<char const*> >
+typedef spirit_test::output_iterator<char>::type outiter_type;
+
+struct num_list : grammar<outiter_type, rule<outiter_type> >
{
- num_list()
+ num_list() : num_list::base_type(start)
{
- using boost::spirit::int_;
start = int_(1) << ',' << int_(0);
}
- rule<char const*, rule<char const*> > start;
+ rule<outiter_type, rule<outiter_type> > start;
};
-// this test must fail compiling
+// this test must fail compiling as the rule is used with an incompatible
+// delimiter type
int main()
{
- using boost::make_function_output_iterator;
- using spirit_test::make_string_appender;
-
std::string generated;
-
+
+ std::back_insert_iterator<std::string> outit(generated);
num_list def;
- bool r = generate_delimited(
- make_function_output_iterator(make_string_appender(generated)),
- make_generator(def), char_('%') << '\n');
+ bool r = generate_delimited(outit, def, char_('%') << '\n');
return 0;
}
Modified: trunk/libs/spirit/test/karma/int_numerics.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/int_numerics.cpp (original)
+++ trunk/libs/spirit/test/karma/int_numerics.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -12,14 +12,13 @@
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/bool.hpp>
+
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
-#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_numeric.hpp>
-#include <boost/spirit/include/karma_generate.hpp>
#include <boost/spirit/include/karma_directive.hpp>
#include <boost/spirit/include/karma_action.hpp>
@@ -36,24 +35,23 @@
{
using namespace boost::spirit;
using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
-
+
T minval = (std::numeric_limits<T>::min)();
T maxval = (std::numeric_limits<T>::max)();
-
+
std::string expected_minval = boost::lexical_cast<std::string>(minval);
std::string expected_maxval = boost::lexical_cast<std::string>(maxval);
-
+
// create a correct generator type from the given integer type
typedef typename
boost::mpl::if_<
boost::mpl::bool_<std::numeric_limits<T>::is_signed>,
- karma::int_spec<T>,
- karma::uint_spec<T>
+ karma::int_generator<T>,
+ karma::uint_generator<T>
>::type
- int_spec_type;
-
- int_spec_type const gen = int_spec_type();
+ int_generator_type;
+
+ int_generator_type const gen = int_generator_type();
BOOST_TEST(test(expected_maxval, gen, maxval));
BOOST_TEST(test(expected_minval, gen, minval));
@@ -76,10 +74,10 @@
main()
{
using namespace boost::spirit;
-
+
{
using namespace boost::spirit::ascii;
-
+
///////////////////////////////////////////////////////////////////////
// this is currently ambiguous with character literals
// BOOST_TEST(test("0", 0));
@@ -136,11 +134,24 @@
BOOST_TEST(test_delimited("-123 ", upper[int_(-123)], char_(' ')));
}
+ { // lazy numerics
+ using namespace boost::phoenix;
+
+ BOOST_TEST(test("0", int_(val(0))));
+ BOOST_TEST(test("123", int_(val(123))));
+ BOOST_TEST(test("-123", int_(val(-123))));
+
+ int i1 = 0, i2 = 123, i3 = -123;
+ BOOST_TEST(test("0", int_(ref(i1))));
+ BOOST_TEST(test("123", int_(ref(i2))));
+ BOOST_TEST(test("-123", int_(ref(i3))));
+ }
+
{
using namespace boost::spirit::ascii;
-
- karma::int_spec<int, 10, true> const signed_int =
- karma::int_spec<int, 10, true>();
+
+ karma::int_generator<int, 10, true> const signed_int =
+ karma::int_generator<int, 10, true>();
///////////////////////////////////////////////////////////////////////
BOOST_TEST(test(" 0", signed_int, 0));
@@ -191,54 +202,64 @@
BOOST_TEST(test_delimited(" 0 ", upper[signed_int(0)], char_(' ')));
BOOST_TEST(test_delimited("+123 ", upper[signed_int(123)], char_(' ')));
BOOST_TEST(test_delimited("-123 ", upper[signed_int(-123)], char_(' ')));
+
+ using namespace boost::phoenix;
+
+ BOOST_TEST(test(" 0", signed_int(val(0))));
+ BOOST_TEST(test("+123", signed_int(val(123))));
+ BOOST_TEST(test("-123", signed_int(val(-123))));
+
+ int i1 = 0, i2 = 123, i3 = -123;
+ BOOST_TEST(test(" 0", signed_int(ref(i1))));
+ BOOST_TEST(test("+123", signed_int(ref(i2))));
+ BOOST_TEST(test("-123", signed_int(ref(i3))));
}
{
///////////////////////////////////////////////////////////////////////
- using boost::spirit::uint_;
using namespace boost::spirit::ascii;
-
+
BOOST_TEST(test("1234", uint_, 1234));
BOOST_TEST(test("ff", hex, 0xff));
BOOST_TEST(test("1234", oct, 01234));
BOOST_TEST(test("11110000", bin, 0xf0));
-
+
BOOST_TEST(test_delimited("1234 ", uint_, 1234, char_(' ')));
BOOST_TEST(test_delimited("ff ", hex, 0xff, char_(' ')));
BOOST_TEST(test_delimited("1234 ", oct, 01234, char_(' ')));
BOOST_TEST(test_delimited("11110000 ", bin, 0xf0, char_(' ')));
-
+
BOOST_TEST(test("1234", lower[uint_], 1234));
BOOST_TEST(test("ff", lower[hex], 0xff));
BOOST_TEST(test("1234", lower[oct], 01234));
BOOST_TEST(test("11110000", lower[bin], 0xf0));
-
+
BOOST_TEST(test_delimited("1234 ", lower[uint_], 1234, char_(' ')));
BOOST_TEST(test_delimited("ff ", lower[hex], 0xff, char_(' ')));
BOOST_TEST(test_delimited("1234 ", lower[oct], 01234, char_(' ')));
BOOST_TEST(test_delimited("11110000 ", lower[bin], 0xf0, char_(' ')));
-
+
BOOST_TEST(test("1234", upper[uint_], 1234));
BOOST_TEST(test("FF", upper[hex], 0xff));
BOOST_TEST(test("1234", upper[oct], 01234));
BOOST_TEST(test("11110000", upper[bin], 0xf0));
-
+
BOOST_TEST(test_delimited("1234 ", upper[uint_], 1234, char_(' ')));
BOOST_TEST(test_delimited("FF ", upper[hex], 0xff, char_(' ')));
BOOST_TEST(test_delimited("1234 ", upper[oct], 01234, char_(' ')));
BOOST_TEST(test_delimited("11110000 ", upper[bin], 0xf0, char_(' ')));
-
+
// no generator transformation should occur for uint_'s
BOOST_TEST(test("1234", upper[upper[uint_]], 1234));
BOOST_TEST(test("1234", upper[lower[uint_]], 1234));
BOOST_TEST(test("1234", lower[upper[uint_]], 1234));
BOOST_TEST(test("1234", lower[lower[uint_]], 1234));
-
+
BOOST_TEST(test_delimited("1234 ", upper[upper[uint_]], 1234, char_(' ')));
BOOST_TEST(test_delimited("1234 ", upper[lower[uint_]], 1234, char_(' ')));
BOOST_TEST(test_delimited("1234 ", lower[upper[uint_]], 1234, char_(' ')));
BOOST_TEST(test_delimited("1234 ", lower[lower[uint_]], 1234, char_(' ')));
-
+
BOOST_TEST(test("FF", upper[upper[hex]], 0xff));
BOOST_TEST(test("FF", upper[lower[hex]], 0xff));
BOOST_TEST(test("ff", lower[upper[hex]], 0xff));
@@ -254,7 +275,7 @@
BOOST_TEST(test("ff", hex(0xff)));
BOOST_TEST(test("1234", oct(01234)));
BOOST_TEST(test("11110000", bin(0xf0)));
-
+
BOOST_TEST(test_delimited("1234 ", uint_(1234), char_(' ')));
BOOST_TEST(test_delimited("ff ", hex(0xff), char_(' ')));
BOOST_TEST(test_delimited("1234 ", oct(01234), char_(' ')));
@@ -264,22 +285,22 @@
BOOST_TEST(test("ff", lower[hex(0xff)]));
BOOST_TEST(test("1234", lower[oct(01234)]));
BOOST_TEST(test("11110000", lower[bin(0xf0)]));
-
+
BOOST_TEST(test_delimited("1234 ", lower[uint_(1234)], char_(' ')));
BOOST_TEST(test_delimited("ff ", lower[hex(0xff)], char_(' ')));
BOOST_TEST(test_delimited("1234 ", lower[oct(01234)], char_(' ')));
BOOST_TEST(test_delimited("11110000 ", lower[bin(0xf0)], char_(' ')));
-
+
BOOST_TEST(test("1234", upper[uint_(1234)]));
BOOST_TEST(test("FF", upper[hex(0xff)]));
BOOST_TEST(test("1234", upper[oct(01234)]));
BOOST_TEST(test("11110000", upper[bin(0xf0)]));
-
+
BOOST_TEST(test_delimited("1234 ", upper[uint_(1234)], char_(' ')));
BOOST_TEST(test_delimited("FF ", upper[hex(0xff)], char_(' ')));
BOOST_TEST(test_delimited("1234 ", upper[oct(01234)], char_(' ')));
BOOST_TEST(test_delimited("11110000 ", upper[bin(0xf0)], char_(' ')));
-
+
BOOST_TEST(test("FF", upper[upper[hex(0xff)]]));
BOOST_TEST(test("FF", upper[lower[hex(0xff)]]));
BOOST_TEST(test("ff", lower[upper[hex(0xff)]]));
@@ -301,7 +322,7 @@
long, unsigned long
> integer_types;
boost::mpl::for_each<integer_types>(test_minmax());
-
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/kleene.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/kleene.cpp (original)
+++ trunk/libs/spirit/test/karma/kleene.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -8,8 +8,6 @@
#include <boost/assign/std/vector.hpp>
-#include <boost/spirit/include/support_argument.hpp>
-// #include <boost/spirit/include/support_pack.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_string.hpp>
#include <boost/spirit/include/karma_numeric.hpp>
@@ -17,7 +15,6 @@
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_action.hpp>
#include <boost/fusion/include/vector.hpp>
-#include <boost/spirit/include/support_unused.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
@@ -30,8 +27,19 @@
int main()
{
using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
namespace fusion = boost::fusion;
-
+
+ {
+ std::string s1("aaaa");
+ BOOST_TEST(test("aaaa", *char_, s1));
+ BOOST_TEST(test_delimited("a a a a ", *char_, s1, ' '));
+
+ std::string s2("");
+ BOOST_TEST(test("", *char_, s2));
+ BOOST_TEST(test_delimited("", *char_, s2, ' '));
+ }
+
{
using namespace boost::assign;
@@ -41,72 +49,35 @@
BOOST_TEST(test("abc", *char_, v));
BOOST_TEST(test_delimited("a b c ", *char_, v, ' '));
}
-
- {
- using namespace boost::assign;
- std::vector<char> v;
-
- // these need to fail, because the return value should be false
- BOOST_TEST(!test("", +char_, v));
- BOOST_TEST(!test_delimited("", +char_, v, ' '));
-
- v += 'a', 'b', 'c';
-
- BOOST_TEST(test("abc", +char_, v));
- BOOST_TEST(test_delimited("a b c ", +char_, v, ' '));
- }
-
{
using namespace boost::assign;
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
-
+
std::vector<int> v;
v += 10, 20, 30;
BOOST_TEST(test("102030", *int_, v));
BOOST_TEST(test_delimited("10, 20, 30, ", *int_, v, lit(", ")));
- typedef fusion::vector<int> fvec;
- std::vector<fvec> sv;
- sv += fvec(10), fvec(20), fvec(30);
-
- BOOST_TEST(test("10,20,30,", *(int_ << ','), sv));
- BOOST_TEST(test_delimited("10 , 20 , 30 , ", *(int_ << ','), sv, lit(" ")));
+ BOOST_TEST(test("10,20,30,", *(int_ << ','), v));
+ BOOST_TEST(test_delimited("10 , 20 , 30 , ", *(int_ << ','), v, lit(" ")));
fusion::vector<char, char> cc ('a', 'c');
BOOST_TEST(test("ac", char_ << *(char_(' ') << ',') << char_, cc));
BOOST_TEST(test_delimited("a c ",
char_ << *(char_(' ') << ',') << char_, cc, " "));
}
-
- {
- using namespace boost::assign;
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
-
- std::vector<int> v;
-
- BOOST_TEST(!test("", +int_, v));
- BOOST_TEST(!test_delimited("", +int_, v, lit(", ")));
- v += 10, 20, 30;
-
- BOOST_TEST(test("102030", +int_, v));
- BOOST_TEST(test_delimited("10, 20, 30, ", +int_, v, lit(", ")));
-
- typedef fusion::vector<int> fvec;
- std::vector<fvec> sv;
- sv += fvec(10), fvec(20), fvec(30);
+ { // actions
+ using namespace boost::assign;
+ namespace phx = boost::phoenix;
- BOOST_TEST(test("10,20,30,", +(int_ << ','), sv));
- BOOST_TEST(test_delimited("10 , 20 , 30 , ", +(int_ << ','), sv, lit(" ")));
+ std::vector<char> v;
+ v += 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h';
- fusion::vector<char, char> cc ('a', 'c');
- BOOST_TEST(!test("", char_ << +(char_(' ') << ',') << char_, cc));
- BOOST_TEST(!test_delimited("",
- char_ << +(char_(' ') << ',') << char_, cc, " "));
+ BOOST_TEST(test("abcdefgh", (*char_)[_1 = phx::ref(v)]));
+ BOOST_TEST(test_delimited("a b c d e f g h ",
+ (*char_ )[_1 = phx::ref(v)], space));
}
return boost::report_errors();
Modified: trunk/libs/spirit/test/karma/lazy.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/lazy.cpp (original)
+++ trunk/libs/spirit/test/karma/lazy.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -10,8 +10,8 @@
#include <boost/spirit/include/karma_numeric.hpp>
#include <boost/spirit/include/karma_auxiliary.hpp>
#include <boost/spirit/include/karma_action.hpp>
-#include <boost/spirit/include/karma_nonterminal.hpp>
-#include <boost/spirit/include/karma_operator.hpp>
+// #include <boost/spirit/include/karma_nonterminal.hpp>
+// #include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -22,31 +22,31 @@
int
main()
{
+ namespace karma = boost::spirit::karma;
using spirit_test::test;
using namespace boost::spirit;
using namespace boost::spirit::karma;
- using namespace boost::spirit::arg_names;
namespace phx = boost::phoenix;
{
- BOOST_TEST(test("123", lazy(phx::val(int_)), 123));
+ BOOST_TEST(test("123", karma::lazy(phx::val(int_)), 123));
}
{
int result = 123;
- BOOST_TEST(test("123", lazy(phx::val(int_))[_1 = phx::ref(result)]));
+ BOOST_TEST(test("123", karma::lazy(phx::val(int_))[_1 = phx::ref(result)]));
}
- {
- typedef spirit_test::output_iterator<char>::type outiter_type;
- rule<outiter_type, void(std::string)> r;
-
- r = char_('<') << lazy(_r1) << '>' << "</" << lazy(_r1) << '>';
-
- std::string tag("tag"), foo("foo");
- BOOST_TEST(test("<tag></tag>", r (phx::ref(tag))));
- BOOST_TEST(!test("<foo></bar>", r (phx::ref(foo))));
- }
+// {
+// typedef spirit_test::output_iterator<char>::type outiter_type;
+// rule<outiter_type, void(std::string)> r;
+//
+// r = char_('<') << karma::lazy(_r1) << '>' << "</" << karma::lazy(_r1) << '>';
+//
+// std::string tag("tag"), foo("foo");
+// BOOST_TEST(test("<tag></tag>", r (phx::ref(tag))));
+// BOOST_TEST(!test("<foo></bar>", r (phx::ref(foo))));
+// }
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/left_alignment.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/left_alignment.cpp (original)
+++ trunk/libs/spirit/test/karma/left_alignment.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -14,19 +14,19 @@
#include "test.hpp"
-using namespace spirit_test;
-
///////////////////////////////////////////////////////////////////////////////
int
main()
{
+ using namespace spirit_test;
using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
{
BOOST_TEST(test("x ", left_align[char_('x')]));
BOOST_TEST(test("x ", left_align[char_], 'x'));
BOOST_TEST(test("x ", left_align['x']));
-
+
BOOST_TEST(test("x ", left_align(10)[char_('x')]));
BOOST_TEST(test("x ", left_align(10)[char_], 'x'));
BOOST_TEST(test("x ", left_align(10)['x']));
@@ -40,18 +40,18 @@
BOOST_TEST(test("x*********", left_align(char_('*'))['x']));
BOOST_TEST(test("abc ", left_align[lit("abc")]));
- BOOST_TEST(test("abc ", left_align[lit], "abc"));
-
+ BOOST_TEST(test("abc ", left_align[string], "abc"));
+
BOOST_TEST(test("abc ", left_align(10)[lit("abc")]));
- BOOST_TEST(test("abc ", left_align(10)[lit], "abc"));
+ BOOST_TEST(test("abc ", left_align(10)[string], "abc"));
BOOST_TEST(test("abc ", left_align(10)["abc"]));
BOOST_TEST(test("abc*******", left_align(10, char_('*'))[lit("abc")]));
- BOOST_TEST(test("abc*******", left_align(10, '*')[lit], "abc"));
+ BOOST_TEST(test("abc*******", left_align(10, '*')[string], "abc"));
BOOST_TEST(test("abc*******", left_align(10, '*')["abc"]));
BOOST_TEST(test("abc*******", left_align(char_('*'))[lit("abc")]));
- BOOST_TEST(test("abc*******", left_align(char_('*'))[lit], "abc"));
+ BOOST_TEST(test("abc*******", left_align(char_('*'))[string], "abc"));
BOOST_TEST(test("abc*******", left_align(char_('*'))["abc"]));
BOOST_TEST(test("100 ", left_align[int_(100)]));
Modified: trunk/libs/spirit/test/karma/list.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/list.cpp (original)
+++ trunk/libs/spirit/test/karma/list.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -5,7 +5,6 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-#include <boost/utility/enable_if.hpp>
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_char.hpp>
@@ -13,11 +12,11 @@
#include <boost/spirit/include/karma_numeric.hpp>
#include <boost/spirit/include/karma_directive.hpp>
#include <boost/spirit/include/karma_action.hpp>
-#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
+
#include <boost/assign/std/vector.hpp>
#include <string>
@@ -38,7 +37,7 @@
std::vector<char> v;
v += 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h';
-
+
{
BOOST_TEST(test("a,b,c,d,e,f,g,h", char_ % ',', v));
BOOST_TEST(test_delimited("a , b , c , d , e , f , g , h ",
@@ -54,7 +53,6 @@
{ // actions
namespace phx = boost::phoenix;
- using boost::spirit::arg_names::_1;
BOOST_TEST(test("a,b,c,d,e,f,g,h", (char_ % ',')[_1 = phx::ref(v)]));
BOOST_TEST(test_delimited("a , b , c , d , e , f , g , h ",
Modified: trunk/libs/spirit/test/karma/lit.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/lit.cpp (original)
+++ trunk/libs/spirit/test/karma/lit.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -23,28 +23,38 @@
main()
{
using namespace boost::spirit;
-
+
{
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test("a", lit('a')));
BOOST_TEST(!test("a", lit('b')));
-
+
BOOST_TEST(test("abc", "abc"));
BOOST_TEST(!test("abcd", "abc"));
BOOST_TEST(test("abc", lit("abc")));
BOOST_TEST(!test("abcd", lit("abc")));
- BOOST_TEST(test("abc", lit, "abc"));
- BOOST_TEST(!test("abcd", lit, "abc"));
+ BOOST_TEST(test("abc", string, "abc"));
+ BOOST_TEST(!test("abcd", string, "abc"));
+
+ BOOST_TEST(test("abc", string("abc")));
+ BOOST_TEST(!test("abcd", string("abc")));
}
-
+
{
+ using namespace boost::spirit::ascii;
+
std::string str("abc");
BOOST_TEST(test("abc", lit(str)));
BOOST_TEST(!test("abcd", lit(str)));
- BOOST_TEST(test("abc", lit, str));
- BOOST_TEST(!test("abcd", lit, str));
+ BOOST_TEST(test("abc", string(str)));
+ BOOST_TEST(!test("abcd", string(str)));
+
+ BOOST_TEST(test("abc", string, str));
+ BOOST_TEST(!test("abcd", string, str));
BOOST_TEST(test("abc", str));
BOOST_TEST(!test("abcd", str));
@@ -53,85 +63,94 @@
BOOST_TEST(test(L"abc", lit(wstr)));
BOOST_TEST(!test(L"abcd", lit(wstr)));
- BOOST_TEST(test(L"abc", lit, wstr));
- BOOST_TEST(!test(L"abcd", lit, wstr));
+ BOOST_TEST(test(L"abc", string, wstr));
+ BOOST_TEST(!test(L"abcd", string, wstr));
BOOST_TEST(test(L"abc", wstr));
BOOST_TEST(!test(L"abcd", wstr));
}
-
+
{
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test(L"a", lit(L'a')));
BOOST_TEST(!test(L"a", lit(L'b')));
-
+
BOOST_TEST(test(L"abc", L"abc"));
BOOST_TEST(test(L"abc", "abc"));
BOOST_TEST(!test(L"abcd", L"abc"));
BOOST_TEST(test(L"abc", lit(L"abc")));
- BOOST_TEST(test(L"abc", wlit(L"abc")));
BOOST_TEST(!test(L"abcd", lit(L"abc")));
- BOOST_TEST(test(L"abc", lit, L"abc"));
- BOOST_TEST(test(L"abc", wlit, L"abc"));
- BOOST_TEST(!test(L"abcd", lit, L"abc"));
-
- BOOST_TEST(test(L"abc", lit, "abc"));
- BOOST_TEST(test(L"abc", wlit, "abc"));
- BOOST_TEST(!test(L"abcd", lit, "abc"));
+ BOOST_TEST(test(L"abc", string(L"abc")));
+ BOOST_TEST(!test(L"abcd", string(L"abc")));
+
+ BOOST_TEST(test(L"abc", string, L"abc"));
+ BOOST_TEST(!test(L"abcd", string, L"abc"));
+
+ BOOST_TEST(test(L"abc", string, "abc"));
+ BOOST_TEST(!test(L"abcd", string, "abc"));
}
-
+
{
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test_delimited("a ", lit('a'), ' '));
BOOST_TEST(!test_delimited("a ", lit('b'), ' '));
-
+
BOOST_TEST(test_delimited("abc ", "abc", ' '));
BOOST_TEST(!test_delimited("abcd ", "abc", ' '));
BOOST_TEST(test_delimited("abc ", lit("abc"), ' '));
BOOST_TEST(!test_delimited("abcd ", lit("abc"), ' '));
- BOOST_TEST(test_delimited("abc ", lit, "abc", ' '));
- BOOST_TEST(!test_delimited("abcd ", lit, "abc", ' '));
+ BOOST_TEST(test_delimited("abc ", string, "abc", ' '));
+ BOOST_TEST(!test_delimited("abcd ", string, "abc", ' '));
+
+ BOOST_TEST(test_delimited("abc ", string("abc"), ' '));
+ BOOST_TEST(!test_delimited("abcd ", string("abc"), ' '));
}
-
+
{
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test_delimited(L"a ", lit(L'a'), ' '));
BOOST_TEST(!test_delimited(L"a ", lit(L'b'), ' '));
-
+
BOOST_TEST(test_delimited(L"abc ", L"abc", ' '));
BOOST_TEST(!test_delimited(L"abcd ", L"abc", ' '));
BOOST_TEST(test_delimited(L"abc ", lit(L"abc"), ' '));
- BOOST_TEST(test_delimited(L"abc ", wlit(L"abc"), ' '));
- BOOST_TEST(test_delimited(L"abc ", wlit("abc"), ' '));
BOOST_TEST(!test_delimited(L"abcd ", lit(L"abc"), ' '));
- BOOST_TEST(test_delimited(L"abc ", lit, L"abc", ' '));
- BOOST_TEST(test_delimited(L"abc ", wlit, L"abc", ' '));
- BOOST_TEST(test_delimited(L"abc ", wlit, "abc", ' '));
- BOOST_TEST(!test_delimited(L"abcd ", lit, L"abc", ' '));
+ BOOST_TEST(test_delimited(L"abc ", string, L"abc", ' '));
+ BOOST_TEST(!test_delimited(L"abcd ", string, L"abc", ' '));
+
+ BOOST_TEST(test_delimited(L"abc ", string(L"abc"), ' '));
+ BOOST_TEST(!test_delimited(L"abcd ", string(L"abc"), ' '));
}
{ // test action
-
using namespace boost::phoenix;
- using boost::spirit::arg_names::_1;
using namespace boost::spirit::ascii;
-
+
std::string str("abc");
- BOOST_TEST(test("abc", lit[_1 = ref(str)]));
- BOOST_TEST(test_delimited("abc ", lit[_1 = ref(str)], space));
+ BOOST_TEST(test("abc", string[_1 = ref(str)]));
+ BOOST_TEST(test_delimited("abc ", string[_1 = ref(str)], space));
}
{ // lazy strings
-
using namespace boost::phoenix;
+ using namespace boost::spirit::ascii;
+
std::basic_string<char> s("abc");
BOOST_TEST((test("abc", lit(val(s)))));
+ BOOST_TEST((test("abc", string(val(s)))));
std::basic_string<wchar_t> ws(L"abc");
BOOST_TEST((test(L"abc", lit(ref(ws)))));
+ BOOST_TEST((test(L"abc", string(ref(ws)))));
}
return boost::report_errors();
Added: trunk/libs/spirit/test/karma/maxwidth.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/maxwidth.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,77 @@
+// Copyright (c) 2001-2009 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>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_directive.hpp>
+
+#include "test.hpp"
+
+using namespace spirit_test;
+
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
+
+ {
+ BOOST_TEST(test("0123456789", maxwidth[lit("0123456789")]));
+ BOOST_TEST(test("012345678", maxwidth[lit("012345678")]));
+ BOOST_TEST(test("0123456789", maxwidth[lit("01234567890")]));
+
+ BOOST_TEST(test("0123456789", maxwidth[string], "0123456789"));
+ BOOST_TEST(test("012345678", maxwidth[string], "012345678"));
+ BOOST_TEST(test("0123456789", maxwidth[string], "01234567890"));
+ }
+
+ {
+ BOOST_TEST(test("01234567", maxwidth(8)[lit("01234567")]));
+ BOOST_TEST(test("0123456", maxwidth(8)[lit("0123456")]));
+ BOOST_TEST(test("01234567", maxwidth(8)[lit("012345678")]));
+
+ BOOST_TEST(test("01234567", maxwidth(8)[string], "01234567"));
+ BOOST_TEST(test("0123456", maxwidth(8)[string], "0123456"));
+ BOOST_TEST(test("01234567", maxwidth(8)[string], "012345678"));
+ }
+
+ {
+// std::string str;
+// BOOST_TEST(test("01234567",
+// maxwidth(8, std::back_inserter(str))[lit("01234567")]) &&
+// str.empty());
+//
+// str = "";
+// BOOST_TEST(test("0123456",
+// maxwidth(8, std::back_inserter(str))[lit("0123456")]) &&
+// str.empty());
+//
+// str = "";
+// BOOST_TEST(test("01234567",
+// maxwidth(8, std::back_inserter(str))[lit("012345678")]) &&
+// str == "8");
+ }
+
+ {
+ using namespace boost::phoenix;
+
+ BOOST_TEST(test("01234567", maxwidth(val(8))[lit("01234567")]));
+ BOOST_TEST(test("0123456", maxwidth(val(8))[lit("0123456")]));
+ BOOST_TEST(test("01234567", maxwidth(val(8))[lit("012345678")]));
+
+ int w = 8;
+ BOOST_TEST(test("01234567", maxwidth(ref(w))[string], "01234567"));
+ BOOST_TEST(test("0123456", maxwidth(ref(w))[string], "0123456"));
+ BOOST_TEST(test("01234567", maxwidth(ref(w))[string], "012345678"));
+ }
+
+ return boost::report_errors();
+}
Deleted: trunk/libs/spirit/test/karma/none.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/none.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,33 +0,0 @@
-// Copyright (c) 2001-2009 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>
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/karma_auxiliary.hpp>
-#include <boost/spirit/include/karma_char.hpp>
-#include <boost/spirit/include/karma_generate.hpp>
-
-#include <iostream>
-#include "test.hpp"
-
-int
-main()
-{
- using namespace spirit_test;
- using namespace boost::spirit;
- using namespace boost::spirit::ascii;
-
- {
- BOOST_TEST((!test("", none, 1)));
- BOOST_TEST((!test("", none, "test")));
- }
-
- {
- BOOST_TEST((!test_delimited(" ", none, 1, space)));
- BOOST_TEST((!test_delimited(" ", none, "test", space)));
- }
-
- return boost::report_errors();
-}
Modified: trunk/libs/spirit/test/karma/optional.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/optional.cpp (original)
+++ trunk/libs/spirit/test/karma/optional.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -10,7 +10,6 @@
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_numeric.hpp>
#include <boost/spirit/include/karma_action.hpp>
-#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -21,6 +20,7 @@
{
using namespace spirit_test;
using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
{
boost::optional<int> opt;
@@ -36,8 +36,6 @@
}
{
- using namespace boost::spirit::ascii;
-
boost::optional<int> opt;
BOOST_TEST(test_delimited("", -int_, opt, space));
@@ -46,8 +44,6 @@
}
{
- using namespace boost::spirit::ascii;
-
int opt = 10;
BOOST_TEST(test_delimited("10 ", -int_, opt, space));
}
@@ -55,7 +51,6 @@
{ // test action
using namespace boost::phoenix;
namespace phoenix = boost::phoenix;
- using namespace boost::spirit::arg_names;
boost::optional<int> n ;
BOOST_TEST(test("", (-int_)[_1 = phoenix::ref(n)]));
@@ -67,7 +62,6 @@
{ // test action
using namespace boost::phoenix;
namespace phoenix = boost::phoenix;
- using namespace boost::spirit::arg_names;
int n = 1234;
BOOST_TEST(test("1234", (-int_)[_1 = phoenix::ref(n)]));
@@ -76,8 +70,6 @@
{ // test action
using namespace boost::phoenix;
namespace phoenix = boost::phoenix;
- using namespace boost::spirit::arg_names;
- using namespace boost::spirit::ascii;
boost::optional<int> n;
BOOST_TEST(test_delimited("", (-int_)[_1 = phoenix::ref(n)], space));
@@ -89,8 +81,6 @@
{ // test action
using namespace boost::phoenix;
namespace phoenix = boost::phoenix;
- using namespace boost::spirit::arg_names;
- using namespace boost::spirit::ascii;
int n = 1234;
BOOST_TEST(test_delimited("1234 ", (-int_)[_1 = phoenix::ref(n)], space));
Modified: trunk/libs/spirit/test/karma/pattern.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/pattern.cpp (original)
+++ trunk/libs/spirit/test/karma/pattern.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -6,9 +6,6 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-// include this first to make rules have placeholders (e.g. _r1)
-#include <boost/spirit/include/support_argument.hpp>
-
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_auxiliary.hpp>
@@ -30,7 +27,6 @@
{
using namespace boost;
using namespace boost::spirit;
- using namespace boost::spirit::arg_names;
using namespace boost::spirit::karma;
using namespace boost::spirit::ascii;
@@ -39,7 +35,7 @@
// test rule parameter propagation
{
using boost::phoenix::at_c;
-
+
rule<outiter_type, fusion::vector<char, int, double>()> start;
fusion::vector<char, int, double> vec('a', 10, 12.4);
@@ -63,74 +59,115 @@
BOOST_TEST(test("a1012.4", start, vec));
}
- // basic tests with delimiter
{
- rule<outiter_type, space_type> start;
+ using boost::phoenix::at_c;
+
+ rule<outiter_type, space_type, fusion::vector<char, int, double>()> start;
+ fusion::vector<char, int, double> vec('a', 10, 12.4);
+
+ start %= char_ << int_ << double_;
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
- start = char_[_1 = 'a'] << int_[_1 = 10] << double_[_1 = 12.4];
- BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+ rule<outiter_type, space_type, char()> a;
+ rule<outiter_type, space_type, int()> b;
+ rule<outiter_type, space_type, double()> c;
- start = (char_ << int_ << double_)[_1 = 'a', _2 = 10, _3 = 12.4];
- BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+ a %= char_ << eps;
+ b %= int_;
+ c %= double_;
+ start = a[_1 = at_c<0>(_r0)] << b[_1 = at_c<1>(_r0)] << c[_1 = at_c<2>(_r0)];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
- rule<outiter_type, space_type> a, b, c;
- a = char_[_1 = 'a'];
- b = int_[_1 = 10];
- c = double_[_1 = 12.4];
+ start = (a << b << c)[_1 = at_c<0>(_r0), _2 = at_c<1>(_r0), _3 = at_c<2>(_r0)];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
- start = a << b << c;
- BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+ start %= a << b << c;
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, vec, space));
}
// locals test
{
rule<outiter_type, locals<std::string> > start;
- start = lit[_1 = "abc", _a = _1] << int_[_1 = 10] << lit[_1 = _a];
+ start = string[_1 = "abc", _a = _1] << int_[_1 = 10] << string[_1 = _a];
BOOST_TEST(test("abc10abc", start));
}
- //~ { // alias tests
- //~ typedef variant<char, int, double> var_type;
- //~ fusion::vector<unused_type, var_type> v (unused, 'a');
+ {
+ rule<outiter_type, space_type, locals<std::string> > start;
- //~ rule<outiter_type, void(var_type)> d, start;
+ start = string[_1 = "abc", _a = _1] << int_[_1 = 10] << string[_1 = _a];
+ BOOST_TEST(test_delimited("abc 10 abc ", start, space));
+ }
- //~ d = start.alias(); // d will always track start
+ // alias tests
+ {
+ typedef variant<char, int, double> var_type;
+
+ rule<outiter_type, var_type()> d, start;
+
+ d = start.alias(); // d will always track start
+
+ start = (char_ | int_ | double_)[_1 = _val];
+
+ var_type v ('a');
+ BOOST_TEST(test("a", d, v));
+ v = 10;
+ BOOST_TEST(test("10", d, v));
+ v = 12.4;
+ BOOST_TEST(test("12.4", d, v));
+ }
- //~ start = (char_ | int_ | double_)[_1 = _r1];
- //~ BOOST_TEST(test("a", d, v));
+ {
+ typedef variant<char, int, double> var_type;
- //~ v = fusion::vector<unused_type, var_type>(unused, 10);
- //~ BOOST_TEST(test("10", d, v));
- //~ v = fusion::vector<unused_type, var_type>(unused, 12.4);
- //~ BOOST_TEST(test("12.4", d, v));
- //~ }
+ rule<outiter_type, space_type, var_type()> d, start;
- //~ { // copy tests
+ d = start.alias(); // d will always track start
- //~ rule<char const*> a, b, c, start;
+ start = (char_ | int_ | double_)[_1 = _val];
- //~ a = 'a';
- //~ b = 'b';
- //~ c = 'c';
+ var_type v ('a');
+ BOOST_TEST(test_delimited("a ", d, v, space));
+ v = 10;
+ BOOST_TEST(test_delimited("10 ", d, v, space));
+ v = 12.4;
+ BOOST_TEST(test_delimited("12.4 ", d, v, space));
+ }
- //~ // The FF is the dynamic equivalent of start = *(a | b | c);
- //~ start = a;
- //~ start = start.copy() | b;
- //~ start = start.copy() | c;
- //~ start = *(start.copy());
+ {
+ typedef variant<char, int, double> var_type;
- //~ BOOST_TEST(test("abcabcacb", start));
+ rule<outiter_type, var_type()> d, start;
- //~ // The FF is the dynamic equivalent of start = (a | b) >> (start | b);
- //~ start = b;
- //~ start = a | copy(start);
- //~ start = start.copy() >> (start | b);
+ d = start.alias(); // d will always track start
+
+ start %= char_ | int_ | double_;
+
+ var_type v ('a');
+ BOOST_TEST(test("a", d, v));
+ v = 10;
+ BOOST_TEST(test("10", d, v));
+ v = 12.4;
+ BOOST_TEST(test("12.4", d, v));
+ }
- //~ BOOST_TEST(test("aaaabababaaabbb", start));
- //~ BOOST_TEST(test("aaaabababaaabba", start, false));
- //~ }
+ {
+ typedef variant<char, int, double> var_type;
+
+ rule<outiter_type, space_type, var_type()> d, start;
+
+ d = start.alias(); // d will always track start
+
+ start %= char_ | int_ | double_;
+
+ var_type v ('a');
+ BOOST_TEST(test_delimited("a ", d, v, space));
+ v = 10;
+ BOOST_TEST(test_delimited("10 ", d, v, space));
+ v = 12.4;
+ BOOST_TEST(test_delimited("12.4 ", d, v, space));
+ }
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/pattern2.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/pattern2.cpp (original)
+++ trunk/libs/spirit/test/karma/pattern2.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -6,9 +6,6 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-// include this first to make rules have placeholders (e.g. _r1)
-#include <boost/spirit/include/support_argument.hpp>
-
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_auxiliary.hpp>
@@ -30,7 +27,6 @@
{
using namespace boost;
using namespace boost::spirit;
- using namespace boost::spirit::arg_names;
using namespace boost::spirit::karma;
using namespace boost::spirit::ascii;
@@ -55,16 +51,35 @@
BOOST_TEST(test("a1012.4", start));
}
+ // basic tests with delimiter
+ {
+ rule<outiter_type, space_type> start;
+
+ start = char_[_1 = 'a'] << int_[_1 = 10] << double_[_1 = 12.4];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+
+ start = (char_ << int_ << double_)[_1 = 'a', _2 = 10, _3 = 12.4];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+
+ rule<outiter_type, space_type> a, b, c;
+ a = char_[_1 = 'a'];
+ b = int_[_1 = 10];
+ c = double_[_1 = 12.4];
+
+ start = a << b << c;
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+ }
+
// basic tests involving a direct parameter
{
typedef variant<char, int, double> var_type;
- var_type v ('a');
rule<outiter_type, var_type()> start;
start = (char_ | int_ | double_)[_1 = _r0];
- BOOST_TEST(test("a", start, v));
+ var_type v ('a');
+ BOOST_TEST(test("a", start, v));
v = 10;
BOOST_TEST(test("10", start, v));
v = 12.4;
@@ -72,6 +87,21 @@
}
{
+ typedef variant<char, int, double> var_type;
+
+ rule<outiter_type, space_type, var_type()> start;
+
+ start = (char_ | int_ | double_)[_1 = _r0];
+
+ var_type v ('a');
+ BOOST_TEST(test_delimited("a ", start, v, space));
+ v = 10;
+ BOOST_TEST(test_delimited("10 ", start, v, space));
+ v = 12.4;
+ BOOST_TEST(test_delimited("12.4 ", start, v, space));
+ }
+
+ {
rule<outiter_type, void(char, int, double)> start;
fusion::vector<char, int, double> vec('a', 10, 12.4);
@@ -92,6 +122,64 @@
BOOST_TEST(test("a1012.4", start('a', 10, 12.4)));
}
+ {
+ rule<outiter_type, space_type, void(char, int, double)> start;
+ fusion::vector<char, int, double> vec('a', 10, 12.4);
+
+ start = char_[_1 = _r1] << int_[_1 = _r2] << double_[_1 = _r3];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
+
+ start = (char_ << int_ << double_)[_1 = _r1, _2 = _r2, _3 = _r3];
+ BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
+
+ rule<outiter_type, space_type, void(char)> a;
+ rule<outiter_type, space_type, void(int)> b;
+ rule<outiter_type, space_type, void(double)> c;
+
+ a = char_[_1 = _r1];
+ b = int_[_1 = _r1];
+ c = double_[_1 = _r1];
+ start = a(_r1) << b(_r2) << c(_r3);
+ BOOST_TEST(test_delimited("a 10 12.4 ", start('a', 10, 12.4), space));
+ }
+
+ // copy tests
+ {
+ typedef variant<char, int, double> var_type;
+
+ rule<outiter_type> a, b, c, start;
+
+ a = 'a';
+ b = int_(10);
+ c = double_(12.4);
+
+ // The FF is the dynamic equivalent of start = a << b << c;
+ start = a;
+ start = start.copy() << b;
+ start = start.copy() << c;
+ start = start.copy();
+
+ BOOST_TEST(test("a1012.4", start));
+ }
+
+ {
+ typedef variant<char, int, double> var_type;
+
+ rule<outiter_type, space_type> a, b, c, start;
+
+ a = 'a';
+ b = int_(10);
+ c = double_(12.4);
+
+ // The FF is the dynamic equivalent of start = a << b << c;
+ start = a;
+ start = start.copy() << b;
+ start = start.copy() << c;
+ start = start.copy();
+
+ BOOST_TEST(test_delimited("a 10 12.4 ", start, space));
+ }
+
return boost::report_errors();
}
Added: trunk/libs/spirit/test/karma/plus.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/plus.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,89 @@
+// Copyright (c) 2001-2009 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>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/assign/std/vector.hpp>
+
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_operator.hpp>
+#include <boost/spirit/include/karma_action.hpp>
+#include <boost/fusion/include/vector.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+#include <boost/spirit/include/phoenix_statement.hpp>
+
+#include "test.hpp"
+
+using namespace spirit_test;
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
+ namespace fusion = boost::fusion;
+
+ {
+ std::string s1("aaaa");
+ BOOST_TEST(test("aaaa", +char_, s1));
+ BOOST_TEST(test_delimited("a a a a ", +char_, s1, ' '));
+
+ std::string s2("a");
+ BOOST_TEST(test("a", +char_, s2));
+ BOOST_TEST(test_delimited("a ", +char_, s2, ' '));
+
+ std::string s3("");
+ BOOST_TEST(!test("", +char_, s2));
+ BOOST_TEST(!test_delimited("", +char_, s3, ' '));
+ }
+
+ {
+ using namespace boost::assign;
+
+ std::vector<char> v;
+ v += 'a', 'b', 'c';
+
+ BOOST_TEST(test("abc", +char_, v));
+ BOOST_TEST(test_delimited("a b c ", +char_, v, ' '));
+ }
+
+ {
+ using namespace boost::assign;
+
+ std::vector<int> v;
+ v += 10, 20, 30;
+
+ BOOST_TEST(test("102030", +int_, v));
+ BOOST_TEST(test_delimited("10, 20, 30, ", +int_, v, lit(", ")));
+
+ BOOST_TEST(test("10,20,30,", +(int_ << ','), v));
+ BOOST_TEST(test_delimited("10 , 20 , 30 , ", +(int_ << ','), v, lit(" ")));
+
+ fusion::vector<char, char> cc ('a', 'c');
+ BOOST_TEST(test("ac", char_ << !+(char_(' ') << ',') << char_, cc));
+ BOOST_TEST(test_delimited("a c ",
+ char_ << !+(char_(' ') << ',') << char_, cc, " "));
+ }
+
+ { // actions
+ using namespace boost::assign;
+ namespace phx = boost::phoenix;
+
+ std::vector<char> v;
+ v += 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h';
+
+ BOOST_TEST(test("abcdefgh", (+char_)[_1 = phx::ref(v)]));
+ BOOST_TEST(test_delimited("a b c d e f g h ",
+ (+char_ )[_1 = phx::ref(v)], space));
+ }
+
+ return boost::report_errors();
+}
+
Modified: trunk/libs/spirit/test/karma/real_numerics.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/real_numerics.cpp (original)
+++ trunk/libs/spirit/test/karma/real_numerics.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,4 +1,4 @@
-// Copyright (c) 2001-2008 Hartmut Kaiser
+// Copyright (c) 2001-2009 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)
@@ -23,35 +23,34 @@
///////////////////////////////////////////////////////////////////////////////
// policy for real_generator, which forces the scientific notation
template <typename T>
-struct scientific_policy : boost::spirit::karma::real_generator_policies<T>
+struct scientific_policy : boost::spirit::karma::real_policies<T>
{
// we want the numbers always to be in scientific format
- typedef boost::spirit::karma::real_generator_policies<T> base_type;
- static int floatfield(T) { return base_type::scientific; }
+ typedef boost::spirit::karma::real_policies<T> base_type;
+ static int floatfield(T) { return base_type::fmtflags::scientific; }
};
-///////////////////////////////////////////////////////////////////////////////
-// policy for real_generator, which forces the fixed notation
+// ///////////////////////////////////////////////////////////////////////////////
+// // policy for real_generator, which forces the fixed notation
template <typename T>
-struct fixed_policy : boost::spirit::karma::real_generator_policies<T>
+struct fixed_policy : boost::spirit::karma::real_policies<T>
{
- typedef boost::spirit::karma::real_generator_policies<T> base_type;
+ typedef boost::spirit::karma::real_policies<T> base_type;
// we want the numbers always to be in scientific format
- static int floatfield(T) { return base_type::fixed; }
+ static int floatfield(T) { return base_type::fmtflags::fixed; }
};
///////////////////////////////////////////////////////////////////////////////
// policy for real_generator, which forces to output trailing zeros in the
// fractional part
template <typename T>
-struct trailing_zeros_policy
- : boost::spirit::karma::real_generator_policies<T> // 4 digits
+struct trailing_zeros_policy : boost::spirit::karma::real_policies<T> // 4 digits
{
// we want the numbers always to contain trailing zeros up to 4 digits in
// the fractional part
- static bool const trailing_zeros = true;
-
+ static bool trailing_zeros(T) { return true; }
+
// we want to generate up to 4 fractional digits
static unsigned int precision(T) { return 4; }
};
@@ -59,33 +58,57 @@
///////////////////////////////////////////////////////////////////////////////
// policy for real_generator, which forces the sign to be generated
template <typename T>
-struct signed_policy
- : boost::spirit::karma::real_generator_policies<T>
+struct signed_policy : boost::spirit::karma::real_policies<T>
{
// we want to always have a sign generated
static bool const force_sign = true;
};
-// support for using real_concept with a Karma generator has been implemented
-// in Boost versions > 1.36 only
-#if BOOST_VERSION > 103600
///////////////////////////////////////////////////////////////////////////////
-// We need to specialize is_real_lit_tag to allow to use a real_concept as a
-// literal below
-namespace boost { namespace spirit
+// policy for real_generator, which forces to output trailing zeros in the
+// fractional part
+template <typename T>
+struct bordercase_policy : boost::spirit::karma::real_policies<T>
{
- template <typename Domain>
- struct is_real_lit_tag<boost::math::concepts::real_concept, Domain>
- : boost::mpl::true_ {};
-}}
-#endif
+ // we want to generate up to the maximum significant amount of fractional
+ // digits
+ static unsigned int precision(T)
+ {
+ return std::numeric_limits<T>::digits10 + 1;
+ }
+};
///////////////////////////////////////////////////////////////////////////////
-int
-main()
+// policy for real_generator, which forces to output trailing zeros in the
+// fractional part
+template <typename T>
+struct statefull_policy : boost::spirit::karma::real_policies<T>
+{
+ statefull_policy(int precision = 4, bool trailingzeros = false)
+ : precision_(precision), trailingzeros_(trailingzeros)
+ {}
+
+ // we want to generate up to the maximum significant amount of fractional
+ // digits
+ unsigned int precision(T) const
+ {
+ return precision_;
+ }
+
+ bool trailing_zeros(T) const
+ {
+ return trailingzeros_;
+ }
+
+ int precision_;
+ bool trailingzeros_;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
{
using namespace boost::spirit;
-
+
{
///////////////////////////////////////////////////////////////////////
// use the default real_policies
@@ -95,7 +118,7 @@
BOOST_TEST(test("1.001", double_, 1.001));
BOOST_TEST(test("1.01", double_, 1.010));
BOOST_TEST(test("1.1", double_, 1.100));
-
+
BOOST_TEST(test("1.234e-04", double_, 0.00012345));
BOOST_TEST(test("0.001", double_, 0.0012345));
BOOST_TEST(test("0.012", double_, 0.012345));
@@ -106,18 +129,18 @@
BOOST_TEST(test("1234.5", double_, 1234.5));
BOOST_TEST(test("12342.0", double_, 12342.));
BOOST_TEST(test("1.234e05", double_, 123420.));
-
+
BOOST_TEST(test("-1.0", double_, -1.0));
BOOST_TEST(test("-1.234", double_, -1.2345));
BOOST_TEST(test("-1.235", double_, -1.2346));
BOOST_TEST(test("-1234.2", double_, -1234.2));
-
+
BOOST_TEST(test("1.0", double_(1.0)));
BOOST_TEST(test("1.0", double_(1.0001)));
BOOST_TEST(test("1.001", double_(1.001)));
BOOST_TEST(test("1.01", double_(1.010)));
BOOST_TEST(test("1.1", double_(1.100)));
-
+
BOOST_TEST(test("1.234e-04", double_(0.00012345)));
BOOST_TEST(test("0.001", double_(0.0012345)));
BOOST_TEST(test("0.012", double_(0.012345)));
@@ -129,7 +152,7 @@
BOOST_TEST(test("12342.0", double_(12342.)));
BOOST_TEST(test("1.234e05", double_(123420.)));
}
-
+
{
///////////////////////////////////////////////////////////////////////
// test NaN and Inf
@@ -138,7 +161,7 @@
BOOST_TEST(test("inf", double_, std::numeric_limits<double>::infinity()));
BOOST_TEST(test("-inf", double_, -std::numeric_limits<double>::infinity()));
- typedef karma::real_spec<double, signed_policy<double> > signed_type;
+ typedef karma::real_generator<double, signed_policy<double> > signed_type;
signed_type const signed_ = signed_type();
BOOST_TEST(test("+nan", signed_, std::numeric_limits<double>::quiet_NaN()));
@@ -146,17 +169,32 @@
BOOST_TEST(test("+inf", signed_, std::numeric_limits<double>::infinity()));
BOOST_TEST(test("-inf", signed_, -std::numeric_limits<double>::infinity()));
BOOST_TEST(test(" 0.0", signed_, 0.0));
-
+
BOOST_TEST(test("+nan", signed_(std::numeric_limits<double>::quiet_NaN())));
BOOST_TEST(test("-nan", signed_(-std::numeric_limits<double>::quiet_NaN())));
BOOST_TEST(test("+inf", signed_(std::numeric_limits<double>::infinity())));
BOOST_TEST(test("-inf", signed_(-std::numeric_limits<double>::infinity())));
BOOST_TEST(test(" 0.0", signed_(0.0)));
}
-
+
+ {
+ ///////////////////////////////////////////////////////////////////////
+ typedef karma::real_generator<double, statefull_policy<double> >
+ statefull_type;
+
+ statefull_policy<double> policy(5, true);
+ statefull_type const statefull = statefull_type(policy);
+
+ BOOST_TEST(test("0.00000", statefull, 0.0));
+ BOOST_TEST(test("0.00000", statefull(0.0)));
+
+ using namespace boost::phoenix;
+ BOOST_TEST(test("0.00000", statefull(val(0.0))));
+ }
+
{
///////////////////////////////////////////////////////////////////////
- typedef karma::real_spec<double, trailing_zeros_policy<double> >
+ typedef karma::real_generator<double, trailing_zeros_policy<double> >
trailing_zeros_type;
trailing_zeros_type const trail_zeros = trailing_zeros_type();
@@ -166,7 +204,7 @@
BOOST_TEST(test("1.0010", trail_zeros, 1.001));
BOOST_TEST(test("1.0100", trail_zeros, 1.010));
BOOST_TEST(test("1.1000", trail_zeros, 1.100));
-
+
BOOST_TEST(test("1.2345e-04", trail_zeros, 0.00012345));
BOOST_TEST(test("0.0012", trail_zeros, 0.0012345));
BOOST_TEST(test("0.0123", trail_zeros, 0.012345));
@@ -177,18 +215,18 @@
BOOST_TEST(test("1234.5000", trail_zeros, 1234.5));
BOOST_TEST(test("12342.0000", trail_zeros, 12342.));
BOOST_TEST(test("1.2342e05", trail_zeros, 123420.));
-
+
BOOST_TEST(test("-1.0000", trail_zeros, -1.0));
BOOST_TEST(test("-1.2345", trail_zeros, -1.2345));
BOOST_TEST(test("-1.2346", trail_zeros, -1.2346));
BOOST_TEST(test("-1234.2000", trail_zeros, -1234.2));
-
+
BOOST_TEST(test("1.0000", trail_zeros(1.0)));
BOOST_TEST(test("1.0001", trail_zeros(1.0001)));
BOOST_TEST(test("1.0010", trail_zeros(1.001)));
BOOST_TEST(test("1.0100", trail_zeros(1.010)));
BOOST_TEST(test("1.1000", trail_zeros(1.100)));
-
+
BOOST_TEST(test("1.2345e-04", trail_zeros(0.00012345)));
BOOST_TEST(test("0.0012", trail_zeros(0.0012345)));
BOOST_TEST(test("0.0123", trail_zeros(0.012345)));
@@ -200,8 +238,10 @@
BOOST_TEST(test("12342.0000", trail_zeros(12342.)));
BOOST_TEST(test("1.2342e05", trail_zeros(123420.)));
}
-
+
{
+ using namespace boost::spirit::ascii;
+
///////////////////////////////////////////////////////////////////////
BOOST_TEST(test_delimited("0.0 ", double_, 0.0, char_(' ')));
BOOST_TEST(test_delimited("1.0 ", double_, 1.0, char_(' ')));
@@ -209,7 +249,7 @@
BOOST_TEST(test_delimited("1.001 ", double_, 1.001, char_(' ')));
BOOST_TEST(test_delimited("1.01 ", double_, 1.010, char_(' ')));
BOOST_TEST(test_delimited("1.1 ", double_, 1.100, char_(' ')));
-
+
BOOST_TEST(test_delimited("1.234e-04 ", double_, 0.00012345, char_(' ')));
BOOST_TEST(test_delimited("0.001 ", double_, 0.0012345, char_(' ')));
BOOST_TEST(test_delimited("0.012 ", double_, 0.012345, char_(' ')));
@@ -220,18 +260,18 @@
BOOST_TEST(test_delimited("1234.5 ", double_, 1234.5, char_(' ')));
BOOST_TEST(test_delimited("12342.0 ", double_, 12342., char_(' ')));
BOOST_TEST(test_delimited("1.234e05 ", double_, 123420., char_(' ')));
-
+
BOOST_TEST(test_delimited("-1.0 ", double_, -1.0, char_(' ')));
BOOST_TEST(test_delimited("-1.234 ", double_, -1.2345, char_(' ')));
BOOST_TEST(test_delimited("-1.235 ", double_, -1.2346, char_(' ')));
BOOST_TEST(test_delimited("-1234.2 ", double_, -1234.2, char_(' ')));
-
+
BOOST_TEST(test_delimited("1.0 ", double_(1.0), char_(' ')));
BOOST_TEST(test_delimited("1.0 ", double_(1.0001), char_(' ')));
BOOST_TEST(test_delimited("1.001 ", double_(1.001), char_(' ')));
BOOST_TEST(test_delimited("1.01 ", double_(1.010), char_(' ')));
BOOST_TEST(test_delimited("1.1 ", double_(1.100), char_(' ')));
-
+
BOOST_TEST(test_delimited("1.234e-04 ", double_(0.00012345), char_(' ')));
BOOST_TEST(test_delimited("0.001 ", double_(0.0012345), char_(' ')));
BOOST_TEST(test_delimited("0.012 ", double_(0.012345), char_(' ')));
@@ -245,6 +285,8 @@
}
{
+ using namespace boost::spirit::ascii;
+
///////////////////////////////////////////////////////////////////////
// test NaN and Inf
BOOST_TEST(test_delimited("nan ", double_,
@@ -256,7 +298,7 @@
BOOST_TEST(test_delimited("-inf ", double_,
-std::numeric_limits<double>::infinity(), char_(' ')));
- typedef karma::real_spec<double, signed_policy<double> > signed_type;
+ typedef karma::real_generator<double, signed_policy<double> > signed_type;
signed_type const signed_ = signed_type();
BOOST_TEST(test_delimited("+nan ", signed_,
@@ -272,15 +314,15 @@
{
using namespace boost::spirit::ascii;
-
+
///////////////////////////////////////////////////////////////////////
- typedef karma::real_spec<double, scientific_policy<double> >
+ typedef karma::real_generator<double, scientific_policy<double> >
science_type;
science_type const science = science_type();
-
+
BOOST_TEST(test("0.0e00", science, 0.0));
BOOST_TEST(test("1.0e00", science, 1.0));
-
+
BOOST_TEST(test("1.234e-05", science, 0.000012345));
BOOST_TEST(test("1.234e-04", science, 0.00012345));
BOOST_TEST(test("1.234e-03", science, 0.0012345));
@@ -329,17 +371,17 @@
BOOST_TEST(test("-1.234E04", upper[science], -12342.));
BOOST_TEST(test("-1.234E05", upper[science], -123420.));
}
-
+
{
using namespace boost::spirit::ascii;
-
+
///////////////////////////////////////////////////////////////////////
- typedef karma::real_spec<double, fixed_policy<double> > fixed_type;
+ typedef karma::real_generator<double, fixed_policy<double> > fixed_type;
fixed_type const fixed = fixed_type();
-
+
BOOST_TEST(test("0.0", fixed, 0.0));
BOOST_TEST(test("1.0", fixed, 1.0));
-
+
BOOST_TEST(test("0.0", fixed, 0.000012345));
BOOST_TEST(test("0.0", fixed, 0.00012345));
BOOST_TEST(test("0.001", fixed, 0.0012345));
@@ -369,7 +411,7 @@
{
using namespace boost::spirit::ascii;
-
+
///////////////////////////////////////////////////////////////////////
// test NaN and Inf
BOOST_TEST(test("NAN", upper[double_],
@@ -381,7 +423,7 @@
BOOST_TEST(test("-INF", upper[double_],
-std::numeric_limits<double>::infinity()));
- typedef karma::real_spec<double, signed_policy<double> > signed_type;
+ typedef karma::real_generator<double, signed_policy<double> > signed_type;
signed_type const signed_ = signed_type();
BOOST_TEST(test("+NAN", upper[signed_],
@@ -400,7 +442,7 @@
#if BOOST_VERSION > 103600
{
using boost::math::concepts::real_concept;
- typedef karma::real_spec<real_concept> custom_type;
+ typedef karma::real_generator<real_concept> custom_type;
custom_type const custom = custom_type();
BOOST_TEST(test("0.0", custom, real_concept(0.0)));
@@ -409,7 +451,7 @@
BOOST_TEST(test("1.001", custom, real_concept(1.001)));
BOOST_TEST(test("1.01", custom, real_concept(1.010)));
BOOST_TEST(test("1.1", custom, real_concept(1.100)));
-
+
BOOST_TEST(test("1.234e-04", custom, real_concept(0.00012345)));
BOOST_TEST(test("0.001", custom, real_concept(0.0012345)));
BOOST_TEST(test("0.012", custom, real_concept(0.012345)));
@@ -420,18 +462,18 @@
BOOST_TEST(test("1234.5", custom, real_concept(1234.5)));
BOOST_TEST(test("12342.0", custom, real_concept(12342.)));
BOOST_TEST(test("1.234e05", custom, real_concept(123420.)));
-
+
BOOST_TEST(test("-1.0", custom, real_concept(-1.0)));
BOOST_TEST(test("-1.234", custom, real_concept(-1.2345)));
BOOST_TEST(test("-1.235", custom, real_concept(-1.2346)));
BOOST_TEST(test("-1234.2", custom, real_concept(-1234.2)));
-
+
BOOST_TEST(test("1.0", custom(real_concept(1.0))));
BOOST_TEST(test("1.0", custom(real_concept(1.0001))));
BOOST_TEST(test("1.001", custom(real_concept(1.001))));
BOOST_TEST(test("1.01", custom(real_concept(1.010))));
BOOST_TEST(test("1.1", custom(real_concept(1.100))));
-
+
BOOST_TEST(test("1.234e-04", custom(real_concept(0.00012345))));
BOOST_TEST(test("0.001", custom(real_concept(0.0012345))));
BOOST_TEST(test("0.012", custom(real_concept(0.012345))));
@@ -445,5 +487,23 @@
}
#endif
+ {
+ ///////////////////////////////////////////////////////////////////////
+ typedef karma::real_generator<double, bordercase_policy<double> >
+ bordercase_type;
+ bordercase_type const bordercase = bordercase_type();
+
+// BOOST_TEST(test("-5.7222349715140557e307",
+// bordercase(-5.7222349715140557e307)));
+
+ BOOST_TEST(test("1.7976931348623158e308",
+ bordercase(1.7976931348623158e308))); // DBL_MAX
+ BOOST_TEST(test("-1.7976931348623158e308",
+ bordercase(-1.7976931348623158e308))); // -DBL_MAX
+ BOOST_TEST(test("2.2250738585072014e-308",
+ bordercase(2.2250738585072014e-308))); // DBL_MIN
+ BOOST_TEST(test("-2.2250738585072014e-308",
+ bordercase(-2.2250738585072014e-308))); // -DBL_MIN
+ }
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/karma/right_alignment.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/right_alignment.cpp (original)
+++ trunk/libs/spirit/test/karma/right_alignment.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -14,13 +14,13 @@
#include "test.hpp"
-using namespace spirit_test;
-
///////////////////////////////////////////////////////////////////////////////
int
main()
{
+ using namespace spirit_test;
using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
{
BOOST_TEST(test(" x", right_align[char_('x')]));
@@ -40,18 +40,18 @@
BOOST_TEST(test("*********x", right_align(char_('*'))['x']));
BOOST_TEST(test(" abc", right_align[lit("abc")]));
- BOOST_TEST(test(" abc", right_align[lit], "abc"));
+ BOOST_TEST(test(" abc", right_align[string], "abc"));
BOOST_TEST(test(" abc", right_align(10)[lit("abc")]));
- BOOST_TEST(test(" abc", right_align(10)[lit], "abc"));
+ BOOST_TEST(test(" abc", right_align(10)[string], "abc"));
BOOST_TEST(test(" abc", right_align(10)["abc"]));
BOOST_TEST(test("*******abc", right_align(10, char_('*'))[lit("abc")]));
- BOOST_TEST(test("*******abc", right_align(10, '*')[lit], "abc"));
+ BOOST_TEST(test("*******abc", right_align(10, '*')[string], "abc"));
BOOST_TEST(test("*******abc", right_align(10, '*')["abc"]));
BOOST_TEST(test("*******abc", right_align(char_('*'))[lit("abc")]));
- BOOST_TEST(test("*******abc", right_align(char_('*'))[lit], "abc"));
+ BOOST_TEST(test("*******abc", right_align(char_('*'))[string], "abc"));
BOOST_TEST(test("*******abc", right_align(char_('*'))["abc"]));
BOOST_TEST(test(" 100", right_align[int_(100)]));
Modified: trunk/libs/spirit/test/karma/rule_fail.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/rule_fail.cpp (original)
+++ trunk/libs/spirit/test/karma/rule_fail.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -19,20 +19,19 @@
using namespace boost::spirit::karma;
using namespace boost::spirit::ascii;
-// this test must fail compiling
+// this test must fail compiling as the rule is used with an incompatible
+// delimiter type
int main()
{
- using boost::make_function_output_iterator;
- using spirit_test::make_string_appender;
-
+ typedef spirit_test::output_iterator<char>::type outiter_type;
+
std::string generated;
-
- rule<char const*, rule<char const*> > def;
+
+ rule<outiter_type, rule<outiter_type> > def;
def = int_(1) << ',' << int_(0);
-
- bool r = generate_delimited(
- make_function_output_iterator(make_string_appender(generated)),
- def, char_('%') << '\n');
+
+ std::back_insert_iterator<std::string> outit(generated);
+ bool r = generate_delimited(outit, def, char_('%') << '\n');
return 0;
}
Modified: trunk/libs/spirit/test/karma/sequence.cpp
==============================================================================
--- trunk/libs/spirit/test/karma/sequence.cpp (original)
+++ trunk/libs/spirit/test/karma/sequence.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -8,7 +8,6 @@
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/karma_char.hpp>
#include <boost/spirit/include/karma_string.hpp>
#include <boost/spirit/include/karma_numeric.hpp>
@@ -16,11 +15,11 @@
#include <boost/spirit/include/karma_operator.hpp>
#include <boost/spirit/include/karma_directive.hpp>
#include <boost/spirit/include/karma_action.hpp>
-#include <boost/fusion/include/vector.hpp>
#include <boost/spirit/include/support_unused.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
+#include <boost/fusion/include/vector.hpp>
#include "test.hpp"
@@ -31,8 +30,9 @@
main()
{
using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
namespace fusion = boost::fusion;
-
+
{
{
BOOST_TEST(test("xi", char_('x') << char_('i')));
@@ -49,12 +49,12 @@
BOOST_TEST(test_delimited("Hello , World ",
lit("Hello") << ',' << "World", char(' ')));
}
-
+
{
fusion::vector<char, char, std::string> p ('a', 'b', "cdefg");
- BOOST_TEST(test("abcdefg", char_ << char_ << lit, p));
+ BOOST_TEST(test("abcdefg", char_ << char_ << string, p));
BOOST_TEST(test_delimited("a b cdefg ",
- char_ << char_ << lit, p, char(' ')));
+ char_ << char_ << string, p, char(' ')));
}
{
@@ -75,16 +75,26 @@
}
{
- // literal generators do not need a parameter
+ // literal generators do not need an attribute
fusion::vector<char, char> p('a', 'c');
BOOST_TEST(test("abc", char_ << 'b' << char_, p));
BOOST_TEST(test_delimited("a b c ",
char_ << 'b' << char_, p, char(' ')));
}
-
+
+ {
+ std::list<int> v;
+ v.push_back(1);
+ v.push_back(2);
+ v.push_back(3);
+ BOOST_TEST(test("123", int_ << int_ << int_, v));
+ BOOST_TEST(test_delimited("1 2 3 ", int_ << int_ << int_, v, ' '));
+ BOOST_TEST(test("1,2,3", int_ << ',' << int_ << ',' << int_, v));
+ BOOST_TEST(test_delimited("1 , 2 , 3 ",
+ int_ << ',' << int_ << ',' << int_, v, ' '));
+ }
+
{
- using namespace boost::spirit::ascii;
-
BOOST_TEST(test("aa", lower[char_('A') << 'a']));
BOOST_TEST(test_delimited("BEGIN END ",
upper[lit("begin") << "end"], char(' ')));
@@ -92,20 +102,18 @@
upper[lit("begin") << "nend"], char(' ')));
BOOST_TEST(test("Aa ", left_align[char_('A') << 'a']));
- BOOST_TEST(test(" Aa ", center[char_('A') << 'a']));
- BOOST_TEST(test(" Aa", right_align[char_('A') << 'a']));
+// BOOST_TEST(test(" Aa ", center[char_('A') << 'a']));
+// BOOST_TEST(test(" Aa", right_align[char_('A') << 'a']));
}
// action tests
{
using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
- using namespace boost::spirit::ascii;
BOOST_TEST(test("abcdefg",
- (char_ << char_ << lit)[_1 = 'a', _2 = 'b', _3 = "cdefg"]));
+ (char_ << char_ << string)[_1 = 'a', _2 = 'b', _3 = "cdefg"]));
BOOST_TEST(test_delimited("a b cdefg ",
- (char_ << char_ << lit)[_1 = 'a', _2 = 'b', _3 = "cdefg"],
+ (char_ << char_ << string)[_1 = 'a', _2 = 'b', _3 = "cdefg"],
char(' ')));
BOOST_TEST(test_delimited("a 12 c ",
@@ -121,11 +129,11 @@
BOOST_TEST(test("AA", upper[char_ << 'a'][_1 = 'a']));
BOOST_TEST(test("Aa ", left_align[char_ << 'a'][_1 = 'A']));
- BOOST_TEST(test(" Aa ", center[char_ << 'a'][_1 = 'A']));
- BOOST_TEST(test(" Aa", right_align[char_ << 'a'][_1 = 'A']));
+// BOOST_TEST(test(" Aa ", center[char_ << 'a'][_1 = 'A']));
+// BOOST_TEST(test(" Aa", right_align[char_ << 'a'][_1 = 'A']));
}
}
-
+
return boost::report_errors();
}
Added: trunk/libs/spirit/test/karma/stream.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/stream.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,144 @@
+// Copyright (c) 2001-2009 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 <iostream>
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_stream.hpp>
+#include <boost/spirit/include/karma_directive.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include "test.hpp"
+
+using namespace spirit_test;
+
+// a simple complex number representation z = a + bi
+struct complex
+{
+ complex (double a, double b)
+ : a(a), b(b)
+ {}
+
+ double a;
+ double b;
+
+ template <typename Char>
+ friend std::basic_ostream<Char>&
+ operator<< (std::basic_ostream<Char>& os, complex z)
+ {
+ os << "{" << z.a << "," << z.b << "}";
+ return os;
+ }
+};
+
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ using namespace boost::spirit;
+
+ {
+ BOOST_TEST(test("x", stream, 'x'));
+ BOOST_TEST(test("xyz", stream, "xyz"));
+ BOOST_TEST(test("xyz", stream, std::string("xyz")));
+ BOOST_TEST(test("1", stream, 1));
+ BOOST_TEST(test("1.1", stream, 1.1));
+ BOOST_TEST(test("{1.2,2.4}", stream, complex(1.2, 2.4)));
+
+ BOOST_TEST(test(L"x", wstream, L'x'));
+ BOOST_TEST(test(L"xyz", wstream, L"xyz"));
+ BOOST_TEST(test(L"xyz", wstream, std::basic_string<wchar_t>(L"xyz")));
+ BOOST_TEST(test(L"1", wstream, 1));
+ BOOST_TEST(test(L"1.1", wstream, 1.1));
+ BOOST_TEST(test(L"{1.2,2.4}", wstream, complex(1.2, 2.4)));
+ }
+
+ {
+ BOOST_TEST(test("x", stream('x')));
+ BOOST_TEST(test("xyz", stream("xyz")));
+ BOOST_TEST(test("xyz", stream(std::string("xyz"))));
+ BOOST_TEST(test("1", stream(1)));
+ BOOST_TEST(test("1.1", stream(1.1)));
+ BOOST_TEST(test("{1.2,2.4}", stream(complex(1.2, 2.4))));
+
+ BOOST_TEST(test(L"x", wstream(L'x')));
+ BOOST_TEST(test(L"xyz", wstream(L"xyz")));
+ BOOST_TEST(test(L"xyz", wstream(std::basic_string<wchar_t>(L"xyz"))));
+ BOOST_TEST(test(L"1", wstream(1)));
+ BOOST_TEST(test(L"1.1", wstream(1.1)));
+ BOOST_TEST(test(L"{1.2,2.4}", wstream(complex(1.2, 2.4))));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test("x", lower[stream], 'X'));
+ BOOST_TEST(test("xyz", lower[stream], "XYZ"));
+ BOOST_TEST(test("xyz", lower[stream], std::string("XYZ")));
+ BOOST_TEST(test("X", upper[stream], 'x'));
+ BOOST_TEST(test("XYZ", upper[stream], "xyz"));
+ BOOST_TEST(test("XYZ", upper[stream], std::string("xyz")));
+
+ BOOST_TEST(test(L"x", lower[wstream], L'X'));
+ BOOST_TEST(test(L"xyz", lower[wstream], L"XYZ"));
+ BOOST_TEST(test(L"xyz", lower[wstream], std::basic_string<wchar_t>(L"XYZ")));
+ BOOST_TEST(test(L"X", upper[wstream], L'x'));
+ BOOST_TEST(test(L"XYZ", upper[wstream], L"xyz"));
+ BOOST_TEST(test(L"XYZ", upper[wstream], std::basic_string<wchar_t>(L"xyz")));
+ }
+
+ {
+ BOOST_TEST(test_delimited("x ", stream, 'x', ' '));
+ BOOST_TEST(test_delimited("xyz ", stream, "xyz", ' '));
+ BOOST_TEST(test_delimited("xyz ", stream, std::string("xyz"), ' '));
+ BOOST_TEST(test_delimited("1 ", stream, 1, ' '));
+ BOOST_TEST(test_delimited("1.1 ", stream, 1.1, ' '));
+ BOOST_TEST(test_delimited("{1.2,2.4} ", stream, complex(1.2, 2.4), ' '));
+
+ BOOST_TEST(test_delimited(L"x ", wstream, L'x', L' '));
+ BOOST_TEST(test_delimited(L"xyz ", wstream, L"xyz", L' '));
+ BOOST_TEST(test_delimited(L"xyz ", wstream, std::basic_string<wchar_t>(L"xyz"), L' '));
+ BOOST_TEST(test_delimited(L"1 ", wstream, 1, ' '));
+ BOOST_TEST(test_delimited(L"1.1 ", wstream, 1.1, ' '));
+ BOOST_TEST(test_delimited(L"{1.2,2.4} ", wstream, complex(1.2, 2.4), ' '));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test_delimited("x ", lower[stream], 'X', ' '));
+ BOOST_TEST(test_delimited("xyz ", lower[stream], "XYZ", ' '));
+ BOOST_TEST(test_delimited("xyz ", lower[stream], std::string("XYZ"), ' '));
+ BOOST_TEST(test_delimited("X ", upper[stream], 'x', ' '));
+ BOOST_TEST(test_delimited("XYZ ", upper[stream], "xyz", ' '));
+ BOOST_TEST(test_delimited("XYZ ", upper[stream], std::string("xyz"), ' '));
+
+ BOOST_TEST(test_delimited(L"x ", lower[wstream], L'X', L' '));
+ BOOST_TEST(test_delimited(L"xyz ", lower[wstream], L"XYZ", L' '));
+ BOOST_TEST(test_delimited(L"xyz ", lower[wstream], std::basic_string<wchar_t>(L"XYZ"), L' '));
+ BOOST_TEST(test_delimited(L"X ", upper[wstream], L'x', L' '));
+ BOOST_TEST(test_delimited(L"XYZ ", upper[wstream], L"xyz", ' '));
+ BOOST_TEST(test_delimited(L"XYZ ", upper[wstream], std::basic_string<wchar_t>(L"xyz"), L' '));
+ }
+
+ { // lazy streams
+ using namespace boost::phoenix;
+
+ std::basic_string<char> s("abc");
+ BOOST_TEST((test("abc", stream(val(s)))));
+ BOOST_TEST((test("abc", stream(ref(s)))));
+
+ std::basic_string<wchar_t> ws(L"abc");
+ BOOST_TEST((test(L"abc", wstream(val(ws)))));
+ BOOST_TEST((test(L"abc", wstream(ref(ws)))));
+ }
+
+ return boost::report_errors();
+}
Modified: trunk/libs/spirit/test/karma/test.hpp
==============================================================================
--- trunk/libs/spirit/test/karma/test.hpp (original)
+++ trunk/libs/spirit/test/karma/test.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -55,7 +55,8 @@
karma::what(g);
string_type generated;
- bool result = karma::generate(std::back_inserter(generated), g);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g);
return result && generated == expected;
}
@@ -71,15 +72,16 @@
karma::what(g);
string_type generated;
- bool result = karma::generate(std::back_inserter(generated), g);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g);
return result && generated == expected;
}
///////////////////////////////////////////////////////////////////////////
- template <typename Char, typename Generator, typename Parameter>
+ template <typename Char, typename Generator, typename Attribute>
inline bool test(Char const *expected, Generator const& g,
- Parameter const ¶meter)
+ Attribute const &attr)
{
namespace karma = boost::spirit::karma;
typedef std::basic_string<Char> string_type;
@@ -89,14 +91,15 @@
karma::what(g);
string_type generated;
- bool result = karma::generate(std::back_inserter(generated), g, parameter);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g, attr);
return result && generated == expected;
}
- template <typename Char, typename Generator, typename Parameter>
+ template <typename Char, typename Generator, typename Attribute>
inline bool test(std::basic_string<Char> const& expected, Generator const& g,
- Parameter const ¶meter)
+ Attribute const &attr)
{
namespace karma = boost::spirit::karma;
typedef std::basic_string<Char> string_type;
@@ -106,7 +109,8 @@
karma::what(g);
string_type generated;
- bool result = karma::generate(std::back_inserter(generated), g, parameter);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g, attr);
return result && generated == expected;
}
@@ -124,7 +128,8 @@
karma::what(g);
string_type generated;
- bool result = karma::generate_delimited(std::back_inserter(generated), g, d);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d);
return result && generated == expected;
}
@@ -141,16 +146,17 @@
karma::what(g);
string_type generated;
- bool result = karma::generate_delimited(std::back_inserter(generated), g, d);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d);
return result && generated == expected;
}
///////////////////////////////////////////////////////////////////////////
- template <typename Char, typename Generator, typename Parameter,
+ template <typename Char, typename Generator, typename Attribute,
typename Delimiter>
inline bool test_delimited(Char const *expected, Generator const& g,
- Parameter const ¶meter, Delimiter const& d)
+ Attribute const &attr, Delimiter const& d)
{
namespace karma = boost::spirit::karma;
typedef std::basic_string<Char> string_type;
@@ -160,16 +166,16 @@
karma::what(g);
string_type generated;
- bool result = karma::generate_delimited(std::back_inserter(generated),
- g, parameter, d);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d, attr);
return result && generated == expected;
}
- template <typename Char, typename Generator, typename Parameter,
+ template <typename Char, typename Generator, typename Attribute,
typename Delimiter>
inline bool test_delimited(std::basic_string<Char> const& expected,
- Generator const& g, Parameter const ¶meter, Delimiter const& d)
+ Generator const& g, Attribute const &attr, Delimiter const& d)
{
namespace karma = boost::spirit::karma;
typedef std::basic_string<Char> string_type;
@@ -179,8 +185,8 @@
karma::what(g);
string_type generated;
- bool result = karma::generate_delimited(std::back_inserter(generated),
- g, parameter, d);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d, attr);
return result && generated == expected;
}
@@ -199,16 +205,17 @@
karma::what(g);
string_type generated;
- bool result = karma::generate(std::back_inserter(generated), g);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g);
return result && !std::memcmp(generated.c_str(), expected, size);
}
///////////////////////////////////////////////////////////////////////////
- template <typename Generator, typename Parameter>
+ template <typename Generator, typename Attribute>
inline bool
binary_test(char const *expected, std::size_t size,
- Generator const& g, Parameter const ¶meter)
+ Generator const& g, Attribute const &attr)
{
namespace karma = boost::spirit::karma;
typedef std::basic_string<char> string_type;
@@ -218,7 +225,8 @@
karma::what(g);
string_type generated;
- bool result = karma::generate(std::back_inserter(generated), g, parameter);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g, attr);
return result && !std::memcmp(generated.c_str(), expected, size);
}
@@ -237,17 +245,17 @@
karma::what(g);
string_type generated;
- bool result = karma::generate_delimited(std::back_inserter(generated),
- g, d);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d);
return result && !std::memcmp(generated.c_str(), expected, size);
}
///////////////////////////////////////////////////////////////////////////
- template <typename Generator, typename Parameter, typename Delimiter>
+ template <typename Generator, typename Attribute, typename Delimiter>
inline bool
binary_test_delimited(char const *expected, std::size_t size,
- Generator const& g, Parameter const ¶meter, Delimiter const& d)
+ Generator const& g, Attribute const &attr, Delimiter const& d)
{
namespace karma = boost::spirit::karma;
typedef std::basic_string<char> string_type;
@@ -257,8 +265,8 @@
karma::what(g);
string_type generated;
- bool result = karma::generate_delimited(std::back_inserter(generated),
- g, parameter, d);
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d, attr);
return result && !std::memcmp(generated.c_str(), expected, size);
}
Added: trunk/libs/spirit/test/karma/test_attr.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/test_attr.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,121 @@
+// Copyright (c) 2001-2009 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_PP_IS_ITERATING)
+
+#if !defined(BOOST_SPIRIT_KARMA_TEST_ATTR_APR_23_2009_0605PM)
+#define BOOST_SPIRIT_KARMA_TEST_ATTR_APR_23_2009_0605PM
+
+#include <cstring>
+#include <string>
+#include <iterator>
+#include <iostream>
+#include <typeinfo>
+
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_what.hpp>
+
+#include <boost/preprocessor/iterate.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+
+namespace spirit_test
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char>
+ struct output_iterator
+ {
+ typedef std::basic_string<Char> string_type;
+ typedef std::back_insert_iterator<string_type> type;
+ };
+}
+
+#define BOOST_PP_FILENAME_1 "karma/test_attr.hpp"
+#define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
+#include BOOST_PP_ITERATE()
+
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Preprocessor vertical repetition code
+//
+///////////////////////////////////////////////////////////////////////////////
+#else // defined(BOOST_PP_IS_ITERATING)
+
+#define N BOOST_PP_ITERATION()
+
+namespace spirit_test
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test(Char const *expected, Generator const& g
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate(outit, g, BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return result && generated == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator, typename Delimiter
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_delimited(Char const *expected, Generator const& g
+ , Delimiter const& d, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d
+ , BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return result && generated == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator, typename Delimiter
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_predelimited(Char const *expected, Generator const& g
+ , Delimiter const& d
+ , BOOST_SCOPED_ENUM(boost::spirit::karma::delimit_flag) pre_delimit
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
+ {
+ namespace karma = boost::spirit::karma;
+ typedef std::basic_string<Char> string_type;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all generators have it:
+ karma::what(g);
+
+ string_type generated;
+ std::back_insert_iterator<string_type> outit(generated);
+ bool result = karma::generate_delimited(outit, g, d
+ , pre_delimit, BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return result && generated == expected;
+ }
+
+} // namespace spirit_test
+
+#undef N
+
+#endif
Added: trunk/libs/spirit/test/karma/test_manip_attr.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/test_manip_attr.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,87 @@
+// Copyright (c) 2001-2009 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_PP_IS_ITERATING)
+
+#if !defined(BOOST_SPIRIT_KARMA_TEST_MANIP_ATTR_APR_24_2009_0834AM)
+#define BOOST_SPIRIT_KARMA_TEST_MANIP_ATTR_APR_24_2009_0834AM
+
+#include <cstring>
+#include <string>
+#include <iterator>
+#include <iostream>
+#include <typeinfo>
+
+#include <boost/spirit/include/karma_stream.hpp>
+
+#include <boost/preprocessor/iterate.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+
+#define BOOST_PP_FILENAME_1 "karma/test_manip_attr.hpp"
+#define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
+#include BOOST_PP_ITERATE()
+
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Preprocessor vertical repetition code
+//
+///////////////////////////////////////////////////////////////////////////////
+#else // defined(BOOST_PP_IS_ITERATING)
+
+#define N BOOST_PP_ITERATION()
+
+namespace spirit_test
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test(Char const *expected, Generator const& g
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
+ {
+ namespace karma = boost::spirit::karma;
+
+ std::ostringstream ostrm;
+ ostrm << karma::format(g, BOOST_PP_ENUM_PARAMS(N, attr));
+ return ostrm.good() && ostrm.str() == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator, typename Delimiter
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_delimited(Char const *expected, Generator const& g
+ , Delimiter const& d, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
+ {
+ namespace karma = boost::spirit::karma;
+
+ std::ostringstream ostrm;
+ ostrm << karma::format_delimited(g, d, BOOST_PP_ENUM_PARAMS(N, attr));
+ return ostrm.good() && ostrm.str() == expected;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Generator, typename Delimiter
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_predelimited(Char const *expected, Generator const& g
+ , Delimiter const& d
+ , BOOST_SCOPED_ENUM(boost::spirit::karma::delimit_flag) pre_delimit
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
+ {
+ namespace karma = boost::spirit::karma;
+
+ std::ostringstream ostrm;
+ ostrm << karma::format_delimited(g, d, pre_delimit
+ , BOOST_PP_ENUM_PARAMS(N, attr));
+ return ostrm.good() && ostrm.str() == expected;
+ }
+
+} // namespace spirit_test
+
+#undef N
+
+#endif
Added: trunk/libs/spirit/test/karma/tricky_alignment.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/karma/tricky_alignment.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,130 @@
+// Copyright (c) 2001-2009 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>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/karma_char.hpp>
+#include <boost/spirit/include/karma_string.hpp>
+#include <boost/spirit/include/karma_numeric.hpp>
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_directive.hpp>
+
+#include "test.hpp"
+
+///////////////////////////////////////////////////////////////////////////////
+int
+main()
+{
+ using namespace spirit_test;
+ using namespace boost::spirit;
+ using namespace boost::spirit::ascii;
+
+ {
+ BOOST_TEST(test("x *****", left_align(15, '*')[left_align[char_('x')]]));
+ BOOST_TEST(test(" x *****", left_align(15, '*')[center[char_('x')]]));
+ BOOST_TEST(test(" x*****", left_align(15, '*')[right_align[char_('x')]]));
+
+ BOOST_TEST(test("*****x ", right_align(15, '*')[left_align[char_('x')]]));
+ BOOST_TEST(test("***** x ", right_align(15, '*')[center[char_('x')]]));
+ BOOST_TEST(test("***** x", right_align(15, '*')[right_align[char_('x')]]));
+
+ BOOST_TEST(test("***x **", center(15, '*')[left_align[char_('x')]]));
+ BOOST_TEST(test("*** x **", center(15, '*')[center[char_('x')]]));
+ BOOST_TEST(test("*** x**", center(15, '*')[right_align[char_('x')]]));
+
+ BOOST_TEST(test("ab *****", left_align(15, '*')[left_align[lit("ab")]]));
+ BOOST_TEST(test(" ab *****", left_align(15, '*')[center[lit("ab")]]));
+ BOOST_TEST(test(" ab*****", left_align(15, '*')[right_align[lit("ab")]]));
+
+ BOOST_TEST(test("*****ab ", right_align(15, '*')[left_align[lit("ab")]]));
+ BOOST_TEST(test("***** ab ", right_align(15, '*')[center[lit("ab")]]));
+ BOOST_TEST(test("***** ab", right_align(15, '*')[right_align[lit("ab")]]));
+
+ BOOST_TEST(test("***ab **", center(15, '*')[left_align[lit("ab")]]));
+ BOOST_TEST(test("*** ab **", center(15, '*')[center[lit("ab")]]));
+ BOOST_TEST(test("*** ab**", center(15, '*')[right_align[lit("ab")]]));
+ }
+
+ {
+ BOOST_TEST(test("x ******", left_align(16, '*')[left_align[char_('x')]]));
+ BOOST_TEST(test(" x ******", left_align(16, '*')[center[char_('x')]]));
+ BOOST_TEST(test(" x******", left_align(16, '*')[right_align[char_('x')]]));
+
+ BOOST_TEST(test("******x ", right_align(16, '*')[left_align[char_('x')]]));
+ BOOST_TEST(test("****** x ", right_align(16, '*')[center[char_('x')]]));
+ BOOST_TEST(test("****** x", right_align(16, '*')[right_align[char_('x')]]));
+
+ BOOST_TEST(test("***x ***", center(16, '*')[left_align[char_('x')]]));
+ BOOST_TEST(test("*** x ***", center(16, '*')[center[char_('x')]]));
+ BOOST_TEST(test("*** x***", center(16, '*')[right_align[char_('x')]]));
+
+ BOOST_TEST(test("ab ******", left_align(16, '*')[left_align[lit("ab")]]));
+ BOOST_TEST(test(" ab ******", left_align(16, '*')[center[lit("ab")]]));
+ BOOST_TEST(test(" ab******", left_align(16, '*')[right_align[lit("ab")]]));
+
+ BOOST_TEST(test("******ab ", right_align(16, '*')[left_align[lit("ab")]]));
+ BOOST_TEST(test("****** ab ", right_align(16, '*')[center[lit("ab")]]));
+ BOOST_TEST(test("****** ab", right_align(16, '*')[right_align[lit("ab")]]));
+
+ BOOST_TEST(test("***ab ***", center(16, '*')[left_align[lit("ab")]]));
+ BOOST_TEST(test("*** ab ***", center(16, '*')[center[lit("ab")]]));
+ BOOST_TEST(test("*** ab***", center(16, '*')[right_align[lit("ab")]]));
+ }
+
+ {
+ BOOST_TEST(test("x ****", left_align(15, '*')[left_align(11)[char_('x')]]));
+ BOOST_TEST(test(" x ****", left_align(15, '*')[center(11)[char_('x')]]));
+ BOOST_TEST(test(" x****", left_align(15, '*')[right_align(11)[char_('x')]]));
+
+ BOOST_TEST(test("****x ", right_align(15, '*')[left_align(11)[char_('x')]]));
+ BOOST_TEST(test("**** x ", right_align(15, '*')[center(11)[char_('x')]]));
+ BOOST_TEST(test("**** x", right_align(15, '*')[right_align(11)[char_('x')]]));
+
+ BOOST_TEST(test("**x **", center(15, '*')[left_align(11)[char_('x')]]));
+ BOOST_TEST(test("** x **", center(15, '*')[center(11)[char_('x')]]));
+ BOOST_TEST(test("** x**", center(15, '*')[right_align(11)[char_('x')]]));
+
+ BOOST_TEST(test("ab ****", left_align(15, '*')[left_align(11)[lit("ab")]]));
+ BOOST_TEST(test(" ab ****", left_align(15, '*')[center(11)[lit("ab")]]));
+ BOOST_TEST(test(" ab****", left_align(15, '*')[right_align(11)[lit("ab")]]));
+
+ BOOST_TEST(test("****ab ", right_align(15, '*')[left_align(11)[lit("ab")]]));
+ BOOST_TEST(test("**** ab ", right_align(15, '*')[center(11)[lit("ab")]]));
+ BOOST_TEST(test("**** ab", right_align(15, '*')[right_align(11)[lit("ab")]]));
+
+ BOOST_TEST(test("**ab **", center(15, '*')[left_align(11)[lit("ab")]]));
+ BOOST_TEST(test("** ab **", center(15, '*')[center(11)[lit("ab")]]));
+ BOOST_TEST(test("** ab**", center(15, '*')[right_align(11)[lit("ab")]]));
+ }
+
+ {
+ BOOST_TEST(test("x *****", left_align(16, '*')[left_align(11)[char_('x')]]));
+ BOOST_TEST(test(" x *****", left_align(16, '*')[center(11)[char_('x')]]));
+ BOOST_TEST(test(" x*****", left_align(16, '*')[right_align(11)[char_('x')]]));
+
+ BOOST_TEST(test("*****x ", right_align(16, '*')[left_align(11)[char_('x')]]));
+ BOOST_TEST(test("***** x ", right_align(16, '*')[center(11)[char_('x')]]));
+ BOOST_TEST(test("***** x", right_align(16, '*')[right_align(11)[char_('x')]]));
+
+ BOOST_TEST(test("***x **", center(16, '*')[left_align(11)[char_('x')]]));
+ BOOST_TEST(test("*** x **", center(16, '*')[center(11)[char_('x')]]));
+ BOOST_TEST(test("*** x**", center(16, '*')[right_align(11)[char_('x')]]));
+
+ BOOST_TEST(test("ab *****", left_align(16, '*')[left_align(11)[lit("ab")]]));
+ BOOST_TEST(test(" ab *****", left_align(16, '*')[center(11)[lit("ab")]]));
+ BOOST_TEST(test(" ab*****", left_align(16, '*')[right_align(11)[lit("ab")]]));
+
+ BOOST_TEST(test("*****ab ", right_align(16, '*')[left_align(11)[lit("ab")]]));
+ BOOST_TEST(test("***** ab ", right_align(16, '*')[center(11)[lit("ab")]]));
+ BOOST_TEST(test("***** ab", right_align(16, '*')[right_align(11)[lit("ab")]]));
+
+ BOOST_TEST(test("***ab **", center(16, '*')[left_align(11)[lit("ab")]]));
+ BOOST_TEST(test("*** ab **", center(16, '*')[center(11)[lit("ab")]]));
+ BOOST_TEST(test("*** ab**", center(16, '*')[right_align(11)[lit("ab")]]));
+ }
+
+ return boost::report_errors();
+}
Modified: trunk/libs/spirit/test/lex/lexertl1.cpp
==============================================================================
--- trunk/libs/spirit/test/lex/lexertl1.cpp (original)
+++ trunk/libs/spirit/test/lex/lexertl1.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -4,12 +4,11 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include "test.hpp"
///////////////////////////////////////////////////////////////////////////////
-int
-main()
+int main()
{
using namespace boost::spirit;
using namespace spirit_test;
@@ -19,53 +18,53 @@
// initialize tokens
typedef lex::token_def<std::string> token_def;
-
+
std::size_t const CCOMMENT = 1;
std::size_t const CPPCOMMENT = 2;
token_def c_comment ("\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT);
token_def cpp_comment ("\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT);
-
+
typedef std::string::iterator base_iterator_type;
- typedef lex::lexertl_token<base_iterator_type> token_type;
- typedef lex::lexertl_lexer<token_type> lexer_type;
- typedef lex::lexer_def<lexer_type> lexer_def;
+ typedef lex::lexertl::token<base_iterator_type> token_type;
+ typedef lex::lexertl::lexer<token_type> lexer_type;
+ typedef lex::lexer<lexer_type> lexer_def;
{
// initialize lexer
- lexer_def def;
- def.self = c_comment;
- def.self += cpp_comment;
-
+ lexer_def lex;
+ lex.self = c_comment;
+ lex.self += cpp_comment;
+
// test lexer for two different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
}
-
+
{
// initialize lexer
- lexer_def def;
- def.self = c_comment | cpp_comment;
-
+ lexer_def lex;
+ lex.self = c_comment | cpp_comment;
+
// test lexer for two different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
}
-
+
{
+ using namespace boost::spirit::ascii;
+
// initialize lexer
- lexer_def def;
- def.self = token_def('+') | '-' | c_comment;
- def.self += '*' | cpp_comment;
-
+ lexer_def lex;
+ lex.self = token_def('+') | '-' | c_comment;
+ lex.self += char_('*') | '/' | cpp_comment;
+
// test lexer for two different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
BOOST_TEST(test (lex, "+", '+'));
BOOST_TEST(test (lex, "-", '-'));
BOOST_TEST(test (lex, "*", '*'));
+ BOOST_TEST(test (lex, "/", '/'));
}
return boost::report_errors();
Modified: trunk/libs/spirit/test/lex/lexertl2.cpp
==============================================================================
--- trunk/libs/spirit/test/lex/lexertl2.cpp (original)
+++ trunk/libs/spirit/test/lex/lexertl2.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -4,7 +4,7 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include <string>
#include "test.hpp"
@@ -12,52 +12,48 @@
///////////////////////////////////////////////////////////////////////////////
// a simple lexer class
template <typename Lexer>
-struct lexertl_test : boost::spirit::lex::lexer_def<Lexer>
+struct lexertl_test
+ : boost::spirit::lex::lexer<Lexer>
{
typedef boost::spirit::lex::token_def<std::string> token_def;
static std::size_t const CCOMMENT = 1;
static std::size_t const CPPCOMMENT = 2;
-
- template <typename Self>
- void def(Self& self)
+
+ lexertl_test()
+ : c_comment("\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT)
+ , cpp_comment("\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT)
{
- c_comment = token_def("\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT);
- cpp_comment = token_def("\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT);
-
- self = c_comment;
- self += cpp_comment;
+ this->self = c_comment;
+ this->self += cpp_comment;
}
token_def c_comment, cpp_comment;
};
template <typename Lexer>
-struct wlexertl_test : boost::spirit::lex::lexer_def<Lexer>
+struct wlexertl_test
+ : boost::spirit::lex::lexer<Lexer>
{
- typedef
- boost::spirit::lex::token_def<std::basic_string<wchar_t>, wchar_t>
- token_def;
+ typedef boost::spirit::lex::token_def<std::basic_string<wchar_t>, wchar_t>
+ token_def;
static std::size_t const CCOMMENT = 1;
static std::size_t const CPPCOMMENT = 2;
-
- template <typename Self>
- void def(Self& self)
+
+ wlexertl_test()
+ : c_comment(L"\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT)
+ , cpp_comment(L"\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT)
{
- c_comment = token_def(L"\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT);
- cpp_comment = token_def(L"\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT);
-
- self = c_comment;
- self += cpp_comment;
+ this->self = c_comment;
+ this->self += cpp_comment;
}
token_def c_comment, cpp_comment;
};
///////////////////////////////////////////////////////////////////////////////
-int
-main()
+int main()
{
using namespace boost::spirit;
using namespace spirit_test;
@@ -67,30 +63,29 @@
{
// initialize lexer
typedef std::string::iterator base_iterator_type;
- typedef lex::lexertl_token<base_iterator_type> token_type;
- typedef lex::lexertl_lexer<token_type> lexer_type;
+ typedef lex::lexertl::token<base_iterator_type> token_type;
+ typedef lex::lexertl::lexer<token_type> lexer_type;
typedef lexertl_test<lexer_type> lexer_def;
-
+
// test lexer for two different input strings
- lexer_def def;
- lex::lexer<lexer_def> lex(def);
+ lexer_def lex;
BOOST_TEST(test (lex, "/* this is a comment */", lexer_def::CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", lexer_def::CPPCOMMENT));
}
-
+
{
// initialize lexer
typedef std::basic_string<wchar_t>::iterator base_iterator_type;
- typedef lex::lexertl_token<base_iterator_type> token_type;
- typedef lex::lexertl_lexer<token_type> lexer_type;
+ typedef lex::lexertl::token<base_iterator_type> token_type;
+ typedef lex::lexertl::lexer<token_type> lexer_type;
typedef wlexertl_test<lexer_type> lexer_def;
-
+
// test lexer for two different input strings
- lexer_def def;
- lex::lexer<lexer_def> lex(def);
+ lexer_def lex;
BOOST_TEST(test (lex, L"/* this is a comment */", lexer_def::CCOMMENT));
BOOST_TEST(test (lex, L"// this is a comment as well\n", lexer_def::CPPCOMMENT));
}
-
+
return boost::report_errors();
}
+
Modified: trunk/libs/spirit/test/lex/lexertl3.cpp
==============================================================================
--- trunk/libs/spirit/test/lex/lexertl3.cpp (original)
+++ trunk/libs/spirit/test/lex/lexertl3.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -4,12 +4,11 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include "test.hpp"
///////////////////////////////////////////////////////////////////////////////
-int
-main()
+int main()
{
using namespace boost::spirit;
using namespace boost::spirit::lex;
@@ -17,32 +16,29 @@
// initialize tokens
typedef lex::token_def<std::string> token_def;
-
+
std::size_t const CCOMMENT = 1;
std::size_t const CPPCOMMENT = 2;
token_def c_comment ("\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT);
token_def cpp_comment ("\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT);
token_def ws_tok ("[\\v\\f\\n\\r]*");
-
+
typedef std::string::iterator base_iterator_type;
- typedef lex::lexertl_token<base_iterator_type> token_type;
- typedef lex::lexertl_lexer<token_type> lexer_type;
-
- typedef lexer_type::token_set token_set;
- typedef lex::lexer_def<lexer_type> lexer_def;
+ typedef lex::lexertl::token<base_iterator_type> token_type;
+ typedef lex::lexertl::lexer<token_type> lexer_type;
+
+ typedef lex::lexer<lexer_type> lexer_def;
+ typedef lexer_def::token_set token_set;
- lexer_def def;
-
{
// initialize lexer
std::string str("def");
- lexer_def def;
- def.self = c_comment;
- def.self += cpp_comment | '1' | '2' | '3' | "abc" | str;
- def.self += token_def(' ') | '\t' | ws_tok;
+ lexer_def lex;
+ lex.self = c_comment;
+ lex.self += cpp_comment | '1' | '2' | '3' | "abc" | str;
+ lex.self += token_def(' ') | '\t' | ws_tok;
// test lexer for two different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
BOOST_TEST(test (lex, "\n\n\v\f\r", ws_tok.id()));
@@ -51,20 +47,19 @@
BOOST_TEST(test (lex, "abc"));
BOOST_TEST(test (lex, "def"));
}
-
+
{
// init a token set
token_set ws;
ws = token_def(' ') | '\t' | ws_tok;
// initialize lexer
- lexer_def def;
- def.self = c_comment;
- def.self += cpp_comment | '1' | '2' | '3';
- def.self("WHITESPACE") = ws;
+ lexer_def lex;
+ lex.self = c_comment;
+ lex.self += cpp_comment | '1' | '2' | '3';
+ lex.self("WHITESPACE") = ws;
// test lexer for two different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
BOOST_TEST(test (lex, "2", '2'));
Modified: trunk/libs/spirit/test/lex/lexertl4.cpp
==============================================================================
--- trunk/libs/spirit/test/lex/lexertl4.cpp (original)
+++ trunk/libs/spirit/test/lex/lexertl4.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -4,12 +4,11 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include "test.hpp"
///////////////////////////////////////////////////////////////////////////////
-int
-main()
+int main()
{
using namespace boost::spirit;
using namespace boost::spirit::lex;
@@ -17,39 +16,38 @@
// initialize tokens
typedef lex::token_def<std::string> token_def;
-
+
std::size_t const CCOMMENT = 1;
std::size_t const CPPCOMMENT = 2;
std::size_t const TOKEN_ID_ABC = 1000;
std::size_t const TOKEN_ID_STR = 1001;
std::size_t const TOKEN_ID_WS = 1002;
-
+
token_def c_comment ("\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/", CCOMMENT);
token_def cpp_comment ("\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)", CPPCOMMENT);
token_def ws_tok ("[\\v\\f\\n\\r]*", TOKEN_ID_WS);
-
+
typedef std::string::iterator base_iterator_type;
- typedef lex::lexertl_token<base_iterator_type> token_type;
- typedef lex::lexertl_lexer<token_type> lexer_type;
-
- typedef lexer_type::token_set token_set;
- typedef lex::lexer_def<lexer_type> lexer_def;
+ typedef lex::lexertl::token<base_iterator_type> token_type;
+ typedef lex::lexertl::lexer<token_type> lexer_type;
+
+ typedef lex::lexer<lexer_type> lexer_def;
+ typedef lexer_def::token_set token_set;
std::string str("def");
{
// initialize lexer
- lexer_def def;
- def.self.add
+ lexer_def lex;
+ lex.self.add
(c_comment)(cpp_comment)
('1')('2')('3')
("abc", TOKEN_ID_ABC)
(str, TOKEN_ID_STR)
;
- def.self += token_def(' ') | '\t' | ws_tok;
+ lex.self += token_def(' ') | '\t' | ws_tok;
// test lexer for different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
BOOST_TEST(test (lex, "\n\n\v\f\r", ws_tok.id()));
@@ -58,7 +56,7 @@
BOOST_TEST(test (lex, "abc", TOKEN_ID_ABC));
BOOST_TEST(test (lex, "def", TOKEN_ID_STR));
}
-
+
{
// init a token set
token_set ws;
@@ -68,18 +66,17 @@
;
// initialize lexer
- lexer_def def;
- def.self.add
+ lexer_def lex;
+ lex.self.add
(c_comment)(cpp_comment)
('1')('2')('3')
("abc", TOKEN_ID_ABC)
(str, TOKEN_ID_STR)
;
- def.self("WHITESPACE").add(ws);
+ lex.self("WHITESPACE").add(ws);
// test lexer for different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
BOOST_TEST(test (lex, "2", '2'));
Modified: trunk/libs/spirit/test/lex/lexertl5.cpp
==============================================================================
--- trunk/libs/spirit/test/lex/lexertl5.cpp (original)
+++ trunk/libs/spirit/test/lex/lexertl5.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -4,13 +4,12 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include "test.hpp"
///////////////////////////////////////////////////////////////////////////////
// test pattern definition capabilities
-int
-main()
+int main()
{
using namespace boost::spirit;
using namespace boost::spirit::lex;
@@ -18,46 +17,45 @@
// initialize tokens
typedef lex::token_def<std::string> token_def;
-
+
std::size_t const CCOMMENT = 1;
std::size_t const CPPCOMMENT = 2;
std::size_t const TOKEN_ID_ABC = 1000;
std::size_t const TOKEN_ID_STR = 1001;
std::size_t const TOKEN_ID_WS = 1002;
-
+
typedef std::string::iterator base_iterator_type;
- typedef lex::lexertl_token<base_iterator_type> token_type;
- typedef lex::lexertl_lexer<token_type> lexer_type;
-
- typedef lexer_type::token_set token_set;
- typedef lex::lexer_def<lexer_type> lexer_def;
+ typedef lex::lexertl::token<base_iterator_type> token_type;
+ typedef lex::lexertl::lexer<token_type> lexer_type;
+
+ typedef lex::lexer<lexer_type> lexer_def;
+ typedef lexer_def::token_set token_set;
std::string str("def");
{
// initialize lexer
- lexer_def def;
-
- def.self.add_pattern
+ lexer_def lex;
+
+ lex.self.add_pattern
("CCOMMENT", "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/")
("CPPCOMMENT", "\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)")
("WS", "[\\v\\f\\n\\r]*")
;
-
+
token_def c_comment ("{CCOMMENT}", CCOMMENT);
token_def cpp_comment ("{CPPCOMMENT}", CPPCOMMENT);
token_def ws_tok ("{WS}");
- def.self.add
+ lex.self.add
(c_comment)(cpp_comment)
('1')('2')('3')
("abc", TOKEN_ID_ABC)
(str, TOKEN_ID_STR)
;
- def.self += token_def(' ') | '\t' | ws_tok;
+ lex.self += token_def(' ') | '\t' | ws_tok;
// test lexer for different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
BOOST_TEST(test (lex, "\n\n\v\f\r", ws_tok.id()));
@@ -66,17 +64,17 @@
BOOST_TEST(test (lex, "abc", TOKEN_ID_ABC));
BOOST_TEST(test (lex, "def", TOKEN_ID_STR));
}
-
+
{
// initialize lexer
- lexer_def def;
+ lexer_def lex;
- def.self.add_pattern
+ lex.self.add_pattern
("CCOMMENT", "\\/\\*[^*]*\\*+([^/*][^*]*\\*+)*\\/")
("CPPCOMMENT", "\\/\\/[^\\n\\r]*(\\n|\\r|\\r\\n)")
("WS", "[\\v\\f\\n\\r]*")
;
-
+
token_def c_comment ("{CCOMMENT}", CCOMMENT);
token_def cpp_comment ("{CPPCOMMENT}", CPPCOMMENT);
token_def ws_tok ("{WS}");
@@ -88,17 +86,16 @@
(ws_tok, TOKEN_ID_WS)
;
- def.self.add
+ lex.self.add
(c_comment)(cpp_comment)
('1')('2')('3')
("abc", TOKEN_ID_ABC)
(str, TOKEN_ID_STR)
;
- def.self("WHITESPACE").add(ws);
+ lex.self("WHITESPACE").add(ws);
// test lexer for different input strings
- lex::lexer<lexer_def> lex(def);
BOOST_TEST(test (lex, "/* this is a comment */", CCOMMENT));
BOOST_TEST(test (lex, "// this is a comment as well\n", CPPCOMMENT));
BOOST_TEST(test (lex, "2", '2'));
Modified: trunk/libs/spirit/test/lex/state_switcher_test.cpp
==============================================================================
--- trunk/libs/spirit/test/lex/state_switcher_test.cpp (original)
+++ trunk/libs/spirit/test/lex/state_switcher_test.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -4,38 +4,36 @@
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/qi_operator.hpp>
-#include <boost/spirit/include/lex_lexer_lexertl.hpp>
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/lex_lexertl.hpp>
#include "test_parser.hpp"
///////////////////////////////////////////////////////////////////////////////
// Token definition
///////////////////////////////////////////////////////////////////////////////
template <typename Lexer>
-struct switch_state_tokens : boost::spirit::lex::lexer_def<Lexer>
+struct switch_state_tokens : boost::spirit::lex::lexer<Lexer>
{
- template <typename Self>
- void def (Self& self)
+ switch_state_tokens()
{
// define tokens and associate them with the lexer
identifier = "[a-zA-Z_][a-zA-Z0-9_]*";
- self = identifier;
-
+ this->self = identifier;
+
// any token definition to be used as the skip parser during parsing
// has to be associated with a separate lexer state (here 'WS')
white_space = "[ \\t\\n]+";
- self("WS") = white_space;
+ this->self("WS") = white_space;
separators = "[,;]";
- self("SEP") = separators;
+ this->self("SEP") = separators;
}
-
+
boost::spirit::lex::token_def<> identifier, white_space, separators;
};
///////////////////////////////////////////////////////////////////////////////
-int
-main()
+int main()
{
using namespace boost::spirit;
using namespace boost::spirit::qi;
@@ -43,50 +41,51 @@
using namespace spirit_test;
typedef std::string::iterator base_iterator_type;
- typedef boost::spirit::lex::lexertl_token<base_iterator_type> token_type;
- typedef boost::spirit::lex::lexertl_lexer<token_type> lexer_type;
+ typedef boost::spirit::lex::lexertl::token<base_iterator_type> token_type;
+ typedef boost::spirit::lex::lexertl::lexer<token_type> lexer_type;
{
// the tokens class will be initialized inside the test_parser function
- switch_state_tokens<lexer_type> tokens;
-
- BOOST_TEST(test_parser("ident", tokens.identifier, tokens));
- BOOST_TEST(!test_parser("ident", set_state("WS") >> tokens.identifier, tokens));
- BOOST_TEST(!test_parser("ident", in_state("WS")[tokens.identifier], tokens));
-
- BOOST_TEST(test_parser("\t \n", set_state("WS") >> tokens.white_space, tokens));
- BOOST_TEST(test_parser("\t \n", in_state("WS")[tokens.white_space], tokens));
- BOOST_TEST(!test_parser("\t \n", tokens.white_space, tokens));
+ switch_state_tokens<lexer_type> lex;
+
+ BOOST_TEST(test_parser("ident", lex.identifier, lex));
+ BOOST_TEST(!test_parser("ident", set_state("WS") >> lex.identifier, lex));
+ BOOST_TEST(!test_parser("ident", in_state("WS")[lex.identifier], lex));
+
+ BOOST_TEST(test_parser("\t \n", set_state("WS") >> lex.white_space, lex));
+ BOOST_TEST(test_parser("\t \n", in_state("WS")[lex.white_space], lex));
+ BOOST_TEST(!test_parser("\t \n", lex.white_space, lex));
}
-
+
{
// the tokens class will be initialized inside the test_parser function
- switch_state_tokens<lexer_type> tokens;
-
- BOOST_TEST(test_parser(",ident", tokens.identifier, tokens,
- in_state("SEP")[tokens.separators]));
- BOOST_TEST(!test_parser(";ident", set_state("WS") >> tokens.identifier,
- tokens, in_state("SEP")[tokens.separators]));
- BOOST_TEST(!test_parser(",ident", in_state("WS")[tokens.identifier],
- tokens, in_state("SEP")[tokens.separators]));
-
- BOOST_TEST(test_parser(",\t \n", set_state("WS") >> tokens.white_space,
- tokens, in_state("SEP")[tokens.separators]));
- BOOST_TEST(test_parser(";\t \n", in_state("WS")[tokens.white_space],
- tokens, in_state("SEP")[tokens.separators]));
- BOOST_TEST(!test_parser(",\t \n", tokens.white_space, tokens,
- in_state("SEP")[tokens.separators]));
+ switch_state_tokens<lexer_type> lex;
+
+ BOOST_TEST(test_parser(",ident", lex.identifier, lex,
+ in_state("SEP")[lex.separators]));
+ BOOST_TEST(!test_parser(";ident", set_state("WS") >> lex.identifier,
+ lex, in_state("SEP")[lex.separators]));
+ BOOST_TEST(!test_parser(",ident", in_state("WS")[lex.identifier],
+ lex, in_state("SEP")[lex.separators]));
+
+ BOOST_TEST(test_parser(",\t \n", set_state("WS") >> lex.white_space,
+ lex, in_state("SEP")[lex.separators]));
+ BOOST_TEST(test_parser(";\t \n", in_state("WS")[lex.white_space],
+ lex, in_state("SEP")[lex.separators]));
+ BOOST_TEST(!test_parser(",\t \n", lex.white_space, lex,
+ in_state("SEP")[lex.separators]));
}
-
+
{
// the tokens class will be initialized inside the test_parser function
- switch_state_tokens<lexer_type> tokens;
+ switch_state_tokens<lexer_type> lex;
BOOST_TEST(test_parser("ident\t \n",
- tokens.identifier >> set_state("WS") >> tokens.white_space, tokens));
+ lex.identifier >> set_state("WS") >> lex.white_space, lex));
BOOST_TEST(test_parser("\t \nident",
- in_state("WS")[tokens.white_space] >> tokens.identifier, tokens));
+ in_state("WS")[lex.white_space] >> lex.identifier, lex));
}
return boost::report_errors();
}
+
Modified: trunk/libs/spirit/test/lex/test_parser.hpp
==============================================================================
--- trunk/libs/spirit/test/lex/test_parser.hpp (original)
+++ trunk/libs/spirit/test/lex/test_parser.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -12,12 +12,10 @@
namespace spirit_test
{
- template <typename Char, typename Parser, typename Tokens>
- bool test_parser(Char const* in, Parser const& p, Tokens& tokens,
+ template <typename Char, typename Parser, typename Lexer>
+ bool test_parser(Char const* in, Parser const& p, Lexer& lex,
bool full_match = true)
{
- boost::spirit::lex::lexer<Tokens> lex(tokens);
-
// we don't care about the result of the "what" function.
// we only care that all parsers have it:
boost::spirit::qi::what(p);
@@ -26,23 +24,19 @@
std::string::iterator it_in = str.begin();
std::string::iterator end_in = str.end();
- typedef typename
- boost::spirit::lex::lexer<Tokens>::iterator_type
- iterator_type;
-
+ typedef typename Lexer::iterator_type iterator_type;
+
iterator_type iter = lex.begin(it_in, end_in);
iterator_type end = lex.end();
-
+
return boost::spirit::qi::parse(iter, end, p)
&& (!full_match || (iter == end));
}
- template <typename Char, typename Parser, typename Tokens, typename Skipper>
- bool test_parser(Char const* in, Parser const& p, Tokens& tokens,
+ template <typename Char, typename Parser, typename Lexer, typename Skipper>
+ bool test_parser(Char const* in, Parser const& p, Lexer& lex,
Skipper const& s, bool full_match = true)
{
- boost::spirit::lex::lexer<Tokens> lex(tokens);
-
// we don't care about the result of the "what" function.
// we only care that all parsers have it:
boost::spirit::qi::what(p);
@@ -51,10 +45,8 @@
std::string::iterator it_in = str.begin();
std::string::iterator end_in = str.end();
- typedef typename
- boost::spirit::lex::lexer<Tokens>::iterator_type
- iterator_type;
-
+ typedef typename Lexer::iterator_type iterator_type;
+
iterator_type iter = lex.begin(it_in, end_in);
iterator_type end = lex.end();
Modified: trunk/libs/spirit/test/qi/actions.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/actions.cpp (original)
+++ trunk/libs/spirit/test/qi/actions.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,17 +1,25 @@
/*=============================================================================
- Copyright (c) 2001-2008 Joel de Guzman
+ Copyright (c) 2001-2009 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(_MSC_VER)
+# pragma warning(disable: 4180) // qualifier applied to function type
+ // has no meaning; ignored
+#endif
+
#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_parse.hpp>
+#include <boost/spirit/include/qi_action.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/bind.hpp>
#include <cstring>
-using namespace boost::spirit;
-
int x = 0;
void fun1(int const& i)
@@ -23,6 +31,7 @@
{
x += i;
}
+using boost::spirit::unused_type;
struct fun_action
{
@@ -34,6 +43,9 @@
int main()
{
+ namespace qi = boost::spirit::qi;
+ using boost::spirit::int_;
+
{
char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
qi::parse(s1, e1, '{' >> int_[&fun1] >> '}');
@@ -45,12 +57,8 @@
}
{
- // $$$ uncomment me! $$$
- //~ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
- //~ qi::parse(s1, e1, '{' >> int_[fun2] >> '}');
-
- //~ int ii;
- //~ boost::spirit::detail::action_dispatch(fun2, ii, ii);
+ char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
+ qi::parse(s1, e1, '{' >> int_[fun2] >> '}');
}
{
Modified: trunk/libs/spirit/test/qi/alternative.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/alternative.cpp (original)
+++ trunk/libs/spirit/test/qi/alternative.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 Joel de Guzman
Copyright (c) 2001-2009 Hartmut Kaiser
Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -10,8 +10,10 @@
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
-#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/qi_directive.hpp>
+#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/qi_nonterminal.hpp>
+#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -21,18 +23,24 @@
#include <iostream>
#include "test.hpp"
-using namespace spirit_test;
-
int
main()
{
- using namespace boost::spirit;
+ using spirit_test::test;
+ using spirit_test::test_attr;
+
+ using boost::spirit::ascii::char_;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::lit;
+ using boost::spirit::qi::unused_type;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::omit;
{
BOOST_TEST((test("a", char_ | char_)));
- BOOST_TEST((test("x", char_('x') | char_('i'))));
- BOOST_TEST((test("i", char_('x') | char_('i'))));
- BOOST_TEST((!test("z", char_('x') | char_('o'))));
+ BOOST_TEST((test("x", lit('x') | lit('i'))));
+ BOOST_TEST((test("i", lit('x') | lit('i'))));
+ BOOST_TEST((!test("z", lit('x') | lit('o'))));
BOOST_TEST((test("rock", lit("rock") | lit("roll"))));
BOOST_TEST((test("roll", lit("rock") | lit("roll"))));
BOOST_TEST((test("rock", lit("rock") | int_)));
@@ -46,7 +54,6 @@
BOOST_TEST(boost::get<int>(v) == 12345);
BOOST_TEST((test_attr("rock", lit("rock") | int_ | char_, v)));
-// BOOST_TEST(boost::get<std::string>(&v) == 0);
BOOST_TEST(boost::get<int>(&v) == 0);
BOOST_TEST(boost::get<char>(&v) == 0);
@@ -55,25 +62,25 @@
}
{ // test action
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
- namespace phx = boost::phoenix;
+ namespace phoenix = boost::phoenix;
boost::variant<unused_type, int, char> v;
- BOOST_TEST((test("12345", (lit("rock") | int_ | char_)[phx::ref(v) = _1])));
+ BOOST_TEST((test("12345", (lit("rock") | int_ | char_)[phoenix::ref(v) = _1])));
BOOST_TEST(boost::get<int>(v) == 12345);
}
{
- boost::variant<unused_type> v;
- BOOST_TEST((test("rock", lit("rock") | char_('x'))));
+ unused_type x;
+ BOOST_TEST((test_attr("rock", lit("rock") | lit('x'), x)));
}
{
// test if alternatives with all components having unused
- // attributes return attributes them self
- using namespace boost::fusion;
+ // attributes have an unused attribute
+
+ using boost::fusion::vector;
+ using boost::fusion::at_c;
vector<char, char> v;
BOOST_TEST((test_attr("abc",
@@ -82,6 +89,31 @@
BOOST_TEST((at_c<1>(v) == 'c'));
}
+ {
+ // Test that we can still pass a "compatible" attribute to
+ // an alternate even if its "expected" attribute is unused type.
+
+ std::string s;
+ BOOST_TEST((test_attr("...", *(char_('.') | char_(',')), s)));
+ BOOST_TEST(s == "...");
+ }
+
+ { // make sure collapsing eps works as expected
+ // (compile check only)
+
+ using boost::spirit::qi::rule;
+ using boost::spirit::qi::_val;
+ using boost::spirit::qi::_1;
+ using boost::spirit::eps;
+ rule<const wchar_t*, wchar_t()> r1, r2, r3;
+
+ r3 = ((eps >> r1))[_val += _1];
+ r3 = ((r1 ) | r2)[_val += _1];
+
+ r3 %= ((eps >> r1) | r2);
+ r3 = ((eps >> r1) | r2)[_val += _1];
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/qi/and_predicate.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/and_predicate.cpp (original)
+++ trunk/libs/spirit/test/qi/and_predicate.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -16,7 +16,7 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit;
+ using boost::spirit::int_;
{
BOOST_TEST((test("1234", &int_, false)));
Modified: trunk/libs/spirit/test/qi/binary.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/binary.cpp (original)
+++ trunk/libs/spirit/test/qi/binary.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,27 +1,34 @@
-// Copyright (c) 2001-2009 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)
+/*=============================================================================
+ Copyright (c) 2001-2009 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/detail/lightweight_test.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/qi_binary.hpp>
-#include <boost/spirit/include/qi_parse.hpp>
-
#include <boost/cstdint.hpp>
-
#include "test.hpp"
-using namespace spirit_test;
-
///////////////////////////////////////////////////////////////////////////////
-int
-main()
+int main()
{
- using namespace boost::spirit;
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
+ using spirit_test::test_attr;
+ using spirit_test::test;
+
+ using boost::spirit::qi::byte_;
+ using boost::spirit::qi::word;
+ using boost::spirit::qi::dword;
+ using boost::spirit::qi::big_word;
+ using boost::spirit::qi::big_dword;
+ using boost::spirit::qi::little_word;
+ using boost::spirit::qi::little_dword;
+#ifdef BOOST_HAS_LONG_LONG
+ using boost::spirit::qi::qword;
+ using boost::spirit::qi::big_qword;
+ using boost::spirit::qi::little_qword;
+#endif
boost::uint8_t uc;
boost::uint16_t us;
@@ -32,7 +39,7 @@
{ // test native endian binaries
#ifdef BOOST_LITTLE_ENDIAN
- BOOST_TEST(test_attr("\x01", byte, uc) && uc == 0x01);
+ BOOST_TEST(test_attr("\x01", byte_, uc) && uc == 0x01);
BOOST_TEST(test_attr("\x01\x02", word, us) && us == 0x0201);
BOOST_TEST(test_attr("\x01\x02\x03\x04", dword, ui) && ui == 0x04030201);
#ifdef BOOST_HAS_LONG_LONG
@@ -40,7 +47,7 @@
ul == 0x0807060504030201LL);
#endif
#else
- BOOST_TEST(test_attr("\x01", byte, uc) && uc == 0x01);
+ BOOST_TEST(test_attr("\x01", byte_, uc) && uc == 0x01);
BOOST_TEST(test_attr("\x01\x02", word, us) && us == 0x0102);
BOOST_TEST(test_attr("\x01\x02\x03\x04", dword, ui) && ui == 0x01020304);
#ifdef BOOST_HAS_LONG_LONG
@@ -52,7 +59,7 @@
{ // test native endian binaries
#ifdef BOOST_LITTLE_ENDIAN
- BOOST_TEST(test("\x01", byte(0x01)));
+ BOOST_TEST(test("\x01", byte_(0x01)));
BOOST_TEST(test("\x01\x02", word(0x0201)));
BOOST_TEST(test("\x01\x02\x03\x04", dword(0x04030201)));
#ifdef BOOST_HAS_LONG_LONG
@@ -60,7 +67,7 @@
qword(0x0807060504030201LL)));
#endif
#else
- BOOST_TEST(test("\x01", byte(0x01)));
+ BOOST_TEST(test("\x01", byte_(0x01)));
BOOST_TEST(test("\x01\x02", word(0x0102)));
BOOST_TEST(test("\x01\x02\x03\x04", dword(0x01020304)));
#ifdef BOOST_HAS_LONG_LONG
Modified: trunk/libs/spirit/test/qi/char.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/char.cpp (original)
+++ trunk/libs/spirit/test/qi/char.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 Joel de Guzman
Copyright (c) 2001-2009 Hartmut Kaiser
Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -7,8 +7,7 @@
=============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_char.hpp>
-#include <boost/spirit/include/qi_string.hpp>
-#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -19,20 +18,20 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit::qi;
- using namespace boost::spirit::ascii;
- using boost::spirit::char_;
- using boost::spirit::wchar;
-
+ using spirit_test::test_attr;
+ using spirit_test::print_info;
+
{
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test("x", 'x'));
BOOST_TEST(test(L"x", L'x'));
+ BOOST_TEST(!test("y", 'x'));
+ BOOST_TEST(!test(L"y", L'x'));
BOOST_TEST(test("x", char_));
BOOST_TEST(test("x", char_('x')));
BOOST_TEST(!test("x", char_('y')));
- BOOST_TEST(test(L"x", char_(L'x')));
- BOOST_TEST(!test(L"x", char_(L'y')));
BOOST_TEST(test("x", char_('a', 'z')));
BOOST_TEST(!test("x", char_('0', '9')));
@@ -54,66 +53,119 @@
}
{
+ using namespace boost::spirit::ascii;
+ using boost::spirit::qi::lit;
+
+ BOOST_TEST(test("x", lit('x')));
+ BOOST_TEST(!test("x", lit('y')));
+
+ BOOST_TEST(!test("x", ~lit('x')));
+ BOOST_TEST(test(" ", ~lit('x')));
+ BOOST_TEST(test("X", ~lit('x')));
+
+ BOOST_TEST(test("x", ~~lit('x')));
+ BOOST_TEST(!test(" ", ~~lit('x')));
+ BOOST_TEST(!test("X", ~~lit('x')));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
BOOST_TEST(test(" x", 'x', space));
BOOST_TEST(test(L" x", L'x', space));
BOOST_TEST(test(" x", char_, space));
BOOST_TEST(test(" x", char_('x'), space));
BOOST_TEST(!test(" x", char_('y'), space));
- BOOST_TEST(test(L" x", char_(L'x'), space));
- BOOST_TEST(!test(L" x", char_(L'y'), space));
BOOST_TEST(test(" x", char_('a', 'z'), space));
BOOST_TEST(!test(" x", char_('0', '9'), space));
-
}
{
- BOOST_TEST(test(L"x", wchar));
- BOOST_TEST(test(L"x", wchar(L'x')));
- BOOST_TEST(!test(L"x", wchar(L'y')));
- BOOST_TEST(test(L"x", wchar('a', 'z')));
- BOOST_TEST(!test(L"x", wchar('0', '9')));
-
- BOOST_TEST(!test(L"x", ~wchar));
- BOOST_TEST(!test(L"x", ~wchar('x')));
- BOOST_TEST(test(L" ", ~wchar('x')));
- BOOST_TEST(test(L"X", ~wchar('x')));
- BOOST_TEST(!test(L"x", ~wchar('b', 'y')));
- BOOST_TEST(test(L"a", ~wchar('b', 'y')));
- BOOST_TEST(test(L"z", ~wchar('b', 'y')));
-
- BOOST_TEST(test(L"x", ~~wchar));
- BOOST_TEST(test(L"x", ~~wchar('x')));
- BOOST_TEST(!test(L" ", ~~wchar('x')));
- BOOST_TEST(!test(L"X", ~~wchar('x')));
- BOOST_TEST(test(L"x", ~~wchar('b', 'y')));
- BOOST_TEST(!test(L"a", ~~wchar('b', 'y')));
- BOOST_TEST(!test(L"z", ~~wchar('b', 'y')));
+ using namespace boost::spirit::standard_wide;
+
+ BOOST_TEST(test(L"x", char_));
+ BOOST_TEST(test(L"x", char_(L'x')));
+ BOOST_TEST(!test(L"x", char_(L'y')));
+ BOOST_TEST(test(L"x", char_(L'a', L'z')));
+ BOOST_TEST(!test(L"x", char_(L'0', L'9')));
+
+ BOOST_TEST(!test(L"x", ~char_));
+ BOOST_TEST(!test(L"x", ~char_(L'x')));
+ BOOST_TEST(test(L" ", ~char_(L'x')));
+ BOOST_TEST(test(L"X", ~char_(L'x')));
+ BOOST_TEST(!test(L"x", ~char_(L'b', L'y')));
+ BOOST_TEST(test(L"a", ~char_(L'b', L'y')));
+ BOOST_TEST(test(L"z", ~char_(L'b', L'y')));
+
+ BOOST_TEST(test(L"x", ~~char_));
+ BOOST_TEST(test(L"x", ~~char_(L'x')));
+ BOOST_TEST(!test(L" ", ~~char_(L'x')));
+ BOOST_TEST(!test(L"X", ~~char_(L'x')));
+ BOOST_TEST(test(L"x", ~~char_(L'b', L'y')));
+ BOOST_TEST(!test(L"a", ~~char_(L'b', L'y')));
+ BOOST_TEST(!test(L"z", ~~char_(L'b', L'y')));
}
- { // single char strings as argument to char_
- BOOST_TEST(test("x", char_("x"), space));
- BOOST_TEST(test("x", wchar(L"x"), space));
+ { // single char strings!
+ namespace ascii = boost::spirit::ascii;
+ namespace wide = boost::spirit::standard_wide;
+
+ BOOST_TEST(test("x", "x"));
+ BOOST_TEST(test(L"x", L"x"));
+ BOOST_TEST(test("x", ascii::char_("x")));
+ BOOST_TEST(test(L"x", wide::char_(L"x")));
}
{
// chsets
- BOOST_TEST(test("x", char_("a-z")));
- BOOST_TEST(!test("1", char_("a-z")));
- BOOST_TEST(test("1", char_("a-z0-9")));
-
- BOOST_TEST(test("x", char_(L"a-z")));
- BOOST_TEST(!test("1", char_(L"a-z")));
- BOOST_TEST(test("1", char_(L"a-z0-9")));
+ namespace ascii = boost::spirit::ascii;
+ namespace wide = boost::spirit::standard_wide;
+
+ BOOST_TEST(test("x", ascii::char_("a-z")));
+ BOOST_TEST(!test("1", ascii::char_("a-z")));
+ BOOST_TEST(test("1", ascii::char_("a-z0-9")));
+
+ BOOST_TEST(test("x", wide::char_(L"a-z")));
+ BOOST_TEST(!test("1", wide::char_(L"a-z")));
+ BOOST_TEST(test("1", wide::char_(L"a-z0-9")));
+
+ std::string set = "a-z0-9";
+ BOOST_TEST(test("x", ascii::char_(set)));
+
+#ifdef SPIRIT_NO_COMPILE_CHECK
+ test("", ascii::char_(L"a-z0-9"));
+#endif
}
{ // lazy chars
- using namespace boost::phoenix;
+ using namespace boost::spirit::ascii;
+
+ using boost::phoenix::val;
+ using boost::phoenix::ref;
+ using boost::spirit::_1;
+
BOOST_TEST((test("x", char_(val('x')))));
BOOST_TEST((test("h", char_(val('a'), val('n')))));
+ BOOST_TEST(test("0", char_(val("a-z0-9"))));
+
+ char ch; // make sure lazy chars have an attribute
+ BOOST_TEST(test("x", char_(val('x'))[ref(ch) = _1]));
+ BOOST_TEST(ch == 'x');
+ }
+
+ { // testing "what"
+
+ using boost::spirit::qi::what;
+ using boost::spirit::ascii::char_;
+ using boost::spirit::ascii::alpha;
+
+ print_info(what('x'));
+ print_info(what(char_('a','z')));
+ print_info(what(alpha));
}
-
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/qi/char_class.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/char_class.cpp (original)
+++ trunk/libs/spirit/test/qi/char_class.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
- Copyright (c) 2001-2007 Hartmut Kaiser
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -8,14 +8,13 @@
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_action.hpp>
-#include <boost/spirit/include/qi_domain.hpp>
-#include <boost/spirit/include/support_attribute_of.hpp>
#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/support_attributes.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
-
#include <boost/type_traits/is_same.hpp>
#include <boost/static_assert.hpp>
+
#include <iostream>
#include "test.hpp"
@@ -138,11 +137,12 @@
using boost::spirit::traits::attribute_of;
using boost::spirit::iso8859_1::alpha;
using boost::spirit::iso8859_1::alpha_type;
+ using boost::spirit::result_of::compile;
BOOST_STATIC_ASSERT((
boost::is_same<
- attribute_of<domain, alpha_type, char const*, int>::type
- , char>::value));
+ attribute_of<compile<domain, alpha_type>::type>::type
+ , unsigned char>::value));
int attr = 0;
BOOST_TEST(test_attr("a", alpha, attr));
@@ -159,9 +159,9 @@
{ // test action
- using namespace boost::phoenix;
using namespace boost::spirit::ascii;
- using boost::spirit::arg_names::_1;
+ using boost::phoenix::ref;
+ using boost::spirit::_1;
char ch;
BOOST_TEST(test("x", alnum[ref(ch) = _1]));
Modified: trunk/libs/spirit/test/qi/difference.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/difference.cpp (original)
+++ trunk/libs/spirit/test/qi/difference.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -19,13 +19,12 @@
#include <iostream>
#include "test.hpp"
-using namespace spirit_test;
-
int
main()
{
- using namespace boost::spirit;
using namespace boost::spirit::ascii;
+ using boost::spirit::lit;
+ using spirit_test::test;
{
BOOST_TEST(test("b", char_ - 'a'));
@@ -47,16 +46,16 @@
{
// $$$ See difference.hpp why these tests are not done anymore. $$$
- //~ BOOST_TEST(test("switcher", lit("switcher") - "switch"));
- //~ BOOST_TEST(test(" switcher ", lit("switcher") - "switch", space));
+ // BOOST_TEST(test("switcher", lit("switcher") - "switch"));
+ // BOOST_TEST(test(" switcher ", lit("switcher") - "switch", space));
BOOST_TEST(!test("switch", lit("switch") - "switch"));
}
{
- using boost::spirit::arg_names::_1;
+ using boost::spirit::_1;
namespace phx = boost::phoenix;
-
+
std::string s;
BOOST_TEST(test(
@@ -67,7 +66,7 @@
s.clear();
BOOST_TEST(test(
- " /*abcdefghijk*/ "
+ " /*abcdefghijk*/"
, "/*" >> *(char_ - "*/")[phx::ref(s) += _1] >> "*/"
, space
));
Modified: trunk/libs/spirit/test/qi/end.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/end.cpp (original)
+++ trunk/libs/spirit/test/qi/end.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
- Copyright (c) 2001-2008 Hartmut Kaiser
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -8,6 +8,7 @@
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_auxiliary.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -19,60 +20,52 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit::qi;
- using namespace boost::spirit::ascii;
- using boost::spirit::char_;
- using boost::spirit::wchar;
- using boost::spirit::eol;
- using boost::spirit::eoi;
-
+ namespace qi = boost::spirit::qi;
+ namespace ascii = boost::spirit::ascii;
+ namespace wide = boost::spirit::standard_wide;
+
+ using qi::eol;
+ using qi::eoi;
+ using ascii::space;
+
{ // eol
BOOST_TEST(test("\r", eol));
BOOST_TEST(test("\r\n", eol));
BOOST_TEST(test("\n", eol));
BOOST_TEST(!test("\b", eol));
- BOOST_TEST(!test("\r", ~eol, false));
- BOOST_TEST(!test("\r\n", ~eol, false));
- BOOST_TEST(!test("\n", ~eol, false));
- BOOST_TEST(test("\b", ~eol, false));
-
- BOOST_TEST(test("\r", ~~eol));
- BOOST_TEST(test("\r\n", ~~eol));
- BOOST_TEST(test("\n", ~~eol));
- BOOST_TEST(!test("\b", ~~eol));
-
- BOOST_TEST(test(" \r", eol, char_(' ')));
- BOOST_TEST(test(" \r\n", eol, char_(' ')));
- BOOST_TEST(test(" \n", eol, char_(' ')));
- BOOST_TEST(!test(" \b", eol, char_(' ')));
+ BOOST_TEST(!test("\r", !eol, false));
+ BOOST_TEST(!test("\r\n", !eol, false));
+ BOOST_TEST(!test("\n", !eol, false));
+ BOOST_TEST(test("\b", !eol, false));
+
+ BOOST_TEST(test(" \r", eol, ascii::char_(L' ')));
+ BOOST_TEST(test(" \r\n", eol, ascii::char_(L' ')));
+ BOOST_TEST(test(" \n", eol, ascii::char_(L' ')));
+ BOOST_TEST(!test(" \b", eol, ascii::char_(L' ')));
BOOST_TEST(test(L"\r", eol));
BOOST_TEST(test(L"\r\n", eol));
BOOST_TEST(test(L"\n", eol));
BOOST_TEST(!test(L"\b", eol));
- BOOST_TEST(test(L" \r", eol, wchar(L' ')));
- BOOST_TEST(test(L" \r\n", eol, wchar(L' ')));
- BOOST_TEST(test(L" \n", eol, wchar(L' ')));
- BOOST_TEST(!test(L" \b", eol, wchar(L' ')));
+ BOOST_TEST(test(L" \r", eol, wide::char_(L' ')));
+ BOOST_TEST(test(L" \r\n", eol, wide::char_(L' ')));
+ BOOST_TEST(test(L" \n", eol, wide::char_(L' ')));
+ BOOST_TEST(!test(L" \b", eol, wide::char_(L' ')));
}
-
+
{ // eoi
BOOST_TEST(test("", eoi));
BOOST_TEST(!test("a", eoi));
- BOOST_TEST(test("a", ~eoi, false));
- BOOST_TEST(!test("", ~eoi));
- BOOST_TEST(test("", ~~eoi));
- BOOST_TEST(!test("a", ~~eoi));
+ BOOST_TEST(test("a", !eoi, false));
+ BOOST_TEST(!test("", !eoi));
BOOST_TEST(test(" ", eoi, space));
BOOST_TEST(!test(" a", eoi, space));
- BOOST_TEST(test(" a", ~eoi, space, false));
- BOOST_TEST(!test(" ", ~eoi, space));
- BOOST_TEST(test(" ", ~~eoi, space));
- BOOST_TEST(!test(" a", ~~eoi, space));
+ BOOST_TEST(test(" a", !eoi, space, false));
+ BOOST_TEST(!test(" ", !eoi, space));
}
-
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/qi/eps.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/eps.cpp (original)
+++ trunk/libs/spirit/test/qi/eps.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,11 +1,12 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
=============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_auxiliary.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <iostream>
@@ -15,18 +16,28 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit;
+ using boost::spirit::eps;
{
BOOST_TEST((test("", eps)));
BOOST_TEST((test("xxx", eps, false)));
+ BOOST_TEST((!test("", !eps))); // not predicate
}
- { // test action
+ { // test non-lazy semantic predicate
+
+ BOOST_TEST((test("", eps(true))));
+ BOOST_TEST((!test("", eps(false))));
+ BOOST_TEST((test("", !eps(false)))); // not predicate
+ }
+
+ { // test lazy semantic predicate
+
+ using boost::phoenix::val;
- using namespace boost::phoenix;
BOOST_TEST((test("", eps(val(true)))));
BOOST_TEST((!test("", eps(val(false)))));
+ BOOST_TEST((test("", !eps(val(false))))); // not predicate
}
return boost::report_errors();
Modified: trunk/libs/spirit/test/qi/expect.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/expect.cpp (original)
+++ trunk/libs/spirit/test/qi/expect.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -11,6 +11,8 @@
#include <boost/spirit/include/qi_numeric.hpp>
#include <boost/spirit/include/qi_directive.hpp>
#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/qi_nonterminal.hpp>
+#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
@@ -28,6 +30,7 @@
using namespace boost::spirit;
using namespace boost::spirit::ascii;
using spirit_test::test;
+ using spirit_test::print_info;
using boost::spirit::qi::expectation_failure;
{
@@ -42,10 +45,10 @@
}
catch (expectation_failure<char const*> const& x)
{
- std::cout << "expected: " << x.what << std::endl;
+ std::cout << "expected: "; print_info(x.what);
std::cout << "got: \"" << x.first << '"' << std::endl;
- BOOST_TEST(x.what == "'o'");
+ BOOST_TEST(boost::get<std::string>(x.what.value) == "o");
BOOST_TEST(std::string(x.first, x.last) == "i");
}
}
@@ -53,17 +56,17 @@
{
try
{
- BOOST_TEST((test(" a a ", char_ > char_, space)));
- BOOST_TEST((test(" x i ", char_('x') > char_('i'), space)));
- BOOST_TEST((!test(" x i ", char_('x') > char_('o'), space)));
+ BOOST_TEST((test(" a a", char_ > char_, space)));
+ BOOST_TEST((test(" x i", char_('x') > char_('i'), space)));
+ BOOST_TEST((!test(" x i", char_('x') > char_('o'), space)));
}
catch (expectation_failure<char const*> const& x)
{
- std::cout << "expected: " << x.what << std::endl;
+ std::cout << "expected: "; print_info(x.what);
std::cout << "got: \"" << x.first << '"' << std::endl;
- BOOST_TEST(x.what == "'o'");
- BOOST_TEST(std::string(x.first, x.last) == "i ");
+ BOOST_TEST(boost::get<std::string>(x.what.value) == "o");
+ BOOST_TEST(std::string(x.first, x.last) == "i");
}
}
@@ -76,14 +79,22 @@
}
catch (expectation_failure<char const*> const& x)
{
- std::cout << "expected: " << x.what << std::endl;
+ std::cout << "expected: "; print_info(x.what);
std::cout << "got: \"" << x.first << '"' << std::endl;
- BOOST_TEST(x.what == "case-insensitive \"nend\"");
+ BOOST_TEST(x.what.tag == "no-case-literal-string");
+ BOOST_TEST(boost::get<std::string>(x.what.value) == "nend");
BOOST_TEST(std::string(x.first, x.last) == "END");
}
}
+ {
+ using boost::spirit::qi::rule;
+ using boost::spirit::eps;
+ rule<const wchar_t*, void(int)> r;
+ r = eps > eps(_r1);
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/qi/grammar.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/grammar.cpp (original)
+++ trunk/libs/spirit/test/qi/grammar.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -18,11 +18,17 @@
#include <iostream>
#include "test.hpp"
-using namespace spirit_test;
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace boost::spirit::ascii;
-using namespace boost::spirit::arg_names;
+using spirit_test::test;
+using spirit_test::test_attr;
+
+using boost::spirit::ascii::space_type;
+using boost::spirit::ascii::space;
+using boost::spirit::int_;
+using boost::spirit::qi::grammar;
+using boost::spirit::qi::rule;
+using boost::spirit::_val;
+using boost::spirit::_r1;
+using boost::spirit::lit;
struct num_list : grammar<char const*, space_type>
{
@@ -101,7 +107,7 @@
{ // direct access to the rules
num_list g;
- BOOST_TEST(test("123", g.num));
+ BOOST_TEST(test("123", g.num, space));
BOOST_TEST(test("123, 456, 789", g.start, space));
}
Modified: trunk/libs/spirit/test/qi/int.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/int.cpp (original)
+++ trunk/libs/spirit/test/qi/int.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 Joel de Guzman
Copyright (c) 2001-2009 Hartmut Kaiser
Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -27,12 +27,17 @@
// Some compilers have long long, but don't define the
// LONG_LONG_MIN and LONG_LONG_MAX macros in limits.h. This
// assumes that long long is 64 bits.
+
+BOOST_STATIC_ASSERT(sizeof(long long) == 8);
+
#if !defined(LONG_LONG_MIN) && !defined(LONG_LONG_MAX)
# define LONG_LONG_MAX 0x7fffffffffffffffLL
# define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
#endif
#endif // BOOST_HAS_LONG_LONG
+BOOST_STATIC_ASSERT(sizeof(long) == 4);
+
char const* max_int = "2147483647";
char const* int_overflow = "2147483648";
char const* min_int = "-2147483648";
@@ -48,7 +53,8 @@
int
main()
{
- using namespace spirit_test;
+ using spirit_test::test;
+ using spirit_test::test_attr;
///////////////////////////////////////////////////////////////////////////
// signed integer tests
@@ -130,12 +136,29 @@
#endif
///////////////////////////////////////////////////////////////////////////
- // int_spec<unused_type> tests
+ // short_ and long_ tests
+ ///////////////////////////////////////////////////////////////////////////
+ {
+ using boost::spirit::short_;
+ using boost::spirit::long_;
+ int i;
+
+ BOOST_TEST(test("12345", short_));
+ BOOST_TEST(test_attr("12345", short_, i));
+ BOOST_TEST(i == 12345);
+
+ BOOST_TEST(test("1234567890", long_));
+ BOOST_TEST(test_attr("1234567890", long_, i));
+ BOOST_TEST(i == 1234567890);
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ // int_parser<unused_type> tests
///////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::qi::int_spec;
+ using boost::spirit::qi::int_parser;
using boost::spirit::unused_type;
- int_spec<unused_type> any_int;
+ int_parser<unused_type> any_int;
BOOST_TEST(test("123456", any_int));
BOOST_TEST(test("-123456", any_int));
@@ -146,8 +169,8 @@
// action tests
///////////////////////////////////////////////////////////////////////////
{
- using namespace boost::phoenix;
- using boost::spirit::arg_names::_1;
+ using boost::phoenix::ref;
+ using boost::spirit::_1;
using boost::spirit::ascii::space;
using boost::spirit::int_;
int n, m;
Modified: trunk/libs/spirit/test/qi/kleene.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/kleene.cpp (original)
+++ trunk/libs/spirit/test/qi/kleene.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -24,13 +24,15 @@
#include <iostream>
#include "test.hpp"
-using namespace spirit_test;
-
int
main()
{
- using namespace boost::spirit;
+ using spirit_test::test;
+ using spirit_test::test_attr;
using namespace boost::spirit::ascii;
+ using boost::spirit::qi::omit;
+ using boost::spirit::qi::uint_;
+ using boost::spirit::qi::int_;
{
BOOST_TEST(test("aaaaaaaa", *char_));
@@ -42,40 +44,38 @@
{
BOOST_TEST(test(" a a aaa aa", *char_, space));
- BOOST_TEST(test("12345 678 9 ", *digit, space));
+ BOOST_TEST(test("12345 678 9", *digit, space));
}
{
BOOST_TEST(test("aBcdeFGH", no_case[*char_]));
- BOOST_TEST(test("a B cde FGH ", no_case[*char_], space));
+ BOOST_TEST(test("a B cde FGH", no_case[*char_], space));
}
{
- using boost::spirit::uint;
- BOOST_TEST(test("12345 678 955 987", *uint, space));
- BOOST_TEST(test("12345, 678, 955, 987", uint >> *(',' >> uint), space));
+ BOOST_TEST(test("12345 678 955 987", *uint_, space));
+ BOOST_TEST(test("12345, 678, 955, 987", uint_ >> *(',' >> uint_), space));
}
{
- std::vector<char> v;
- BOOST_TEST(test_attr("bbbb", *char_, v) && 4 == v.size() &&
- v[0] == 'b' && v[1] == 'b' && v[2] == 'b' && v[3] == 'b');
+ std::string s;
+ BOOST_TEST(test_attr("bbbb", *char_, s) && 4 == s.size() && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("b b b b ", *char_, v, space) && 4 == v.size() &&
- v[0] == 'b' && v[1] == 'b' && v[2] == 'b' && v[3] == 'b');
+ s.clear();
+ BOOST_TEST(test_attr("b b b b ", *char_, s, space) && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("bbbb", *omit[char_('b')], v) && 0 == v.size());
+ // The following 4 tests show that omit does not inhibit explicit attributes
+ s.clear();
+ BOOST_TEST(test_attr("bbbb", *omit[char_('b')], s) && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("bbbb", omit[*char_('b')], v) && 0 == v.size());
+ s.clear();
+ BOOST_TEST(test_attr("bbbb", omit[*char_('b')], s) && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("b b b b ", *omit[char_('b')], v, space) && 0 == v.size());
+ s.clear();
+ BOOST_TEST(test_attr("b b b b", *omit[char_('b')], s, space) && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("b b b b ", omit[*char_('b')], v, space) && 0 == v.size());
+ s.clear();
+ BOOST_TEST(test_attr("b b b b", omit[*char_('b')], s, space) && s == "bbbb");
}
{
@@ -92,7 +92,7 @@
{ // actions
namespace phx = boost::phoenix;
- using boost::spirit::arg_names::_1;
+ using boost::spirit::_1;
std::vector<char> v;
BOOST_TEST(test("bbbb", (*char_)[phx::ref(v) = _1]) && 4 == v.size() &&
@@ -101,7 +101,7 @@
{ // more actions
namespace phx = boost::phoenix;
- using boost::spirit::arg_names::_1;
+ using boost::spirit::_1;
std::vector<int> v;
BOOST_TEST(test("123 456 789", (*int_)[phx::ref(v) = _1], space) && 3 == v.size() &&
Modified: trunk/libs/spirit/test/qi/lazy.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/lazy.cpp (original)
+++ trunk/libs/spirit/test/qi/lazy.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -23,27 +23,44 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit;
- using namespace boost::spirit::qi;
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
+ using spirit_test::test_attr;
+
+ namespace qi = boost::spirit::qi;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::_val;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::rule;
+ using boost::spirit::ascii::char_;
+
+ using boost::phoenix::val;
+ using boost::phoenix::ref;
{
- BOOST_TEST(test("123", lazy(val(int_))));
+ BOOST_TEST(test("123", val(int_)));
}
{
int result;
- BOOST_TEST(test("123", lazy(val(int_))[ref(result) = _1]));
+ BOOST_TEST(test("123", qi::lazy(val(int_))[ref(result) = _1]));
BOOST_TEST((result == 123));
}
{
+ rule<char const*, char()> r;
+
+ r = char_[_val = _1] >> *qi::lazy(_val);
+
+ BOOST_TEST(test("aaaaaaaaaaaa", r));
+ BOOST_TEST(!test("abbbbbbbbbb", r));
+ BOOST_TEST(test("bbbbbbbbbbb", r));
+ }
+
+ {
rule<char const*, std::string()> r;
r =
'<' >> *(char_ - '>')[_val += _1] >> '>'
- >> "</" >> lazy(_val) >> '>'
+ >> "</" >> qi::lazy(_val) >> '>'
;
BOOST_TEST(test("<tag></tag>", r));
Modified: trunk/libs/spirit/test/qi/lexeme.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/lexeme.cpp (original)
+++ trunk/libs/spirit/test/qi/lexeme.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -17,8 +17,10 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit;
- using namespace boost::spirit::ascii;
+ using boost::spirit::ascii::space;
+ using boost::spirit::ascii::space_type;
+ using boost::spirit::ascii::digit;
+ using boost::spirit::qi::lexeme;
using boost::spirit::qi::rule;
{
@@ -27,7 +29,8 @@
BOOST_TEST((test(" 12345", lexeme[+digit], space)));
BOOST_TEST((test(" 12345 ", lexeme[+digit], space, false)));
- rule<char const*, space_type> r, rr;
+ rule<char const*, space_type> rr;
+ rule<char const*> r;
r = +digit;
rr = lexeme[r];
BOOST_TEST((!test(" 1 2 3 4 5", rr, space)));
Modified: trunk/libs/spirit/test/qi/list.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/list.cpp (original)
+++ trunk/libs/spirit/test/qi/list.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -31,7 +31,6 @@
int
main()
{
- using namespace boost::spirit;
using namespace boost::spirit::ascii;
{
@@ -50,9 +49,28 @@
BOOST_TEST(s == "abcdefgh");
}
+ {
+ using boost::spirit::int_;
+
+ std::vector<int> v;
+ BOOST_TEST(test_attr("1,2", int_ % ',', v));
+ BOOST_TEST(2 == v.size() && 1 == v[0] && 2 == v[1]);
+ }
+
+ {
+ using boost::spirit::int_;
+
+ std::vector<int> v;
+ BOOST_TEST(test_attr("(1,2)", '(' >> int_ % ',' >> ')', v));
+ BOOST_TEST(2 == v.size() && 1 == v[0] && 2 == v[1]);
+ }
+
{ // actions
- using namespace boost::phoenix;
- using boost::spirit::arg_names::_1;
+ using boost::phoenix::ref;
+ using boost::phoenix::begin;
+ using boost::phoenix::end;
+ using boost::phoenix::construct;
+ using boost::spirit::qi::_1;
std::string s;
BOOST_TEST(test("a,b,c,d,e,f,g,h", (char_ % ',')
Modified: trunk/libs/spirit/test/qi/lit.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/lit.cpp (original)
+++ trunk/libs/spirit/test/qi/lit.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 Joel de Guzman
http://spirit.sourceforge.net/
Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -9,7 +9,6 @@
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_action.hpp>
-#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -21,22 +20,29 @@
{
using spirit_test::test;
using spirit_test::test_attr;
- using namespace boost::spirit;
+ using boost::spirit::qi::lit;
+ using boost::spirit::qi::_1;
{
BOOST_TEST((test("kimpo", "kimpo")));
BOOST_TEST((test("kimpo", lit("kimpo"))));
BOOST_TEST((test("x", lit("x"))));
- BOOST_TEST((test("x", lit('x'))));
- BOOST_TEST((test(L"x", lit(L'x'))));
+ BOOST_TEST((test(L"x", lit(L"x"))));
+
+ std::basic_string<char> s("kimpo");
+ std::basic_string<wchar_t> ws(L"kimpo");
+ BOOST_TEST((test("kimpo", s)));
+ BOOST_TEST((test(L"kimpo", ws)));
+ BOOST_TEST((test("kimpo", lit(s))));
+ BOOST_TEST((test(L"kimpo", lit(ws))));
}
{
BOOST_TEST((test(L"kimpo", L"kimpo")));
- BOOST_TEST((test(L"kimpo", wlit(L"kimpo"))));
- BOOST_TEST((test(L"x", wlit(L"x"))));
- BOOST_TEST((test(L"x", wlit(L'x'))));
- BOOST_TEST((test(L"x", wlit(L'x'))));
+ BOOST_TEST((test(L"kimpo", lit(L"kimpo"))));
+ BOOST_TEST((test(L"x", lit(L"x"))));
+ BOOST_TEST((test(L"x", lit(L'x'))));
+ BOOST_TEST((test(L"x", lit(L'x'))));
}
{
@@ -58,21 +64,35 @@
{
using namespace boost::spirit::ascii;
- BOOST_TEST((test(" kimpo", wlit("kimpo"), space)));
- BOOST_TEST((test(L" kimpo", wlit(L"kimpo"), space)));
- BOOST_TEST((test(" x", wlit("x"), space)));
- BOOST_TEST((test(" x", wlit('x'), space)));
- BOOST_TEST((test(L" x", wlit(L'x'), space)));
+ BOOST_TEST((test(" kimpo", lit("kimpo"), space)));
+ BOOST_TEST((test(L" kimpo", lit(L"kimpo"), space)));
+ BOOST_TEST((test(" x", lit("x"), space)));
+ BOOST_TEST((test(" x", lit('x'), space)));
+ BOOST_TEST((test(L" x", lit(L'x'), space)));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ std::string s;
+ BOOST_TEST((test_attr("kimpo", string("kimpo"), s)));
+ BOOST_TEST(s == "kimpo");
+ BOOST_TEST((test_attr(L"kimpo", string(L"kimpo"), s)));
+ BOOST_TEST(s == "kimpo");
+ BOOST_TEST((test_attr("x", string("x"), s)));
+ BOOST_TEST(s == "x");
}
- { // lazy strings
+ { // lazy string
- using namespace boost::phoenix;
- std::basic_string<char> s("kimpo");
- BOOST_TEST((test("kimpo", lit(val(s)))));
+ using namespace boost::spirit::ascii;
+ using boost::phoenix::ref;
+ using boost::phoenix::val;
- std::basic_string<wchar_t> ws(L"kimpo");
- BOOST_TEST((test(L"kimpo", lit(ref(ws)))));
+ BOOST_TEST((test("x", string(val("x")))));
+
+ std::string str; // make sure lazy lits have an attribute
+ BOOST_TEST(test("x", string(val("x"))[ref(str) = _1]));
+ BOOST_TEST(str == "x");
}
return boost::report_errors();
Modified: trunk/libs/spirit/test/qi/match_manip.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/match_manip.cpp (original)
+++ trunk/libs/spirit/test/qi/match_manip.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,9 +1,16 @@
-// Copyright (c) 2001-2009 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/spirit/include/qi.hpp>
+/*=============================================================================
+ Copyright (c) 2001-2009 Hartmut Kaiser
+ Copyright (c) 2001-2009 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)
+=============================================================================*/
+#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
#include <boost/spirit/include/qi_stream.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -19,32 +26,20 @@
///////////////////////////////////////////////////////////////////////////////
template <typename Char, typename Expr>
-bool test(Char const *toparse, Expr const& xpr)
+bool test(Char const *toparse, Expr const& expr)
{
namespace spirit = boost::spirit;
- typedef
- spirit::traits::is_component<spirit::qi::domain, Expr>
- is_component;
-
- // report invalid expression error as early as possible
- BOOST_MPL_ASSERT_MSG(is_component::value,
- xpr_is_not_convertible_to_a_parser, ());
-
- typedef
- typename spirit::result_of::as_component<spirit::qi::domain, Expr>::type
- component;
- typedef typename component::director director;
-
- component c = spirit::as_component(spirit::qi::domain(), xpr);
+ BOOST_SPIRIT_ASSERT_MATCH(spirit::qi::domain, Expr)
std::istringstream istrm(toparse);
- istrm >> c;
+ istrm >> spirit::qi::compile<spirit::qi::domain>(expr);
return istrm.good() || istrm.eof();
}
-template <typename Char, typename Expr, typename Attribute, typename Skipper>
+template <typename Char, typename Expr, typename Copy, typename Skipper
+ , typename Attribute>
bool test(Char const *toparse,
- boost::spirit::qi::detail::match_manip<Expr, Attribute, Skipper> const& mm)
+ boost::spirit::qi::detail::match_manip<Expr, Copy, Skipper, Attribute> const& mm)
{
std::istringstream istrm(toparse);
istrm >> mm;
@@ -67,13 +62,17 @@
int
main()
{
- using namespace boost::spirit;
- using namespace boost::spirit::ascii;
- using namespace boost::spirit::arg_names;
- using namespace boost::spirit::qi;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::_2;
+ using boost::spirit::qi::match;
+ using boost::spirit::qi::phrase_match;
+ using boost::spirit::qi::typed_stream;
+ using boost::spirit::qi::stream;
+ using boost::spirit::qi::int_;
+ using boost::phoenix::ref;
+ using namespace boost::spirit::ascii;
namespace fusion = boost::fusion;
- using namespace boost::phoenix;
{
char c = '\0';
@@ -98,7 +97,7 @@
c = '\0';
BOOST_TEST(test( " a",
- phrase_match(char_, c, space)
+ phrase_match(char_, space, c)
) && c == 'a');
}
@@ -149,7 +148,7 @@
c = '\0';
BOOST_TEST(test( " a",
- phrase_match(stream, c, space)
+ phrase_match(stream, space, c)
) && c == 'a');
i = 0;
@@ -159,7 +158,7 @@
i = 0;
BOOST_TEST(test( " 42",
- phrase_match(stream, i, space)
+ phrase_match(stream, space, i)
) && i == 42);
}
@@ -186,7 +185,7 @@
t = fusion::vector<char, char>();
BOOST_TEST(test( " a b",
- phrase_match(char_ >> char_, t, space)
+ phrase_match(char_ >> char_, space, t)
) && fusion::at_c<0>(t) == 'a' && fusion::at_c<1>(t) == 'b');
}
@@ -219,7 +218,7 @@
t = fusion::vector<char, char, char>();
BOOST_TEST(test( " a b c",
- phrase_match(char_ >> char_ >> char_, t, space)
+ phrase_match(char_ >> char_ >> char_, space, t)
) && fusion::at_c<0>(t) == 'a' && fusion::at_c<1>(t) == 'b' && fusion::at_c<2>(t) == 'c');
}
@@ -237,14 +236,14 @@
t = fusion::vector<char, int>();
BOOST_TEST(test( " a 2",
- phrase_match(char_ >> int_, t, space)
+ phrase_match(char_ >> int_, space, t)
) && fusion::at_c<0>(t) == 'a' && fusion::at_c<1>(t) == 2);
BOOST_TEST(!test( "a2",
match(char_ >> alpha, t)
));
BOOST_TEST(!test( " a 2",
- phrase_match(char_ >> alpha, t, space)
+ phrase_match(char_ >> alpha, space, t)
));
}
@@ -262,7 +261,7 @@
v.clear();
BOOST_TEST(test( " a b c",
- phrase_match(*char_, v, space)
+ phrase_match(*char_, space, v)
) && 3 == v.size() && v[0] == 'a' && v[1] == 'b' && v[2] == 'c');
// parse a comma separated list of vector elements
@@ -273,7 +272,7 @@
v.clear();
BOOST_TEST(test( " a , b , c",
- phrase_match(char_ % ',', v, space)
+ phrase_match(char_ % ',', space, v)
) && 3 == v.size() && v[0] == 'a' && v[1] == 'b' && v[2] == 'c');
// output all elements of a list
@@ -284,7 +283,7 @@
l.clear();
BOOST_TEST(test( " a b c",
- phrase_match(*char_, l, space)
+ phrase_match(*char_, space, l)
) && 3 == l.size() && is_list_ok(l));
}
Added: trunk/libs/spirit/test/qi/match_manip_attr.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/match_manip_attr.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,166 @@
+// Copyright (c) 2001-2009 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)
+
+#define SPIRIT_ARGUMENTS_LIMIT 10
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_parse.hpp>
+
+#include "test_manip_attr.hpp"
+
+using namespace spirit_test;
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using namespace boost::spirit;
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test("1", char_, '1'));
+ BOOST_TEST(test("12", char_ >> char_, '1', '2'));
+ BOOST_TEST(test("123", char_ >> char_ >> char_, '1', '2', '3'));
+ BOOST_TEST(test("1234"
+ , char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4'));
+ BOOST_TEST(test("12345"
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5'));
+ BOOST_TEST(test("123456"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test("1234567"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test("12345678"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test("123456789"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test("1234567890"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test_skipped(" 1 ", char_, space, '1'));
+ BOOST_TEST(test_skipped(" 1 2 "
+ , char_ >> char_, space, '1', '2'));
+ BOOST_TEST(test_skipped(" 1 2 3 "
+ , char_ >> char_ >> char_, space, '1', '2', '3'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 "
+ , char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 "
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 8 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 8 9 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 8 9 0 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::qi::skip_flag;
+
+ BOOST_TEST(test_postskipped(" 1 ", char_, space
+ , skip_flag::postskip, '1'));
+ BOOST_TEST(test_postskipped(" 1 2 "
+ , char_ >> char_, space, skip_flag::postskip
+ , '1', '2'));
+ BOOST_TEST(test_postskipped(" 1 2 3 "
+ , char_ >> char_ >> char_, space
+ , skip_flag::postskip, '1', '2', '3'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 "
+ , char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip, '1', '2', '3', '4'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 "
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9 0 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::qi::skip_flag;
+
+ BOOST_TEST(test_postskipped(" 1", char_, space
+ , skip_flag::dont_postskip, '1'));
+ BOOST_TEST(test_postskipped(" 1 2"
+ , char_ >> char_, space, skip_flag::dont_postskip
+ , '1', '2'));
+ BOOST_TEST(test_postskipped(" 1 2 3"
+ , char_ >> char_ >> char_, space
+ , skip_flag::dont_postskip, '1', '2', '3'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4"
+ , char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip, '1', '2', '3', '4'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5"
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9 0"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ return boost::report_errors();
+}
+
Modified: trunk/libs/spirit/test/qi/no_case.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/no_case.cpp (original)
+++ trunk/libs/spirit/test/qi/no_case.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,9 +1,9 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
- http://spirit.sourceforge.net/
+ Copyright (c) 2001-2009 Joel de Guzman
+ include/qi_://spirit.sourceforge.net/
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)
+ file LICENSE_1_0.txt or copy at include/qi_://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/include/qi_char.hpp>
@@ -17,7 +17,8 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit;
+ using spirit_test::test_attr;
+ using boost::spirit::qi::lit;
{
using namespace boost::spirit::ascii;
@@ -36,12 +37,41 @@
{
using namespace boost::spirit::ascii;
+ BOOST_TEST(test("X", no_case['x']));
+ BOOST_TEST(test("X", no_case['X']));
+ BOOST_TEST(test("x", no_case['X']));
+ BOOST_TEST(test("x", no_case['x']));
+ BOOST_TEST(!test("z", no_case['X']));
+ BOOST_TEST(!test("z", no_case['x']));
+ }
+
+ {
+ using namespace boost::spirit::iso8859_1;
+ BOOST_TEST(test("Á", no_case[char_('á')]));
+ }
+
+ {
+ using namespace boost::spirit::iso8859_1;
+ BOOST_TEST(test("X", no_case[char_("a-z")]));
+ BOOST_TEST(!test("1", no_case[char_("a-z")]));
+ BOOST_TEST(test("É", no_case[char_("å-ï")]));
+ BOOST_TEST(!test("ÿ", no_case[char_("å-ï")]));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
BOOST_TEST(test("Bochi Bochi", no_case[lit("bochi bochi")]));
BOOST_TEST(test("BOCHI BOCHI", no_case[lit("bochi bochi")]));
BOOST_TEST(!test("Vavoo", no_case[lit("bochi bochi")]));
}
{
+ using namespace boost::spirit::iso8859_1;
+ BOOST_TEST(test("Áá", no_case[lit("áÁ")]));
+ BOOST_TEST(test("áá", no_case[no_case[lit("áÁ")]]));
+ }
+
+ {
// should work!
using namespace boost::spirit::ascii;
BOOST_TEST(test("x", no_case[no_case[char_]]));
@@ -92,12 +122,23 @@
}
{
- using namespace boost::spirit::standard;
// chsets
- BOOST_TEST(test("x", no_case[char_("a-z")]));
- BOOST_TEST(test("X", no_case[char_("a-z")]));
- BOOST_TEST(test(L"X", no_case[wchar(L"a-z")]));
- BOOST_TEST(test(L"X", no_case[wchar(L"X")]));
+ namespace standard = boost::spirit::standard;
+ namespace standard_wide = boost::spirit::standard_wide;
+
+ BOOST_TEST(test("x", standard::no_case[standard::char_("a-z")]));
+ BOOST_TEST(test("X", standard::no_case[standard::char_("a-z")]));
+ BOOST_TEST(test(L"X", standard_wide::no_case[standard_wide::char_(L"a-z")]));
+ BOOST_TEST(test(L"X", standard_wide::no_case[standard_wide::char_(L"X")]));
+ }
+
+ {
+ using namespace boost::spirit::standard;
+ std::string s("bochi bochi");
+ BOOST_TEST(test("Bochi Bochi", no_case[lit(s.c_str())]));
+ BOOST_TEST(test("Bochi Bochi", no_case[lit(s)]));
+ BOOST_TEST(test("Bochi Bochi", no_case[s.c_str()]));
+ BOOST_TEST(test("Bochi Bochi", no_case[s]));
}
return boost::report_errors();
Deleted: trunk/libs/spirit/test/qi/none.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/none.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,25 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2007 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)
-=============================================================================*/
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/include/qi_auxiliary.hpp>
-
-#include <iostream>
-#include "test.hpp"
-
-int
-main()
-{
- using spirit_test::test;
- using namespace boost::spirit;
-
- {
- BOOST_TEST((!test("", none)));
- BOOST_TEST((!test("xxx", none)));
- }
-
- return boost::report_errors();
-}
Modified: trunk/libs/spirit/test/qi/not_predicate.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/not_predicate.cpp (original)
+++ trunk/libs/spirit/test/qi/not_predicate.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -16,11 +16,12 @@
main()
{
using spirit_test::test;
- using namespace boost::spirit;
+ using boost::spirit::qi::int_;
{
BOOST_TEST((!test("1234", !int_)));
BOOST_TEST((test("abcd", !int_, false)));
+ BOOST_TEST((!test("abcd", !!int_, false)));
}
return boost::report_errors();
Added: trunk/libs/spirit/test/qi/omit.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/omit.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,134 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 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)
+=============================================================================*/
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_string.hpp>
+#include <boost/spirit/include/qi_directive.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <string>
+#include <iostream>
+#include "test.hpp"
+
+int
+main()
+{
+ using namespace boost::spirit::ascii;
+ using boost::spirit::qi::omit;
+ using boost::spirit::qi::unused_type;
+ using boost::spirit::qi::unused;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::_1;
+
+ using boost::fusion::vector;
+ using boost::fusion::at_c;
+
+ using spirit_test::test;
+ using spirit_test::test_attr;
+
+ {
+ BOOST_TEST(test("a", omit['a']));
+ }
+
+ {
+ // omit[] means we don't receive the attribute
+ vector<char> attr;
+ BOOST_TEST((test_attr("abc", omit[char_] >> omit['b'] >> char_, attr)));
+ BOOST_TEST((at_c<0>(attr) == 'c'));
+ }
+
+ {
+ // If all elements except 1 is omitted, the attribute is
+ // a single-element sequence. For this case alone, we allow
+ // naked attributes (unwrapped in a fusion sequence).
+ char attr;
+ BOOST_TEST((test_attr("abc", omit[char_] >> 'b' >> char_, attr)));
+ BOOST_TEST((attr == 'c'));
+ }
+
+ {
+ // omit[] means we don't receive the attribute
+ vector<> attr;
+ BOOST_TEST((test_attr("abc", omit[char_] >> omit['b'] >> omit[char_], attr)));
+ }
+
+ {
+ // omit[] means we don't receive the attribute
+ // this test is merely a compile test, because using a unused as the
+ // explicit attribute doesn't make any sense
+ unused_type attr;
+ BOOST_TEST((test_attr("abc", omit[char_ >> 'b' >> char_], attr)));
+ }
+
+ {
+ // omit[] means we don't receive the attribute, if all elements of a
+ // sequence have unused attributes, the whole sequence has an unused
+ // attribute as well
+ vector<char, char> attr;
+ BOOST_TEST((test_attr("abcde",
+ char_ >> (omit[char_] >> omit['c'] >> omit[char_]) >> char_, attr)));
+ BOOST_TEST((at_c<0>(attr) == 'a'));
+ BOOST_TEST((at_c<1>(attr) == 'e'));
+ }
+
+ {
+ // "hello" has an unused_type. unused attrubutes are not part of the sequence
+ vector<char, char> attr;
+ BOOST_TEST((test_attr("a hello c", char_ >> "hello" >> char_, attr, space)));
+ BOOST_TEST((at_c<0>(attr) == 'a'));
+ BOOST_TEST((at_c<1>(attr) == 'c'));
+ }
+
+ {
+ // omit[] means we don't receive the attribute
+ vector<char> attr;
+ BOOST_TEST((test_attr("a hello c", char_ >> "hello" >> omit[char_], attr, space)));
+ BOOST_TEST((at_c<0>(attr) == 'a'));
+ }
+
+ {
+ // if only one node in a sequence is left (all the others are omitted),
+ // then we should also allow "naked" attributes (unwraped in a tuple)
+ int attr;
+ BOOST_TEST((test_attr("a 123 c", omit['a'] >> int_ >> omit['c'], attr, space)));
+ BOOST_TEST((attr == 123));
+ }
+
+ {
+ // unused means we don't care about the attribute
+ BOOST_TEST((test_attr("abc", char_ >> 'b' >> char_, unused)));
+ }
+
+ { // test action with omitted attribute
+ char c = 0;
+
+ using boost::phoenix::ref;
+
+ BOOST_TEST(test("x123\"a string\"", (char_ >> omit[int_] >> "\"a string\"")
+ [ref(c) = _1]));
+ BOOST_TEST(c == 'x');
+ }
+
+
+ { // test action with omitted attribute
+ int n = 0;
+
+ using boost::phoenix::ref;
+
+ BOOST_TEST(test("x 123 \"a string\"",
+ (omit[char_] >> int_ >> "\"a string\"")[ref(n) = _1], space));
+ BOOST_TEST(n == 123);
+ }
+
+ return boost::report_errors();
+}
+
Modified: trunk/libs/spirit/test/qi/optional.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/optional.cpp (original)
+++ trunk/libs/spirit/test/qi/optional.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -22,7 +22,11 @@
{
using spirit_test::test;
using spirit_test::test_attr;
- using namespace boost::spirit;
+
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::omit;
+ using boost::spirit::ascii::char_;
{
BOOST_TEST((test("1234", -int_)));
@@ -30,7 +34,8 @@
}
{ // test propagation of unused
- using namespace boost::fusion;
+ using boost::fusion::at_c;
+ using boost::fusion::vector;
vector<char, char> v;
BOOST_TEST((test_attr("a1234c", char_ >> -omit[int_] >> char_, v)));
@@ -42,16 +47,14 @@
BOOST_TEST((at_c<0>(v) == 'a'));
BOOST_TEST((at_c<1>(v) == 'c'));
- //~ char ch;
- //~ BOOST_TEST((test_attr(",c", -(',' >> char_), ch)));
- //~ BOOST_TEST((ch == 'c'));
+ char ch;
+ BOOST_TEST((test_attr(",c", -(',' >> char_), ch)));
+ BOOST_TEST((ch == 'c'));
}
{ // test action
- using namespace boost::phoenix;
namespace phx = boost::phoenix;
- using namespace boost::spirit::arg_names;
boost::optional<int> n = 0;
BOOST_TEST((test("1234", (-int_)[phx::ref(n) = _1])));
Added: trunk/libs/spirit/test/qi/parse_attr.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/parse_attr.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,166 @@
+// Copyright (c) 2001-2009 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)
+
+#define SPIRIT_ARGUMENTS_LIMIT 10
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_parse_attr.hpp>
+
+#include "test_attr.hpp"
+
+using namespace spirit_test;
+
+///////////////////////////////////////////////////////////////////////////////
+int main()
+{
+ using namespace boost::spirit;
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test("1", char_, '1'));
+ BOOST_TEST(test("12", char_ >> char_, '1', '2'));
+ BOOST_TEST(test("123", char_ >> char_ >> char_, '1', '2', '3'));
+ BOOST_TEST(test("1234"
+ , char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4'));
+ BOOST_TEST(test("12345"
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5'));
+ BOOST_TEST(test("123456"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test("1234567"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test("12345678"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test("123456789"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test("1234567890"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+
+ BOOST_TEST(test_skipped(" 1 ", char_, space, '1'));
+ BOOST_TEST(test_skipped(" 1 2 "
+ , char_ >> char_, space, '1', '2'));
+ BOOST_TEST(test_skipped(" 1 2 3 "
+ , char_ >> char_ >> char_, space, '1', '2', '3'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 "
+ , char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 "
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 8 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 8 9 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_skipped(" 1 2 3 4 5 6 7 8 9 0 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::qi::skip_flag;
+
+ BOOST_TEST(test_postskipped(" 1 ", char_, space
+ , skip_flag::postskip, '1'));
+ BOOST_TEST(test_postskipped(" 1 2 "
+ , char_ >> char_, space, skip_flag::postskip
+ , '1', '2'));
+ BOOST_TEST(test_postskipped(" 1 2 3 "
+ , char_ >> char_ >> char_, space
+ , skip_flag::postskip, '1', '2', '3'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 "
+ , char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip, '1', '2', '3', '4'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 "
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9 0 "
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ {
+ using namespace boost::spirit::ascii;
+ using boost::spirit::qi::skip_flag;
+
+ BOOST_TEST(test_postskipped(" 1", char_, space
+ , skip_flag::dont_postskip, '1'));
+ BOOST_TEST(test_postskipped(" 1 2"
+ , char_ >> char_, space, skip_flag::dont_postskip
+ , '1', '2'));
+ BOOST_TEST(test_postskipped(" 1 2 3"
+ , char_ >> char_ >> char_, space
+ , skip_flag::dont_postskip, '1', '2', '3'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4"
+ , char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip, '1', '2', '3', '4'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5"
+ , char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip, '1', '2', '3', '4', '5'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9'));
+ BOOST_TEST(test_postskipped(" 1 2 3 4 5 6 7 8 9 0"
+ , char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_ >> char_
+ , space, skip_flag::dont_postskip
+ , '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'));
+ }
+
+ return boost::report_errors();
+}
+
Modified: trunk/libs/spirit/test/qi/permutation.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/permutation.cpp (original)
+++ trunk/libs/spirit/test/qi/permutation.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -28,9 +28,13 @@
int
main()
{
- using namespace boost::spirit;
- using boost::spirit::ascii::alpha;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::_2;
using boost::spirit::qi::rule;
+ using boost::spirit::ascii::alpha;
+ using boost::spirit::ascii::char_;
+
using boost::fusion::vector;
using boost::fusion::at_c;
using boost::optional;
@@ -76,7 +80,6 @@
{ // test action
using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
namespace phx = boost::phoenix;
optional<int> i;
Modified: trunk/libs/spirit/test/qi/plus.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/plus.cpp (original)
+++ trunk/libs/spirit/test/qi/plus.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -29,8 +29,11 @@
int
main()
{
- using namespace boost::spirit;
using namespace boost::spirit::ascii;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::omit;
+ using boost::spirit::qi::lit;
+ using boost::spirit::qi::_1;
{
BOOST_TEST(test("aaaaaaaa", +char_));
@@ -61,23 +64,23 @@
}
{
- std::vector<char> v;
- v.clear();
- BOOST_TEST(test_attr("bbbb", +omit[char_('b')], v) && 0 == v.size());
+ // The following 4 tests show that omit does not inhibit explicit attributes
+
+ std::string s;
+ BOOST_TEST(test_attr("bbbb", +omit[char_('b')], s) && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("bbbb", omit[+char_('b')], v) && 0 == v.size());
+ s.clear();
+ BOOST_TEST(test_attr("bbbb", omit[+char_('b')], s) && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("b b b b ", +omit[char_('b')], v, space) && 0 == v.size());
+ s.clear();
+ BOOST_TEST(test_attr("b b b b ", +omit[char_('b')], s, space) && s == "bbbb");
- v.clear();
- BOOST_TEST(test_attr("b b b b ", omit[+char_('b')], v, space) && 0 == v.size());
+ s.clear();
+ BOOST_TEST(test_attr("b b b b ", omit[+char_('b')], s, space) && s == "bbbb");
}
{ // actions
namespace phx = boost::phoenix;
- using boost::spirit::arg_names::_1;
std::vector<char> v;
BOOST_TEST(test("bbbb", (+char_)[phx::ref(v) = _1]) && 4 == v.size() &&
@@ -86,7 +89,6 @@
{ // more actions
namespace phx = boost::phoenix;
- using boost::spirit::arg_names::_1;
std::vector<int> v;
BOOST_TEST(test("1 2 3", (+int_)[phx::ref(v) = _1], space) && 3 == v.size() &&
Modified: trunk/libs/spirit/test/qi/range_run.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/range_run.cpp (original)
+++ trunk/libs/spirit/test/qi/range_run.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
Modified: trunk/libs/spirit/test/qi/raw.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/raw.cpp (original)
+++ trunk/libs/spirit/test/qi/raw.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -8,7 +8,7 @@
#include <boost/spirit/include/qi_directive.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_operator.hpp>
-#include <boost/spirit/include/qi_nonterminal.hpp>
+#include <boost/spirit/include/qi_auxiliary.hpp>
#include <iostream>
#include <string>
@@ -17,16 +17,19 @@
int
main()
{
+ using spirit_test::test;
using spirit_test::test_attr;
- using namespace boost::spirit;
using namespace boost::spirit::ascii;
- using boost::spirit::qi::rule;
+ using boost::spirit::qi::raw;
+ using boost::spirit::qi::eps;
{
boost::iterator_range<char const*> range;
std::string str;
BOOST_TEST((test_attr("spirit_test_123", raw[alpha >> *(alnum | '_')], range)));
BOOST_TEST((std::string(range.begin(), range.end()) == "spirit_test_123"));
+ BOOST_TEST((test_attr(" spirit", raw[*alpha], range, space)));
+ BOOST_TEST((range.size() == 6));
}
{
@@ -35,5 +38,12 @@
BOOST_TEST((str == "spirit_test_123"));
}
+ {
+ boost::iterator_range<char const*> range;
+ BOOST_TEST((test("x", raw[alpha])));
+ BOOST_TEST((test_attr("x", raw[alpha], range)));
+ //~ BOOST_TEST((test_attr("x", raw[alpha] >> eps, range)));
+ }
+
return boost::report_errors();
}
Modified: trunk/libs/spirit/test/qi/real.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/real.cpp (original)
+++ trunk/libs/spirit/test/qi/real.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 Joel de Guzman
Copyright (c) 2001-2009 Hartmut Kaiser
Use, modification and distribution is subject to the Boost Software
@@ -12,11 +12,10 @@
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
#include <boost/spirit/include/qi_operator.hpp>
-#include <boost/spirit/home/support/detail/math/fpclassify.hpp>
-#include <boost/spirit/home/support/detail/math/signbit.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
+#include <boost/math/special_functions/sign.hpp>
#include "test.hpp"
-using namespace spirit_test;
///////////////////////////////////////////////////////////////////////////////
// These policies can be used to parse thousand separated
@@ -56,11 +55,11 @@
static bool
parse_n(Iterator& first, Iterator const& last, Attribute& attr)
{
- using namespace boost::spirit::qi;
- using namespace boost::spirit;
+ using boost::spirit::qi::uint_parser;
+ namespace qi = boost::spirit::qi;
- uint_spec<unsigned, 10, 1, 3> uint3;
- uint_spec<unsigned, 10, 3, 3> uint3_3;
+ uint_parser<unsigned, 10, 1, 3> uint3;
+ uint_parser<unsigned, 10, 3, 3> uint3_3;
T result = 0;
if (parse(first, last, uint3, result))
@@ -69,7 +68,7 @@
T n;
Iterator save = first;
- while (parse(first, last, ',') && parse(first, last, uint3_3, n))
+ while (qi::parse(first, last, ',') && qi::parse(first, last, uint3_3, n))
{
result = result * 1000 + n;
save = first;
@@ -101,7 +100,7 @@
bool
compare(T n, double expected)
{
- double const eps = 0.00001;
+ T const eps = std::numeric_limits<T>::epsilon();
T delta = n - expected;
return (delta >= -eps) && (delta <= eps);
}
@@ -109,15 +108,18 @@
int
main()
{
+ using spirit_test::test;
+ using spirit_test::test_attr;
+
///////////////////////////////////////////////////////////////////////////////
// thousand separated numbers
///////////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::qi::uint_spec;
+ using boost::spirit::qi::uint_parser;
using boost::spirit::qi::parse;
- uint_spec<unsigned, 10, 1, 3> uint3;
- uint_spec<unsigned, 10, 3, 3> uint3_3;
+ uint_parser<unsigned, 10, 1, 3> uint3;
+ uint_parser<unsigned, 10, 3, 3> uint3_3;
#define r (uint3 >> *(',' >> uint3_3))
@@ -133,11 +135,11 @@
// unsigned real number tests
///////////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::qi::real_spec;
+ using boost::spirit::qi::real_parser;
using boost::spirit::qi::parse;
using boost::spirit::qi::ureal_policies;
- real_spec<double, ureal_policies<double> > udouble;
+ real_parser<double, ureal_policies<double> > udouble;
double d;
BOOST_TEST(test("1234", udouble));
@@ -204,7 +206,7 @@
// signed real number tests
///////////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::double_;
+ using boost::spirit::qi::double_;
using boost::spirit::qi::parse;
double d;
@@ -238,8 +240,21 @@
BOOST_TEST(!test("-1.2e", double_));
BOOST_TEST(!test_attr("-1.2e", double_, d));
- using boost::spirit::math::fpclassify;
- using boost::spirit::math::signbit;
+ BOOST_TEST(test_attr("-5.7222349715140557e+307", double_, d));
+ BOOST_TEST(d == -5.7222349715140557e+307); // exact!
+
+ BOOST_TEST(test_attr("2.0332938517515416e-308", double_, d));
+ BOOST_TEST(d == 2.0332938517515416e-308); // exact!
+
+ BOOST_TEST(test_attr("20332938517515416e291", double_, d));
+ BOOST_TEST(d == 20332938517515416e291); // exact!
+
+ BOOST_TEST(test_attr("2.0332938517515416e307", double_, d));
+ BOOST_TEST(d == 2.0332938517515416e307); // exact!
+
+ using boost::math::fpclassify;
+ using boost::spirit::detail::signbit; // Boost version is broken
+
BOOST_TEST(test("-inf", double_));
BOOST_TEST(test("-infinity", double_));
BOOST_TEST(test_attr("-inf", double_, d) &&
@@ -272,13 +287,13 @@
// strict real number tests
///////////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::qi::real_spec;
+ using boost::spirit::qi::real_parser;
using boost::spirit::qi::parse;
using boost::spirit::qi::strict_ureal_policies;
using boost::spirit::qi::strict_real_policies;
- real_spec<double, strict_ureal_policies<double> > strict_udouble;
- real_spec<double, strict_real_policies<double> > strict_double;
+ real_parser<double, strict_ureal_policies<double> > strict_udouble;
+ real_parser<double, strict_real_policies<double> > strict_double;
double d;
BOOST_TEST(!test("1234", strict_udouble));
@@ -296,8 +311,8 @@
BOOST_TEST(test("3.E6", strict_double));
BOOST_TEST(test_attr("3.E6", strict_double, d) && compare(d, 3e6));
- real_spec<double, no_trailing_dot_policy<double> > notrdot_real;
- real_spec<double, no_leading_dot_policy<double> > nolddot_real;
+ real_parser<double, no_trailing_dot_policy<double> > notrdot_real;
+ real_parser<double, no_leading_dot_policy<double> > nolddot_real;
BOOST_TEST(!test("1234.", notrdot_real)); // Bad trailing dot
BOOST_TEST(!test(".1234", nolddot_real)); // Bad leading dot
@@ -307,9 +322,9 @@
// Special thousands separated numbers
///////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::qi::real_spec;
+ using boost::spirit::qi::real_parser;
using boost::spirit::qi::parse;
- real_spec<double, ts_real_policies<double> > ts_real;
+ real_parser<double, ts_real_policies<double> > ts_real;
double d;
BOOST_TEST(test("123,456,789.01", ts_real));
@@ -332,13 +347,13 @@
///////////////////////////////////////////////////////////////////////////
{
using boost::math::concepts::real_concept;
- using boost::spirit::qi::real_spec;
+ using boost::spirit::qi::real_parser;
using boost::spirit::qi::real_policies;
using boost::spirit::qi::parse;
-
- real_spec<real_concept, real_policies<real_concept> > custom_real;
+
+ real_parser<real_concept, real_policies<real_concept> > custom_real;
real_concept d;
-
+
BOOST_TEST(test("-1234", custom_real));
BOOST_TEST(test_attr("-1234", custom_real, d) && compare(d, -1234));
@@ -369,6 +384,6 @@
BOOST_TEST(!test("-1.2e", custom_real));
BOOST_TEST(!test_attr("-1.2e", custom_real, d));
}
-
+
return boost::report_errors();
}
Added: trunk/libs/spirit/test/qi/repeat.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/repeat.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,179 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 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)
+=============================================================================*/
+#include <string>
+#include <vector>
+
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/utility/enable_if.hpp>
+
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_string.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_directive.hpp>
+#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/support_argument.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <string>
+#include <iostream>
+#include "test.hpp"
+
+
+int
+main()
+{
+ using spirit_test::test_attr;
+ using spirit_test::test;
+
+ using namespace boost::spirit::ascii;
+ using boost::spirit::qi::repeat;
+ using boost::spirit::qi::inf;
+ using boost::spirit::qi::omit;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::_1;
+
+ {
+ BOOST_TEST(test("aaaaaaaa", repeat[char_])); // kleene synonym
+ BOOST_TEST(test("aaaaaaaa", repeat(8)[char_]));
+ BOOST_TEST(!test("aa", repeat(3)[char_]));
+
+ BOOST_TEST(test("aaa", repeat(3, 5)[char_]));
+ BOOST_TEST(test("aaaaa", repeat(3, 5)[char_]));
+ BOOST_TEST(!test("aaaaaa", repeat(3, 5)[char_]));
+ BOOST_TEST(!test("aa", repeat(3, 5)[char_]));
+
+ BOOST_TEST(test("aaa", repeat(3, inf)[char_]));
+ BOOST_TEST(test("aaaaa", repeat(3, inf)[char_]));
+ BOOST_TEST(test("aaaaaa", repeat(3, inf)[char_]));
+ BOOST_TEST(!test("aa", repeat(3, inf)[char_]));
+ }
+
+ { // from classic spirit tests
+ BOOST_TEST(test("", repeat(0, inf)['x']));
+
+ // repeat exact 8
+ #define rep8 repeat(8)[alpha] >> 'X'
+ BOOST_TEST(!test("abcdefgX", rep8, false));
+ BOOST_TEST(test("abcdefghX", rep8));
+ BOOST_TEST(!test("abcdefghiX", rep8, false));
+ BOOST_TEST(!test("abcdefgX", rep8, false));
+ BOOST_TEST(!test("aX", rep8, false));
+
+ // repeat 2 to 8
+ #define rep28 repeat(2, 8)[alpha] >> '*'
+ BOOST_TEST(test("abcdefg*", rep28));
+ BOOST_TEST(test("abcdefgh*", rep28));
+ BOOST_TEST(!test("abcdefghi*", rep28, false));
+ BOOST_TEST(!test("a*", rep28, false));
+
+ // repeat 2 or more
+ #define rep2_ repeat(2, inf)[alpha] >> '+'
+ BOOST_TEST(test("abcdefg+", rep2_));
+ BOOST_TEST(test("abcdefgh+", rep2_));
+ BOOST_TEST(test("abcdefghi+", rep2_));
+ BOOST_TEST(test("abcdefg+", rep2_));
+ BOOST_TEST(!test("a+", rep2_, false));
+
+ // repeat 0
+ #define rep0 repeat(0)[alpha] >> '/'
+ BOOST_TEST(test("/", rep0));
+ BOOST_TEST(!test("a/", rep0, false));
+
+ // repeat 0 or 1
+ #define rep01 repeat(0, 1)[alpha >> digit] >> '?'
+ BOOST_TEST(!test("abcdefg?", rep01, false));
+ BOOST_TEST(!test("a?", rep01, false));
+ BOOST_TEST(!test("1?", rep01, false));
+ BOOST_TEST(!test("11?", rep01, false));
+ BOOST_TEST(!test("aa?", rep01, false));
+ BOOST_TEST(test("?", rep01));
+ BOOST_TEST(test("a1?", rep01));
+ }
+
+ {
+ BOOST_TEST(test(" a a aaa aa", repeat(7)[char_], space));
+ BOOST_TEST(test("12345 678 9", repeat(9)[digit], space));
+ }
+
+ {
+ BOOST_TEST(test("aBcdeFGH", no_case[repeat(8)[lower]]));
+ BOOST_TEST(test("a B cde FGH", no_case[repeat(8)[lower]], space));
+ }
+
+ {
+ std::string s;
+ BOOST_TEST(test_attr("bbbb", repeat(4)[char_], s) && s == "bbbb");
+
+ s.clear();
+ BOOST_TEST(test_attr("b b b b", repeat(4)[char_], s, space) && s == "bbbb");
+
+ // The following 4 tests show that omit does not inhibit explicit attributes
+ s.clear();
+ BOOST_TEST(test_attr("bbbb", repeat(4)[omit[char_('b')]], s) && s == "bbbb");
+
+ s.clear();
+ BOOST_TEST(test_attr("bbbb", omit[repeat(4)[char_('b')]], s) && s == "bbbb");
+
+ s.clear();
+ BOOST_TEST(test_attr("b b b b", repeat(4)[omit[char_('b')]], s, space) && s == "bbbb");
+
+ s.clear();
+ BOOST_TEST(test_attr("b b b b", omit[repeat(4)[char_('b')]], s, space) && s == "bbbb");
+ }
+
+ { // actions
+ namespace phx = boost::phoenix;
+
+ std::vector<char> v;
+ BOOST_TEST(test("bbbb", repeat(4)[char_][phx::ref(v) = _1]) && 4 == v.size() &&
+ v[0] == 'b' && v[1] == 'b' && v[2] == 'b' && v[3] == 'b');
+ }
+
+ { // more actions
+ namespace phx = boost::phoenix;
+
+ std::vector<int> v;
+ BOOST_TEST(test("123 456 789", repeat(3)[int_][phx::ref(v) = _1], space) && 3 == v.size() &&
+ v[0] == 123 && v[1] == 456 && v[2] == 789);
+ }
+
+ { // lazy repeats
+ using boost::phoenix::val;
+
+ BOOST_TEST(test("aaaaaaaa", repeat(val(8))[char_]));
+ BOOST_TEST(!test("aa", repeat(val(3))[char_]));
+
+ BOOST_TEST(test("aaa", repeat(val(3), val(5))[char_]));
+ BOOST_TEST(test("aaaaa", repeat(val(3), val(5))[char_]));
+ BOOST_TEST(!test("aaaaaa", repeat(val(3), val(5))[char_]));
+ BOOST_TEST(!test("aa", repeat(val(3), val(5))[char_]));
+
+ BOOST_TEST(test("aaa", repeat(val(3), val(inf))[char_]));
+ BOOST_TEST(test("aaaaa", repeat(val(3), val(inf))[char_]));
+ BOOST_TEST(test("aaaaaa", repeat(val(3), val(inf))[char_]));
+ BOOST_TEST(!test("aa", repeat(val(3), val(inf))[char_]));
+ }
+
+ { // more lazy repeats
+ using boost::phoenix::val;
+
+ BOOST_TEST(test("aaa", repeat(3, val(5))[char_]));
+ BOOST_TEST(test("aaaaa", repeat(val(3), 5)[char_]));
+ BOOST_TEST(!test("aaaaaa", repeat(3, val(5))[char_]));
+ BOOST_TEST(!test("aa", repeat(val(3), 5)[char_]));
+
+ BOOST_TEST(test("aaa", repeat(val(3), inf)[char_]));
+ BOOST_TEST(test("aaaaa", repeat(3, val(inf))[char_]));
+ BOOST_TEST(test("aaaaaa", repeat(val(3), inf)[char_]));
+ BOOST_TEST(!test("aa", repeat(3, val(inf))[char_]));
+ }
+
+ return boost::report_errors();
+}
+
Modified: trunk/libs/spirit/test/qi/rule.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/rule.cpp (original)
+++ trunk/libs/spirit/test/qi/rule.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -9,23 +9,38 @@
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/qi_nonterminal.hpp>
#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_object.hpp>
+#include <boost/spirit/include/phoenix_bind.hpp>
+#include <boost/fusion/include/std_pair.hpp>
#include <string>
+#include <cstring>
#include <iostream>
#include "test.hpp"
-using namespace spirit_test;
-
int
main()
{
- using namespace boost::spirit::qi;
+ using spirit_test::test_attr;
+ using spirit_test::test;
+
using namespace boost::spirit::ascii;
+ using namespace boost::spirit::qi::labels;
+ using boost::spirit::qi::locals;
+ using boost::spirit::qi::rule;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::fail;
+ using boost::spirit::qi::on_error;
+ using boost::spirit::qi::debug;
+
+ using boost::phoenix::ref;
+ using boost::phoenix::val;
+
{ // basic tests
@@ -35,12 +50,25 @@
b = 'b';
c = 'c';
+ a.name("a");
+ b.name("b");
+ c.name("c");
+ start.name("start");
+
+ debug(a);
+ debug(b);
+ debug(c);
+ debug(start);
+
start = *(a | b | c);
BOOST_TEST(test("abcabcacb", start));
start = (a | b) >> (start | b);
BOOST_TEST(test("aaaabababaaabbb", start));
BOOST_TEST(test("aaaabababaaabba", start, false));
+
+ // ignore the skipper!
+ BOOST_TEST(test("aaaabababaaabba", start, space, false));
}
{ // basic tests w/ skipper
@@ -51,17 +79,68 @@
b = 'b';
c = 'c';
- start = *(a | b | c);
- BOOST_TEST(test(" a b c a b c a c b", start, space));
+ a.name("a");
+ b.name("b");
+ c.name("c");
+ start.name("start");
+
+ debug(a);
+ debug(b);
+ debug(c);
+ debug(start);
- // allow no skipping too:
- BOOST_TEST(test("abcabcacb", start));
+ start = *(a | b | c);
+ BOOST_TEST(test(" a b c a b c a c b ", start, space));
start = (a | b) >> (start | b);
BOOST_TEST(test(" a a a a b a b a b a a a b b b ", start, space));
BOOST_TEST(test(" a a a a b a b a b a a a b b a ", start, space, false));
}
+ { // basic tests w/ skipper but no final post-skip
+
+ rule<char const*, space_type> a, b, c, start;
+
+ a = 'a';
+ b = 'b';
+ c = 'c';
+
+ a.name("a");
+ b.name("b");
+ c.name("c");
+ start.name("start");
+
+ debug(a);
+ debug(b);
+ debug(c);
+ debug(start);
+
+ start = *(a | b) >> c;
+
+ using boost::spirit::qi::phrase_parse;
+ using boost::spirit::qi::skip_flag;
+ {
+ char const *s1 = " a b a a b b a c ... "
+ , *const e1 = s1 + std::strlen(s1);
+ BOOST_TEST(phrase_parse(s1, e1, start, space, skip_flag::dont_postskip)
+ && s1 == e1 - 5);
+ }
+
+ start = (a | b) >> (start | c);
+ {
+ char const *s1 = " a a a a b a b a b a a a b b b c "
+ , *const e1 = s1 + std::strlen(s1);
+ BOOST_TEST(phrase_parse(s1, e1, start, space, skip_flag::postskip)
+ && s1 == e1);
+ }
+ {
+ char const *s1 = " a a a a b a b a b a a a b b b c "
+ , *const e1 = s1 + std::strlen(s1);
+ BOOST_TEST(phrase_parse(s1, e1, start, space, skip_flag::dont_postskip)
+ && s1 == e1 - 1);
+ }
+ }
+
{ // alias tests
rule<char const*> a, b, c, d, start;
@@ -105,11 +184,6 @@
{ // context tests
- using namespace boost::phoenix;
- using namespace boost::spirit::ascii;
- using boost::spirit::arg_names::_1;
- using boost::spirit::arg_names::_val;
-
char ch;
rule<char const*, char()> a;
a = alpha[_val = _1];
@@ -121,14 +195,61 @@
BOOST_TEST(ch == 'z');
}
- { // context (w/arg) tests
+ { // auto rules tests
- using namespace boost::phoenix;
- using namespace boost::spirit::ascii;
- using boost::spirit::arg_names::_1;
- using boost::spirit::arg_names::_r1;
- using boost::spirit::arg_names::_r2;
- using boost::spirit::arg_names::_val;
+ char ch;
+ rule<char const*, char()> a;
+ a %= alpha;
+
+ BOOST_TEST(test("x", a[ref(ch) = _1]));
+ BOOST_TEST(ch == 'x');
+
+ BOOST_TEST(test_attr("z", a, ch)); // attribute is given.
+ BOOST_TEST(ch == 'z');
+ }
+
+ { // auto rules tests: allow stl containers as attributes to
+ // sequences (in cases where attributes of the elements
+ // are convertible to the value_type of the container or if
+ // the element itself is an stl container with value_type
+ // that is convertible to the value_type of the attribute).
+
+ std::string s;
+ rule<char const*, std::string()> r;
+ r %= char_ >> *(',' >> char_);
+
+ BOOST_TEST(test("a,b,c,d,e,f", r[ref(s) = _1]));
+ BOOST_TEST(s == "abcdef");
+
+ r %= char_ >> char_ >> char_ >> char_ >> char_ >> char_;
+ BOOST_TEST(test("abcdef", r[ref(s) = _1]));
+ BOOST_TEST(s == "abcdef");
+ }
+
+ { // synth attribute value-init
+
+ std::string s;
+ rule<char const*, char()> r;
+ r = alpha[_val += _1];
+ BOOST_TEST(test_attr("abcdef", +r, s));
+ BOOST_TEST(s == "abcdef");
+ }
+
+ { // auto rules aliasing tests
+
+ char ch;
+ rule<char const*, char()> a, b;
+ a %= b;
+ b %= alpha;
+
+ BOOST_TEST(test("x", a[ref(ch) = _1]));
+ BOOST_TEST(ch == 'x');
+
+ BOOST_TEST(test_attr("z", a, ch)); // attribute is given.
+ BOOST_TEST(ch == 'z');
+ }
+
+ { // context (w/arg) tests
char ch;
rule<char const*, char(int)> a; // 1 arg
@@ -146,13 +267,17 @@
BOOST_TEST(ch == 'a' + 1 + 2);
}
+ { // context (w/ reference arg) tests
+
+ char ch;
+ rule<char const*, void(char&)> a; // 1 arg (reference)
+ a = alpha[_r1 = _1];
+
+ BOOST_TEST(test("x", a(ref(ch))));
+ BOOST_TEST(ch == 'x');
+ }
+
{ // context (w/locals) tests
- using namespace boost::phoenix;
- using namespace boost::spirit::ascii;
- using boost::spirit::arg_names::_1;
- using boost::spirit::arg_names::_a;
- using boost::spirit::char_;
- using boost::spirit::locals;
rule<char const*, locals<char> > a; // 1 local
a = alpha[_a = _1] >> char_(_a);
@@ -161,13 +286,6 @@
}
{ // context (w/args and locals) tests
- using namespace boost::phoenix;
- using namespace boost::spirit::ascii;
- using boost::spirit::arg_names::_1;
- using boost::spirit::arg_names::_r1;
- using boost::spirit::arg_names::_a;
- using boost::spirit::char_;
- using boost::spirit::locals;
rule<char const*, void(int), locals<char> > a; // 1 arg + 1 local
a = alpha[_a = _1 + _r1] >> char_(_a);
@@ -176,13 +294,17 @@
BOOST_TEST(!test("ax", a(val(1))));
}
+ { // void() has unused type (void == unused_type)
+
+ std::pair<int, char> attr;
+ rule<char const*, void()> r;
+ r = char_;
+ BOOST_TEST(test_attr("123ax", int_ >> char_ >> r, attr));
+ BOOST_TEST(attr.first == 123);
+ BOOST_TEST(attr.second == 'a');
+ }
+
{ // bug: test that injected attributes are ok
- using namespace boost::phoenix;
- using namespace boost::spirit::ascii;
- using boost::spirit::arg_names::_1;
- using boost::spirit::arg_names::_r1;
- using boost::spirit::arg_names::_val;
- using boost::spirit::char_;
rule<char const*, char(int) > r;
@@ -190,16 +312,38 @@
r = char_(_r1)[_val = _1];
}
+ { // show that ra = rb and ra %= rb works as expected
+ rule<char const*, int() > ra, rb;
+ int attr;
+
+ ra %= int_;
+ BOOST_TEST(test_attr("123", ra, attr));
+ BOOST_TEST(attr == 123);
+
+ rb %= ra;
+ BOOST_TEST(test_attr("123", rb, attr));
+ BOOST_TEST(attr == 123);
+
+ rb = ra;
+ BOOST_TEST(test_attr("123", rb, attr));
+ BOOST_TEST(attr == 123);
+ }
+
+ { // std::string as container attribute with auto rules
+
+ rule<char const*, std::string()> text;
+ text %= +(!char_(')') >> !char_('>') >> char_);
+ std::string attr;
+ BOOST_TEST(test_attr("x", text, attr));
+ BOOST_TEST(attr == "x");
+ }
+
{ // error handling
- using namespace boost::phoenix;
using namespace boost::spirit::ascii;
using boost::phoenix::val;
- using boost::spirit::int_;
- using boost::spirit::arg_names::_4; // what
- using boost::spirit::arg_names::_3; // error pos
- using boost::spirit::arg_names::_2; // end
- using boost::spirit::qi::fail;
+ using boost::phoenix::construct;
+ using boost::phoenix::bind;
rule<char const*> r;
r = '(' > int_ > ',' > int_ > ')';
@@ -209,7 +353,7 @@
r, std::cout
<< val("Error! Expecting: ")
<< _4
- << val(" Here: \"")
+ << val(", got: \"")
<< construct<std::string>(_3, _2)
<< val("\"")
<< std::endl
Modified: trunk/libs/spirit/test/qi/sequence.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/sequence.cpp (original)
+++ trunk/libs/spirit/test/qi/sequence.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -12,8 +12,6 @@
#include <boost/spirit/include/qi_directive.hpp>
#include <boost/spirit/include/qi_action.hpp>
#include <boost/spirit/include/support_argument.hpp>
-#include <boost/fusion/include/vector.hpp>
-#include <boost/fusion/include/at.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_statement.hpp>
@@ -25,12 +23,20 @@
int
main()
{
- using namespace boost::spirit;
using namespace boost::spirit::ascii;
+ using boost::spirit::qi::lit;
+ using boost::spirit::qi::unused;
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::what;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::_2;
+
using boost::fusion::vector;
using boost::fusion::at_c;
+
using spirit_test::test;
using spirit_test::test_attr;
+ using spirit_test::print_info;
{
BOOST_TEST((test("aa", char_ >> char_)));
@@ -42,9 +48,9 @@
}
{
- BOOST_TEST((test(" a a ", char_ >> char_, space)));
- BOOST_TEST((test(" x i ", char_('x') >> char_('i'), space)));
- BOOST_TEST((!test(" x i ", char_('x') >> char_('o'), space)));
+ BOOST_TEST((test(" a a", char_ >> char_, space)));
+ BOOST_TEST((test(" x i", char_('x') >> char_('i'), space)));
+ BOOST_TEST((!test(" x i", char_('x') >> char_('o'), space)));
}
{
@@ -60,7 +66,7 @@
{
vector<char, char, char> attr;
- BOOST_TEST((test_attr(" a\n b\n c\n ", char_ >> char_ >> char_, attr, space)));
+ BOOST_TEST((test_attr(" a\n b\n c", char_ >> char_ >> char_, attr, space)));
BOOST_TEST((at_c<0>(attr) == 'a'));
BOOST_TEST((at_c<1>(attr) == 'b'));
BOOST_TEST((at_c<2>(attr) == 'c'));
@@ -75,47 +81,6 @@
}
{
- // omit[] means we don't receive the attribute
- vector<char> attr;
- BOOST_TEST((test_attr("abc", omit[char_] >> omit['b'] >> char_, attr)));
- BOOST_TEST((at_c<0>(attr) == 'c'));
- }
-
- {
- // If all elements except 1 is omitted, the attribute is
- // a single-element sequence. For this case alone, we allow
- // naked attributes (unwrapped in a fusion sequence).
- char attr;
- BOOST_TEST((test_attr("abc", omit[char_] >> 'b' >> char_, attr)));
- BOOST_TEST((attr == 'c'));
- }
-
- {
- // omit[] means we don't receive the attribute
- vector<> attr;
- BOOST_TEST((test_attr("abc", omit[char_] >> omit['b'] >> omit[char_], attr)));
- }
-
- {
- // omit[] means we don't receive the attribute
- // this test is merely a compile test, because using a unused as the
- // explicit attribute doesn't make any sense
- unused_type attr;
- BOOST_TEST((test_attr("abc", omit[char_ >> 'b' >> char_], attr)));
- }
-
- {
- // omit[] means we don't receive the attribute, if all elements of a
- // sequence have unused attributes, the whole sequence has an unused
- // attribute as well
- vector<char, char> attr;
- BOOST_TEST((test_attr("abcde",
- char_ >> (omit[char_] >> omit['c'] >> omit[char_]) >> char_, attr)));
- BOOST_TEST((at_c<0>(attr) == 'a'));
- BOOST_TEST((at_c<1>(attr) == 'e'));
- }
-
- {
// "hello" has an unused_type. unused attrubutes are not part of the sequence
vector<char, char> attr;
BOOST_TEST((test_attr("a hello c", char_ >> "hello" >> char_, attr, space)));
@@ -124,18 +89,10 @@
}
{
- // omit[] means we don't receive the attribute
- vector<char> attr;
- BOOST_TEST((test_attr("a hello c", char_ >> "hello" >> omit[char_], attr, space)));
- BOOST_TEST((at_c<0>(attr) == 'a'));
- }
-
- {
- // if only one node in a sequence is left (all the others are omitted),
- // then we should also allow "naked" attributes (unwraped in a tuple)
- int attr;
- BOOST_TEST((test_attr("a 123 c", omit['a'] >> int_ >> omit['c'], attr, space)));
- BOOST_TEST((attr == 123));
+ // a single element
+ char attr;
+ BOOST_TEST((test_attr("ab", char_ >> 'b', attr)));
+ BOOST_TEST((attr == 'a'));
}
{
@@ -150,14 +107,36 @@
}
{
-#ifdef SPIRIT_TEST_COMPILE_FAIL // $$$
+#ifdef SPIRIT_NO_COMPILE_CHECK
char_ >> char_ = char_ >> char_; // disallow this!
#endif
}
+ { // alternative forms of attributes. Allow sequences to take in
+ // stl containers.
+
+ std::vector<char> v;
+ BOOST_TEST(test_attr("abc", char_ >> char_ >> char_, v));
+ BOOST_TEST(v.size() == 3);
+ BOOST_TEST(v[0] == 'a');
+ BOOST_TEST(v[1] == 'b');
+ BOOST_TEST(v[2] == 'c');
+ }
+
+ { // alternative forms of attributes. Allow sequences to take in
+ // stl containers.
+
+ std::vector<char> v;
+ BOOST_TEST(test_attr("a,b,c", char_ >> *(',' >> char_), v));
+ BOOST_TEST(v.size() == 3);
+ BOOST_TEST(v[0] == 'a');
+ BOOST_TEST(v[1] == 'b');
+ BOOST_TEST(v[2] == 'c');
+
+ }
+
{ // test action
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
+ using boost::phoenix::ref;
char c = 0;
int n = 0;
@@ -167,19 +146,8 @@
BOOST_TEST(n == 123);
}
- { // test action with omitted attribute
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
- char c = 0;
-
- BOOST_TEST(test("x123\"a string\"", (char_ >> omit[int_] >> "\"a string\"")
- [ref(c) = _1]));
- BOOST_TEST(c == 'x');
- }
-
{ // test action
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
+ using boost::phoenix::ref;
char c = 0;
int n = 0;
@@ -189,14 +157,9 @@
BOOST_TEST(n == 123);
}
- { // test action with omitted attribute
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
- int n = 0;
+ { // testing "what"
- BOOST_TEST(test("x 123 \"a string\"",
- (omit[char_] >> int_ >> "\"a string\"")[ref(n) = _1], space));
- BOOST_TEST(n == 123);
+ print_info(what(alpha | char_('x') >> lit("hello") >> int_));
}
return boost::report_errors();
Modified: trunk/libs/spirit/test/qi/sequential_or.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/sequential_or.cpp (original)
+++ trunk/libs/spirit/test/qi/sequential_or.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -22,12 +22,16 @@
#include <iostream>
#include "test.hpp"
-using namespace spirit_test;
-
int
main()
{
- using namespace boost::spirit;
+ using spirit_test::test;
+ using spirit_test::test_attr;
+
+ using boost::spirit::qi::int_;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::_2;
+ using boost::spirit::ascii::char_;
using boost::spirit::ascii::alpha;
using boost::fusion::vector;
using boost::fusion::at_c;
@@ -59,9 +63,22 @@
BOOST_TEST((!test("a123", int_ || alpha)));
}
+ { // test unused attribute handling
+
+ vector<optional<int>, optional<char> > attr;
+ BOOST_TEST((test_attr("123ab", int_ || ("a" >> char_), attr)));
+ BOOST_TEST((at_c<0>(attr).get() == 123));
+ BOOST_TEST((at_c<1>(attr).get() == 'b'));
+ }
+
+ { // test unused attribute handling
+
+ optional<int> attr;
+ BOOST_TEST((test_attr("123a", int_ || "a", attr)));
+ BOOST_TEST((attr == 123));
+ }
+
{ // test action
- using namespace boost::phoenix;
- using namespace boost::spirit::arg_names;
namespace phx = boost::phoenix;
optional<int> i;
Added: trunk/libs/spirit/test/qi/skip.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/skip.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,51 @@
+/*=============================================================================
+ Copyright (c) 2001-2009 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)
+=============================================================================*/
+#include <boost/detail/lightweight_test.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/qi_directive.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+
+#include <iostream>
+#include "test.hpp"
+
+int
+main()
+{
+ using spirit_test::test;
+ using spirit_test::test_attr;
+ using boost::spirit::qi::skip;
+ using boost::spirit::qi::lexeme;
+ using boost::spirit::qi::lit;
+ using boost::spirit::ascii::char_;
+ using boost::spirit::ascii::space;
+ using boost::spirit::ascii::alpha;
+
+ {
+ BOOST_TEST((test("a b c d", skip(space)[*char_])));
+ }
+
+ { // test attribute
+ std::string s;
+ BOOST_TEST((test_attr("a b c d", skip(space)[*char_], s)));
+ BOOST_TEST(s == "abcd");
+ }
+
+ { // reskip
+ BOOST_TEST((test("ab c d", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
+ BOOST_TEST((test("abcd", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
+ BOOST_TEST(!(test("a bcd", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
+ }
+
+ { // lazy skip
+ using boost::phoenix::val;
+
+ BOOST_TEST((test("a b c d", skip(val(space))[*char_])));
+ }
+
+ return boost::report_errors();
+}
Modified: trunk/libs/spirit/test/qi/symbols.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/symbols.cpp (original)
+++ trunk/libs/spirit/test/qi/symbols.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -8,7 +8,10 @@
#include <boost/spirit/include/qi_string.hpp>
#include <boost/spirit/include/qi_char.hpp>
#include <boost/spirit/include/qi_action.hpp>
+#include <boost/spirit/include/qi_auxiliary.hpp>
#include <boost/spirit/include/qi_directive.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_nonterminal.hpp>
#include <boost/spirit/include/support_argument.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
@@ -16,12 +19,28 @@
#include <iostream>
#include "test.hpp"
+// Custom string type with a C-style string conversion.
+struct custom_string_c
+{
+ custom_string_c(char c) { str[0] = c; str[1] = '\0'; }
+
+ operator char*() { return str; }
+ operator char const*() const { return str; }
+
+private:
+ char str[2];
+};
+
int
main()
{
using spirit_test::test;
using spirit_test::test_attr;
- using namespace boost::spirit::qi;
+ using boost::spirit::qi::symbols;
+ using boost::spirit::qi::rule;
+ using boost::spirit::qi::lazy;
+ using boost::spirit::qi::_r1;
+ using boost::phoenix::ref;
{ // basics
symbols<char, int> sym;
@@ -35,6 +54,8 @@
("Joey")
;
+ boost::mpl::true_ f = boost::mpl::bool_<boost::spirit::traits::is_parser<symbols<char, int> >::value>();
+
BOOST_TEST((test("Joel", sym)));
BOOST_TEST((test("Ruby", sym)));
BOOST_TEST((test("Tenji", sym)));
@@ -43,6 +64,20 @@
BOOST_TEST((test("Joey", sym)));
BOOST_TEST((!test("XXX", sym)));
+ // test copy
+ symbols<char, int> sym2;
+ sym2 = sym;
+ BOOST_TEST((test("Joel", sym2)));
+ BOOST_TEST((test("Ruby", sym2)));
+ BOOST_TEST((test("Tenji", sym2)));
+ BOOST_TEST((test("Tutit", sym2)));
+ BOOST_TEST((test("Kim", sym2)));
+ BOOST_TEST((test("Joey", sym2)));
+ BOOST_TEST((!test("XXX", sym2)));
+
+ // make sure it plays well with other parsers
+ BOOST_TEST((test("Joelyo", sym >> "yo")));
+
sym.remove
("Joel")
("Ruby")
@@ -90,6 +125,9 @@
BOOST_TEST((test("TUTIT", no_case[sym])));
BOOST_TEST((test("KIM", no_case[sym])));
BOOST_TEST((test("JOEY", no_case[sym])));
+
+ // make sure it plays well with other parsers
+ BOOST_TEST((test("Joelyo", no_case[sym] >> "yo")));
}
{ // attributes
@@ -121,8 +159,8 @@
}
{ // actions
- using namespace boost::phoenix;
- using boost::spirit::arg_names::_1;
+ using boost::phoenix::ref;
+ using boost::spirit::_1;
symbols<char, int> sym;
sym.add
@@ -185,5 +223,52 @@
BOOST_TEST((!test_attr("XXX", sym, i)));
}
+ { // allow std::string and other string types
+ symbols<> sym;
+
+ // const and non-const std::string
+ std::string a("abc");
+ std::string const b("def");
+ sym += a;
+ sym += b;
+ BOOST_TEST((test("abc", sym)));
+ BOOST_TEST((test("def", sym)));
+ sym = a;
+ BOOST_TEST((test("abc", sym)));
+ BOOST_TEST((!test("def", sym)));
+
+ // non-const C-style string
+ char arr[2]; arr[0] = 'a'; arr[1] = '\0';
+ sym = arr;
+ BOOST_TEST((test("a", sym)));
+ BOOST_TEST((!test("b", sym)));
+
+ // const and non-const custom string type
+ custom_string_c c('x');
+ custom_string_c const cc('y');
+ sym = c, cc;
+ BOOST_TEST((test("x", sym)));
+ BOOST_TEST((test("y", sym)));
+ BOOST_TEST((!test("z", sym)));
+ }
+
+ {
+ symbols<char, int> sym;
+ sym.add
+ ("a", 1)
+ ("b", 2)
+ ;
+
+ rule<char const*, int(symbols<char, int>&)> r;
+ r %= lazy(_r1);
+
+ int i = 0;
+ BOOST_TEST(test_attr("a", r(ref(sym)), i));
+ BOOST_TEST(i == 1);
+ BOOST_TEST(test_attr("b", r(ref(sym)), i));
+ BOOST_TEST(i == 2);
+ BOOST_TEST(!test("c", r(ref(sym))));
+ }
+
return boost::report_errors();
}
Added: trunk/libs/spirit/test/qi/terminal_ex.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/terminal_ex.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,386 @@
+/*=============================================================================
+ Copyright (c) 2008 Francois Barel
+
+ 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/detail/lightweight_test.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/spirit/include/qi_operator.hpp>
+#include <boost/spirit/include/qi_char.hpp>
+#include <boost/spirit/include/phoenix_core.hpp>
+#include <boost/spirit/include/phoenix_operator.hpp>
+
+#include <iterator>
+#include "test.hpp"
+
+
+namespace testns
+{
+
+ BOOST_SPIRIT_TERMINAL_EX( ops )
+
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Parsers
+ ///////////////////////////////////////////////////////////////////////////
+
+ template <typename T1>
+ struct ops_1_parser
+ : boost::spirit::qi::primitive_parser<ops_1_parser<T1> >
+ {
+ ops_1_parser(T1 t1)
+ : t1(t1)
+ {}
+
+ template <typename Context, typename Iterator>
+ struct attribute
+ {
+ typedef int type; // Number of parsed chars.
+ };
+
+ template <typename Iterator, typename Context
+ , typename Skipper, typename Attribute>
+ bool parse(Iterator& first, Iterator const& last
+ , Context& /*context*/, Skipper const& skipper
+ , Attribute& attr) const
+ {
+ boost::spirit::qi::skip_over(first, last, skipper);
+
+ int count = 0;
+
+ Iterator it = first;
+ typedef typename std::iterator_traits<Iterator>::value_type Char;
+ for (T1 t = 0; t < t1; t++, count++)
+ if (it == last || *it++ != Char('+'))
+ return false;
+
+ boost::spirit::qi::detail::assign_to(count, attr);
+ first = it;
+ return true;
+ }
+
+ template <typename Context>
+ boost::spirit::qi::info what(Context& /*context*/) const
+ {
+ return boost::spirit::qi::info("ops_1");
+ }
+
+ const T1 t1;
+ };
+
+ template <typename T1, typename T2>
+ struct ops_2_parser
+ : boost::spirit::qi::primitive_parser<ops_2_parser<T1, T2> >
+ {
+ ops_2_parser(T1 t1, T2 t2)
+ : t1(t1)
+ , t2(t2)
+ {}
+
+ template <typename Context, typename Iterator>
+ struct attribute
+ {
+ typedef int type; // Number of parsed chars.
+ };
+
+ template <typename Iterator, typename Context
+ , typename Skipper, typename Attribute>
+ bool parse(Iterator& first, Iterator const& last
+ , Context& /*context*/, Skipper const& skipper
+ , Attribute& attr) const
+ {
+ boost::spirit::qi::skip_over(first, last, skipper);
+
+ int count = 0;
+
+ Iterator it = first;
+ typedef typename std::iterator_traits<Iterator>::value_type Char;
+ for (T1 t = 0; t < t1; t++, count++)
+ if (it == last || *it++ != Char('+'))
+ return false;
+ for (T2 t = 0; t < t2; t++, count++)
+ if (it == last || *it++ != Char('-'))
+ return false;
+
+ boost::spirit::qi::detail::assign_to(count, attr);
+ first = it;
+ return true;
+ }
+
+ template <typename Context>
+ boost::spirit::qi::info what(Context& /*context*/) const
+ {
+ return boost::spirit::qi::info("ops_2");
+ }
+
+ const T1 t1;
+ const T2 t2;
+ };
+
+ template <typename T1, typename T2, typename T3>
+ struct ops_3_parser
+ : boost::spirit::qi::primitive_parser<ops_3_parser<T1, T2, T3> >
+ {
+ ops_3_parser(T1 t1, T2 t2, T3 t3)
+ : t1(t1)
+ , t2(t2)
+ , t3(t3)
+ {}
+
+ template <typename Context, typename Iterator>
+ struct attribute
+ {
+ typedef int type; // Number of parsed chars.
+ };
+
+ template <typename Iterator, typename Context
+ , typename Skipper, typename Attribute>
+ bool parse(Iterator& first, Iterator const& last
+ , Context& /*context*/, Skipper const& skipper
+ , Attribute& attr) const
+ {
+ boost::spirit::qi::skip_over(first, last, skipper);
+
+ int count = 0;
+
+ Iterator it = first;
+ typedef typename std::iterator_traits<Iterator>::value_type Char;
+ for (T1 t = 0; t < t1; t++, count++)
+ if (it == last || *it++ != Char('+'))
+ return false;
+ for (T2 t = 0; t < t2; t++, count++)
+ if (it == last || *it++ != Char('-'))
+ return false;
+ for (T3 t = 0; t < t3; t++, count++)
+ if (it == last || *it++ != Char('*'))
+ return false;
+
+ boost::spirit::qi::detail::assign_to(count, attr);
+ first = it;
+ return true;
+ }
+
+ template <typename Context>
+ boost::spirit::qi::info what(Context& /*context*/) const
+ {
+ return boost::spirit::qi::info("ops_3");
+ }
+
+ const T1 t1;
+ const T2 t2;
+ const T3 t3;
+ };
+
+}
+
+
+namespace boost { namespace spirit
+{
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Enablers
+ ///////////////////////////////////////////////////////////////////////////
+
+ template <typename T1>
+ struct use_terminal<qi::domain
+ , terminal_ex<testns::tag::ops, fusion::vector1<T1> > >
+ : mpl::true_ {};
+
+ template <typename T1, typename T2>
+ struct use_terminal<qi::domain
+ , terminal_ex<testns::tag::ops, fusion::vector2<T1, T2> > >
+ : mpl::true_ {};
+
+ template <typename T1, typename T2, typename T3>
+ struct use_terminal<qi::domain
+ , terminal_ex<testns::tag::ops, fusion::vector3<T1, T2, T3> > >
+ : mpl::true_ {};
+
+ template <>
+ struct use_lazy_terminal<qi::domain, testns::tag::ops, 1>
+ : mpl::true_ {};
+
+ template <>
+ struct use_lazy_terminal<qi::domain, testns::tag::ops, 2>
+ : mpl::true_ {};
+
+ template <>
+ struct use_lazy_terminal<qi::domain, testns::tag::ops, 3>
+ : mpl::true_ {};
+
+}}
+
+namespace boost { namespace spirit { namespace qi
+{
+
+ ///////////////////////////////////////////////////////////////////////////
+ // Parser generators: make_xxx function (objects)
+ ///////////////////////////////////////////////////////////////////////////
+
+ template <typename Modifiers, typename T1>
+ struct make_primitive<
+ terminal_ex<testns::tag::ops, fusion::vector1<T1> >
+ , Modifiers>
+ {
+ typedef testns::ops_1_parser<T1> result_type;
+ template <typename Terminal>
+ result_type operator()(const Terminal& term, unused_type) const
+ {
+ return result_type(
+ fusion::at_c<0>(term.args)
+ );
+ }
+ };
+
+ template <typename Modifiers, typename T1, typename T2>
+ struct make_primitive<
+ terminal_ex<testns::tag::ops, fusion::vector2<T1, T2> >
+ , Modifiers>
+ {
+ typedef testns::ops_2_parser<T1, T2> result_type;
+ template <typename Terminal>
+ result_type operator()(const Terminal& term, unused_type) const
+ {
+ return result_type(
+ fusion::at_c<0>(term.args)
+ , fusion::at_c<1>(term.args)
+ );
+ }
+ };
+
+ template <typename Modifiers, typename T1, typename T2, typename T3>
+ struct make_primitive<
+ terminal_ex<testns::tag::ops, fusion::vector3<T1, T2, T3> >
+ , Modifiers>
+ {
+ typedef testns::ops_3_parser<T1, T2, T3> result_type;
+ template <typename Terminal>
+ result_type operator()(const Terminal& term, unused_type) const
+ {
+ return result_type(
+ fusion::at_c<0>(term.args)
+ , fusion::at_c<1>(term.args)
+ , fusion::at_c<2>(term.args)
+ );
+ }
+ };
+
+}}}
+
+
+namespace testns
+{
+ template <typename T1, typename T>
+ void check_type_1(const T& t)
+ {
+ namespace fusion = boost::fusion;
+ BOOST_STATIC_ASSERT(( boost::is_same<T
+ , typename boost::spirit::terminal<testns::tag::ops>::result<T1>::type >::value ));
+ }
+
+ template <typename T1, typename T2, typename T>
+ void check_type_2(const T& t)
+ {
+ namespace fusion = boost::fusion;
+ BOOST_STATIC_ASSERT(( boost::is_same<T
+ , typename boost::spirit::terminal<testns::tag::ops>::result<T1, T2>::type >::value ));
+ }
+
+ template <typename T1, typename T2, typename T3, typename T>
+ void check_type_3(const T& t)
+ {
+ namespace fusion = boost::fusion;
+ BOOST_STATIC_ASSERT(( boost::is_same<T
+ , typename boost::spirit::terminal<testns::tag::ops>::result<T1, T2, T3>::type >::value ));
+ }
+}
+
+
+int
+main()
+{
+ using spirit_test::test_attr;
+ using spirit_test::test;
+
+ using boost::phoenix::val;
+ using boost::phoenix::actor;
+ using boost::phoenix::value;
+
+ using testns::ops;
+ using testns::check_type_1;
+ using testns::check_type_2;
+ using testns::check_type_3;
+
+ { // immediate args
+ int c = 0;
+#define IP1 ops(2)
+ check_type_1<int>(IP1);
+ BOOST_TEST(test_attr("++/", IP1 >> '/', c) && c == 2);
+
+ c = 0;
+#define IP2 ops(2, 3)
+ check_type_2<int, int>(IP2);
+ BOOST_TEST(test_attr("++---/", IP2 >> '/', c) && c == 5);
+
+ c = 0;
+#define IP3 ops(2, 3, 4)
+ check_type_3<int, int, int>(IP3);
+ BOOST_TEST(!test("++---***/", IP3 >> '/'));
+#define IP4 ops(2, 3, 4)
+ check_type_3<int, int, int>(IP4);
+ BOOST_TEST(test_attr("++---****/", IP4 >> '/', c) && c == 9);
+ }
+
+ { // all lazy args
+ int c = 0;
+#define LP1 ops(val(1))
+ check_type_1<actor<value<int> > >(LP1);
+ BOOST_TEST(test_attr("+/", LP1 >> '/', c) && c == 1);
+
+ c = 0;
+#define LP2 ops(val(1), val(4))
+ check_type_2<actor<value<int> >, actor<value<int> > >(LP2);
+ BOOST_TEST(test_attr("+----/", LP2 >> '/', c) && c == 5);
+
+ c = 0;
+#define LP3 ops(val((char)2), val(3.), val(4))
+ check_type_3<actor<value<char> >, actor<value<double> >, actor<value<int> > >(LP3);
+ BOOST_TEST(!test("++---***/", LP3 >> '/'));
+#define LP4 ops(val(1), val(2), val(3))
+ check_type_3<actor<value<int> >, actor<value<int> >, actor<value<int> > >(LP4);
+ BOOST_TEST(test_attr("+--***/", LP4 >> '/', c) && c == 6);
+ }
+
+ { // mixed immediate and lazy args
+ namespace fusion = boost::fusion;
+ namespace phx = boost::phoenix;
+
+ int c = 0;
+#define MP1 ops(val(3), 2)
+ check_type_2<actor<value<int> >, int>(MP1);
+ BOOST_TEST(test_attr("+++--/", MP1 >> '/', c) && c == 5);
+
+ c = 0;
+#define MP2 ops(4, val(1))
+ check_type_2<int, actor<value<int> > >(MP2);
+ BOOST_TEST(test_attr("++++-/", MP2 >> '/', c) && c == 5);
+
+ c = 0;
+#define MP3 ops(2, val(2), val(2))
+ check_type_3<int, actor<value<int> >, actor<value<int> > >(MP3);
+ BOOST_TEST(!test("++-**/", MP3 >> '/'));
+#define MP4 ops(2, val(2), 2)
+ check_type_3<int, actor<value<int> >, int>(MP4);
+ BOOST_TEST(test_attr("++--**/", MP4 >> '/', c) && c == 6);
+
+ c = 0;
+#define MP5 ops(val(5) - val(3), 2, val(2))
+ check_type_3<actor<phx::composite<phx::minus_eval, fusion::vector<value<int>, value<int> > > >, int, actor<value<int> > >(MP5);
+ BOOST_TEST(test_attr("++--**/", ops(val(5) - val(3), 2, val(2)) >> '/', c) && c == 6);
+ }
+
+ return boost::report_errors();
+}
+
Modified: trunk/libs/spirit/test/qi/test.hpp
==============================================================================
--- trunk/libs/spirit/test/qi/test.hpp (original)
+++ trunk/libs/spirit/test/qi/test.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,14 +1,17 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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_TEST_FEB_01_2007_0605PM)
-#define BOOST_SPIRIT_TEST_FEB_01_2007_0605PM
+#if !defined(BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM)
+#define BOOST_SPIRIT_TEST_FEBRUARY_01_2007_0605PM
#include <boost/spirit/include/qi_parse.hpp>
#include <boost/spirit/include/qi_what.hpp>
+#include <boost/variant/apply_visitor.hpp>
+#include <boost/foreach.hpp>
+#include <iostream>
namespace spirit_test
{
@@ -67,9 +70,34 @@
Char const* last = in;
while (*last)
last++;
- return boost::spirit::qi::phrase_parse(in, last, p, attr, s)
+ return boost::spirit::qi::phrase_parse(in, last, p, s, attr)
&& (!full_match || (in == last));
}
+
+ struct printer
+ {
+ typedef boost::spirit::utf8_string string;
+
+ void element(string const& tag, string const& value, int depth) const
+ {
+ for (int i = 0; i < (depth*4); ++i) // indent to depth
+ std::cout << ' ';
+
+ std::cout << "tag: " << tag;
+ if (value != "")
+ std::cout << ", value: " << value;
+ std::cout << std::endl;
+ }
+ };
+
+ void print_info(boost::spirit::info const& what)
+ {
+ using boost::spirit::basic_info_walker;
+
+ printer pr;
+ basic_info_walker<printer> walker(pr, what.tag, 0);
+ boost::apply_visitor(walker, what.value);
+ }
}
#endif
Added: trunk/libs/spirit/test/qi/test_attr.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/test_attr.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,123 @@
+// Copyright (c) 2001-2009 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_PP_IS_ITERATING)
+
+#if !defined(BOOST_SPIRIT_QI_TEST_ATTR_APR_23_2009_0605PM)
+#define BOOST_SPIRIT_QI_TEST_ATTR_APR_23_2009_0605PM
+
+#include <cstring>
+#include <string>
+#include <iterator>
+#include <iostream>
+#include <typeinfo>
+
+#include <boost/spirit/include/qi_parse.hpp>
+#include <boost/spirit/include/qi_what.hpp>
+
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/iterate.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+
+#define BOOST_PP_FILENAME_1 "qi/test_attr.hpp"
+#define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
+#include BOOST_PP_ITERATE()
+
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Preprocessor vertical repetition code
+//
+///////////////////////////////////////////////////////////////////////////////
+#else // defined(BOOST_PP_IS_ITERATING)
+
+#define N BOOST_PP_ITERATION()
+#define DEFINE_ATTRIBUTE(z, n, _) \
+ BOOST_PP_CAT(A, n) BOOST_PP_CAT(attr, n) = BOOST_PP_CAT(A, n)();
+#define COMPARE_ATTRIBUTE(z, n, _) \
+ BOOST_PP_CAT(attr, n) == BOOST_PP_CAT(val, n) &&
+
+namespace spirit_test
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Parser
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test(Char const *in, Parser const& p
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
+ {
+ namespace qi = boost::spirit::qi;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all parsers have it:
+ qi::what(p);
+
+ Char const* last = in;
+ while (*last)
+ last++;
+
+ BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
+ bool result = qi::parse(in, last, p, BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Parser, typename Skipper
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_skipped(Char const *in, Parser const& p
+ , Skipper const& skipper, BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
+ {
+ namespace qi = boost::spirit::qi;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all parsers have it:
+ qi::what(p);
+
+ Char const* last = in;
+ while (*last)
+ last++;
+
+ BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
+ bool result = qi::phrase_parse(in, last, p, skipper
+ , BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Parser, typename Skipper
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_postskipped(Char const *in, Parser const& p
+ , Skipper const& skipper
+ , BOOST_SCOPED_ENUM(boost::spirit::qi::skip_flag) post_skip
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
+ {
+ namespace qi = boost::spirit::qi;
+
+ // we don't care about the result of the "what" function.
+ // we only care that all parsers have it:
+ qi::what(p);
+
+ Char const* last = in;
+ while (*last)
+ last++;
+
+ BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
+ bool result = qi::phrase_parse(in, last, p, skipper, post_skip
+ , BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return result && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) in == last;
+ }
+
+} // namespace spirit_test
+
+#undef COMPARE_ATTRIBUTE
+#undef DEFINE_ATTRIBUTE
+#undef N
+
+#endif
Added: trunk/libs/spirit/test/qi/test_manip_attr.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/test_manip_attr.hpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,101 @@
+// Copyright (c) 2001-2009 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_PP_IS_ITERATING)
+
+#if !defined(BOOST_SPIRIT_QI_TEST_MANIP_ATTR_APR_23_2009_0605PM)
+#define BOOST_SPIRIT_QI_TEST_MANIP_ATTR_APR_23_2009_0605PM
+
+#include <cstring>
+#include <string>
+#include <iterator>
+#include <iostream>
+#include <typeinfo>
+
+#include <boost/spirit/include/qi_parse.hpp>
+#include <boost/spirit/include/qi_stream.hpp>
+
+#include <boost/preprocessor/cat.hpp>
+#include <boost/preprocessor/iterate.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+
+#define BOOST_PP_FILENAME_1 "qi/test_manip_attr.hpp"
+#define BOOST_PP_ITERATION_LIMITS (1, SPIRIT_ARGUMENTS_LIMIT)
+#include BOOST_PP_ITERATE()
+
+#endif
+
+///////////////////////////////////////////////////////////////////////////////
+//
+// Preprocessor vertical repetition code
+//
+///////////////////////////////////////////////////////////////////////////////
+#else // defined(BOOST_PP_IS_ITERATING)
+
+#define N BOOST_PP_ITERATION()
+#define DEFINE_ATTRIBUTE(z, n, _) \
+ BOOST_PP_CAT(A, n) BOOST_PP_CAT(attr, n) = BOOST_PP_CAT(A, n)();
+#define COMPARE_ATTRIBUTE(z, n, _) \
+ BOOST_PP_CAT(attr, n) == BOOST_PP_CAT(val, n) &&
+
+namespace spirit_test
+{
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Parser
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test(Char const *in, Parser const& p
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
+ {
+ namespace qi = boost::spirit::qi;
+
+ std::basic_stringstream<Char> strm(in);
+ BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
+ strm >> qi::match(p, BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Parser, typename Skipper
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_skipped(Char const *in, Parser const& p
+ , Skipper const& skipper, BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
+ {
+ namespace qi = boost::spirit::qi;
+
+ std::basic_stringstream<Char> strm(in);
+ BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
+ strm >> qi::phrase_match(p, skipper, BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
+ }
+
+ ///////////////////////////////////////////////////////////////////////////
+ template <typename Char, typename Parser, typename Skipper
+ , BOOST_PP_ENUM_PARAMS(N, typename A)>
+ inline bool test_postskipped(Char const *in, Parser const& p
+ , Skipper const& skipper
+ , BOOST_SCOPED_ENUM(boost::spirit::qi::skip_flag) post_skip
+ , BOOST_PP_ENUM_BINARY_PARAMS(N, A, val))
+ {
+ namespace qi = boost::spirit::qi;
+
+ std::basic_stringstream<Char> strm(in);
+ BOOST_PP_REPEAT(N, DEFINE_ATTRIBUTE, _);
+ strm >> qi::phrase_match(p, skipper, post_skip
+ , BOOST_PP_ENUM_PARAMS(N, attr));
+
+ return strm.eof() && BOOST_PP_REPEAT(N, COMPARE_ATTRIBUTE, _) true;
+ }
+
+} // namespace spirit_test
+
+#undef COMPARE_ATTRIBUTE
+#undef DEFINE_ATTRIBUTE
+#undef N
+
+#endif
Modified: trunk/libs/spirit/test/qi/tst.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/tst.cpp (original)
+++ trunk/libs/spirit/test/qi/tst.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,5 +1,5 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -341,10 +341,10 @@
}
}
-int
-main()
+int main()
{
- using namespace boost::spirit::qi;
+ using boost::spirit::qi::tst;
+ using boost::spirit::qi::tst_map;
tests<tst<char, int>, tst<wchar_t, int> >();
tests<tst_map<char, int>, tst_map<wchar_t, int> >();
Modified: trunk/libs/spirit/test/qi/uint.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/uint.cpp (original)
+++ trunk/libs/spirit/test/qi/uint.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
@@ -1,6 +1,6 @@
/*=============================================================================
- Copyright (c) 2001-2007 Joel de Guzman
- Copyright (c) 2001-2007 Hartmut Kaiser
+ Copyright (c) 2001-2009 Joel de Guzman
+ Copyright (c) 2001-2009 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)
@@ -15,6 +15,7 @@
#include <boost/spirit/include/phoenix_operator.hpp>
#include "test.hpp"
+#include <cstring>
///////////////////////////////////////////////////////////////////////////////
//
@@ -40,32 +41,32 @@
int
main()
{
- using namespace spirit_test;
-
+ using spirit_test::test;
+ using spirit_test::test_attr;
///////////////////////////////////////////////////////////////////////////
// unsigned tests
///////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::uint;
+ using boost::spirit::qi::uint_;
unsigned u;
- BOOST_TEST(test("123456", uint));
- BOOST_TEST(test_attr("123456", uint, u));
+ BOOST_TEST(test("123456", uint_));
+ BOOST_TEST(test_attr("123456", uint_, u));
BOOST_TEST(u == 123456);
- BOOST_TEST(test(max_unsigned, uint));
- BOOST_TEST(test_attr(max_unsigned, uint, u));
+ BOOST_TEST(test(max_unsigned, uint_));
+ BOOST_TEST(test_attr(max_unsigned, uint_, u));
BOOST_TEST(u == UINT_MAX);
- BOOST_TEST(!test(unsigned_overflow, uint));
- BOOST_TEST(!test_attr(unsigned_overflow, uint, u));
+ BOOST_TEST(!test(unsigned_overflow, uint_));
+ BOOST_TEST(!test_attr(unsigned_overflow, uint_, u));
}
///////////////////////////////////////////////////////////////////////////
// binary tests
///////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::bin;
+ using boost::spirit::qi::bin;
unsigned u;
BOOST_TEST(test("11111110", bin));
@@ -84,7 +85,7 @@
// octal tests
///////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::oct;
+ using boost::spirit::qi::oct;
unsigned u;
BOOST_TEST(test("12545674515", oct));
@@ -103,7 +104,7 @@
// hex tests
///////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::hex;
+ using boost::spirit::qi::hex;
unsigned u;
BOOST_TEST(test("95BC8DF", hex));
@@ -127,29 +128,41 @@
///////////////////////////////////////////////////////////////////////////
{
unsigned u;
- using boost::spirit::qi::uint_spec;
+ using boost::spirit::qi::uint_parser;
- uint_spec<unsigned, 10, 1, 3> uint3;
+ uint_parser<unsigned, 10, 1, 3> uint3;
BOOST_TEST(test("123456", uint3, false));
BOOST_TEST(test_attr("123456", uint3, u, false));
BOOST_TEST(u == 123);
- uint_spec<unsigned, 10, 2, 4> uint4;
+ uint_parser<unsigned, 10, 2, 4> uint4;
BOOST_TEST(test("123456", uint4, false));
BOOST_TEST(test_attr("123456", uint4, u, false));
BOOST_TEST(u == 1234);
+ char const * first = "0000000";
+ char const * last = first + std::strlen(first);
+ uint_parser<unsigned, 10, 4, 4> uint_exact4;
+ BOOST_TEST(boost::spirit::qi::parse(first, last, uint_exact4, u)
+ && first != last && (last-first == 3) && u == 0);
+
+ first = "0001400";
+ last = first + std::strlen(first);
+ BOOST_TEST(boost::spirit::qi::parse(first, last, uint_exact4, u)
+ && first != last && (last-first == 3) && u == 1);
+
BOOST_TEST(!test("1", uint4));
BOOST_TEST(!test_attr("1", uint4, u));
+ BOOST_TEST(test_attr("014567", uint4, u, false) && u == 145);
}
///////////////////////////////////////////////////////////////////////////
- // uint_spec<unused_type> tests
+ // uint_parser<unused_type> tests
///////////////////////////////////////////////////////////////////////////
{
- using boost::spirit::qi::uint_spec;
- using boost::spirit::unused_type;
- uint_spec<unused_type> any_int;
+ using boost::spirit::qi::uint_parser;
+ using boost::spirit::qi::unused_type;
+ uint_parser<unused_type> any_int;
BOOST_TEST(test("123456", any_int));
BOOST_TEST(test("1234567890123456789", any_int));
@@ -159,15 +172,15 @@
// action tests
///////////////////////////////////////////////////////////////////////////
{
- using namespace boost::phoenix;
- using boost::spirit::arg_names::_1;
+ using boost::phoenix::ref;
+ using boost::spirit::qi::_1;
+ using boost::spirit::qi::uint_;
using boost::spirit::ascii::space;
- using boost::spirit::uint;
int n;
- BOOST_TEST(test("123", uint[ref(n) = _1]));
+ BOOST_TEST(test("123", uint_[ref(n) = _1]));
BOOST_TEST(n == 123);
- BOOST_TEST(test(" 456", uint[ref(n) = _1], space));
+ BOOST_TEST(test(" 456", uint_[ref(n) = _1], space));
BOOST_TEST(n == 456);
}
Deleted: trunk/libs/spirit/test/support/hold_any.cpp
==============================================================================
--- trunk/libs/spirit/test/support/hold_any.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,201 +0,0 @@
-// Copyright (c) 2007-2009 Hartmut Kaiser
-// Copyright (c) Christopher Diggins 2005
-//
-// 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)
-
-// #define BOOST_SPIRIT_ANY_IMPLICIT_CASTING
-
-#include <cassert>
-#include <stdexcept>
-#include <typeinfo>
-#include <iostream>
-#include <vector>
-#include <complex>
-#include <string>
-
-#include <boost/detail/lightweight_test.hpp>
-#include <boost/spirit/home/support/detail/hold_any.hpp>
-
-using namespace std;
-using namespace boost::spirit;
-
-///////////////////////////////////////////////////////////////////////////////
-bool output_any (hold_any const& a, std::string expected)
-{
- std::ostringstream o;
- if (a.type() == typeid(int))
- {
- o << any_cast<int>(a);
- }
- else if (a.type() == typeid(char))
- {
- o << any_cast<char>(a);
- }
- else if (a.type() == typeid(double))
- {
- o << any_cast<double>(a);
- }
- else if (a.type() == typeid(std::complex<int>))
- {
- o << any_cast<std::complex<int> >(a);
- }
- else
- {
- o << "unexpected type: " << a.type().name();
- return false;
- }
- return o.str() == expected;
-}
-
-template <typename T>
-bool output_any_direct (T const& v, std::string expected)
-{
- std::ostringstream o;
- o << v;
- return o.str() == expected;
-}
-
-void simple_any_test()
-{
- BOOST_TEST(output_any(42, "42"));
- BOOST_TEST(output_any('q', "q"));
- BOOST_TEST(output_any(3.14, "3.14"));
- BOOST_TEST(output_any(std::complex<int>(1, 2), "(1,2)"));
-
- int n = 42; BOOST_TEST(output_any(n, "42"));
- char c = 'q'; BOOST_TEST(output_any(c, "q"));
- double d = 3.14; BOOST_TEST(output_any(d, "3.14"));
- std::complex<int> x(1, 2); BOOST_TEST(output_any(x, "(1,2)"));
-
- hold_any a;
- BOOST_TEST(output_any(a = n, "42"));
- BOOST_TEST(output_any(a = c, "q"));
- BOOST_TEST(output_any(a = d, "3.14"));
- BOOST_TEST(output_any(a = x, "(1,2)"));
- BOOST_TEST(output_any(a = 13, "13"));
-
-#ifdef BOOST_SPIRIT_ANY_IMPLICIT_CASTING
- BOOST_TEST(output_any_direct(n = hold_any(42), "42"));
- BOOST_TEST(output_any_direct(c = hold_any('q'), "q"));
- BOOST_TEST(output_any_direct(d = hold_any(3.14), "3.14"));
- BOOST_TEST(output_any_direct(x = std::complex<int>(hold_any(std::complex<int>(1, 2))), "(1,2)"));
-#endif
-
- BOOST_TEST(output_any_direct(hold_any(42), "42"));
- BOOST_TEST(output_any_direct(hold_any('q'), "q"));
- BOOST_TEST(output_any_direct(hold_any(3.14), "3.14"));
- BOOST_TEST(output_any_direct(hold_any(std::complex<int>(1, 2)), "(1,2)"));
-
- BOOST_TEST(!a.empty());
- a = 0;
- BOOST_TEST(!a.empty());
- a.reset();
- BOOST_TEST(a.empty());
-
- try {
- any_cast<int>(a);
- BOOST_TEST(false);
- }
- catch (boost::spirit::bad_any_cast const&) {
- BOOST_TEST(true);
- }
- catch (...) {
- BOOST_TEST(false);
- }
-}
-
-void test2(hold_any const& x, hold_any const& y)
-{
- BOOST_TEST(x.type() != y.type());
- BOOST_TEST(x.type().name() != y.type().name());
-}
-
-///////////////////////////////////////////////////////////////////////////////
-int state;
-
-///////////////////////////////////////////////////////////////////////////////
-struct small_object
-{
- small_object() {}
- small_object(small_object const&) { state = 1; }
- ~small_object() { state = 2; }
-};
-
-inline std::istream&
-operator>> (std::istream& i, small_object&)
-{
- return i;
-}
-
-inline std::ostream&
-operator<< (std::ostream& o, small_object const&)
-{
- return o;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-struct large_object
-{
- large_object() {}
- large_object(large_object const&) { state = 3; }
- ~large_object() { state = 4; }
-
- int data0;
- int data1;
- int data2;
- int data3;
-};
-
-inline std::istream&
-operator>> (std::istream& i, large_object&)
-{
- return i;
-}
-
-inline std::ostream&
-operator<< (std::ostream& o, large_object const&)
-{
- return o;
-}
-
-void constructor_test()
-{
- small_object lfb;
- large_object bfb;
- hold_any a;
- state = 0;
-
- a = lfb; BOOST_TEST(1 == state); state = 0;
- a = 42; BOOST_TEST(2 == state); state = 0;
- a = bfb; BOOST_TEST(3 == state); state = 0;
- a = 42; BOOST_TEST(4 == state); state = 0;
-
- // test assignment of large objects
- a = bfb;
- a = bfb;
-}
-
-int main()
-{
- test2(std::string("10"), std::complex<double>(20));
-
- constructor_test();
- simple_any_test();
-
- hold_any non_const(10);
- BOOST_TEST(any_cast<int>(non_const) == 10);
- *any_cast<int>(&non_const) = 15;
- BOOST_TEST(any_cast<int>(non_const) == 15);
-
- hold_any const const_(10);
- BOOST_TEST(any_cast<int>(const_) == *any_cast<int>(&const_));
-
- hold_any a = 42, b = 'q';
- swap(a, b);
- BOOST_TEST(any_cast<int>(b) == 42);
- BOOST_TEST(any_cast<char>(a) == 'q');
-
- return boost::report_errors();
-}
-
Deleted: trunk/libs/spirit/test/support/multi_pass.cpp
==============================================================================
--- trunk/libs/spirit/test/support/multi_pass.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,770 +0,0 @@
-/*=============================================================================
- Copyright (c) 2001-2003 Daniel Nuffer
- 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)
-=============================================================================*/
-
-#include <boost/spirit/support/iterators/detail/buf_id_check_policy.hpp>
-#include <boost/spirit/support/iterators/detail/ref_counted_policy.hpp>
-#include <boost/spirit/support/iterators/detail/functor_input_policy.hpp>
-#include <boost/spirit/include/support_multi_pass.hpp>
-#include <boost/spirit/support/iterators/look_ahead.hpp>
-
-#include <boost/scoped_ptr.hpp>
-#include <iterator>
-#include <string>
-#include <boost/detail/lightweight_test.hpp>
-#include "detail/sstream.hpp"
-
-using namespace std;
-using namespace boost::spirit;
-
-sstream_t res;
-
-typedef boost::spirit::multi_pass<istream_iterator<char> > default_multi_pass_t;
-
-typedef look_ahead<istream_iterator<char>, 6> fixed_multi_pass_t;
-
-typedef multi_pass<
- istream_iterator<char>,
- multi_pass_policies::input_iterator,
- multi_pass_policies::first_owner,
- multi_pass_policies::buf_id_check,
- multi_pass_policies::std_deque
-> first_owner_multi_pass_t;
-
-
-// a functor to test out the functor_multi_pass
-class my_functor
-{
- public:
- typedef char result_type;
- my_functor()
- : c('A')
- {}
-
- char operator()()
- {
- if (c == 'M')
- return eof;
- else
- return c++;
- }
-
- static result_type eof;
- private:
- char c;
-};
-
-my_functor::result_type my_functor::eof = '\0';
-
-typedef multi_pass<
- my_functor,
- multi_pass_policies::functor_input,
- multi_pass_policies::first_owner,
- multi_pass_policies::no_check,
- multi_pass_policies::std_deque
-> functor_multi_pass_t;
-
-void test_default_multi_pass()
-{
- res << "-*= test_default_multi_pass =*-\n";
- istream_iterator<char> end;
- boost::scoped_ptr<default_multi_pass_t> mpend(new default_multi_pass_t(end));
-
- {
- sstream_t ss;
- ss << "test string";
-
- istream_iterator<char> a(ss);
- boost::scoped_ptr<default_multi_pass_t> mp1(new default_multi_pass_t(a));
-
- while (*mp1 != *mpend)
- {
- res << *((*mp1)++);
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<default_multi_pass_t> mp2(new default_multi_pass_t(b));
- boost::scoped_ptr<default_multi_pass_t> mp3(new default_multi_pass_t(b));
- *mp3 = *mp2;
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp3.reset();
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<default_multi_pass_t> mp1(new default_multi_pass_t(a));
- boost::scoped_ptr<default_multi_pass_t> mp2(new default_multi_pass_t(*mp1));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp1;
- ++*mp1;
- }
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- while (*mp1 != *mpend)
- {
- res << **mp1;
- ++*mp1;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<default_multi_pass_t> mp2(new default_multi_pass_t(b));
- boost::scoped_ptr<default_multi_pass_t> mp3(new default_multi_pass_t(b));
- *mp3 = *mp2;
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp3.reset();
- ++*mp2;
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<default_multi_pass_t> mp1(new default_multi_pass_t(a));
- boost::scoped_ptr<default_multi_pass_t> mp2(new default_multi_pass_t(*mp1));
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- for (int i = 0; i < 4; ++i)
- {
- res << **mp1;
- ++*mp1;
- }
-
- BOOST_TEST(*mp1 != *mp2);
- BOOST_TEST(*mp1 > *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp2 < *mp1);
- BOOST_TEST(*mp2 <= *mp1);
- while (*mp2 != *mp1)
- {
- res << **mp2;
- ++*mp2;
- }
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- while (*mp1 != *mpend)
- {
- res << **mp1;
- ++*mp1;
- }
-
- BOOST_TEST(*mp1 != *mp2);
- BOOST_TEST(*mp1 > *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp2 < *mp1);
- BOOST_TEST(*mp2 <= *mp1);
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<default_multi_pass_t> mp1(new default_multi_pass_t(a));
- boost::scoped_ptr<default_multi_pass_t> mp2(new default_multi_pass_t(a));
- BOOST_TEST(*mp1 != *mp2);
- ++*mp1;
- BOOST_TEST(*mp1 != *mp2);
-
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<default_multi_pass_t> mp2(new default_multi_pass_t(b));
- boost::scoped_ptr<default_multi_pass_t> mp3(new default_multi_pass_t(b));
- *mp3 = *mp2;
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp2->clear_queue();
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- try
- {
- res << **mp3; // this should throw illegal_backtracking
- BOOST_TEST(0);
- }
- catch (const boost::spirit::multi_pass_policies::illegal_backtracking& /*e*/)
- {
- }
- res << endl;
- }
-
-
-}
-
-void test_fixed_multi_pass()
-{
- res << "-*= test_fixed_multi_pass =*-\n";
- istream_iterator<char> end;
- boost::scoped_ptr<fixed_multi_pass_t> mpend(new fixed_multi_pass_t(end));
-
- {
- sstream_t ss;
- ss << "test string";
-
- istream_iterator<char> a(ss);
- boost::scoped_ptr<fixed_multi_pass_t> mp1(new fixed_multi_pass_t(a));
-
- while (*mp1 != *mpend)
- {
- res << *((*mp1)++);
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<fixed_multi_pass_t> mp2(new fixed_multi_pass_t(b));
- boost::scoped_ptr<fixed_multi_pass_t> mp3(new fixed_multi_pass_t(*mp2));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp3.reset();
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<fixed_multi_pass_t> mp1(new fixed_multi_pass_t(a));
- boost::scoped_ptr<fixed_multi_pass_t> mp2(new fixed_multi_pass_t(*mp1));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp1;
- ++*mp1;
- }
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- while (*mp1 != *mpend)
- {
- res << **mp1;
- ++*mp1;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<fixed_multi_pass_t> mp2(new fixed_multi_pass_t(b));
- boost::scoped_ptr<fixed_multi_pass_t> mp3(new fixed_multi_pass_t(*mp2));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp3.reset();
- ++*mp2;
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<fixed_multi_pass_t> mp1(new fixed_multi_pass_t(a));
- boost::scoped_ptr<fixed_multi_pass_t> mp2(new fixed_multi_pass_t(*mp1));
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- for (int i = 0; i < 4; ++i)
- {
- res << **mp1;
- ++*mp1;
- }
-
- BOOST_TEST(*mp1 != *mp2);
- BOOST_TEST(*mp1 > *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp2 < *mp1);
- BOOST_TEST(*mp2 <= *mp1);
- while (*mp2 != *mp1)
- {
- res << **mp2;
- ++*mp2;
- }
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- while (*mp1 != *mpend)
- {
- res << **mp1;
- ++*mp1;
- }
-
- BOOST_TEST(*mp1 != *mp2);
- BOOST_TEST(*mp1 > *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp2 < *mp1);
- BOOST_TEST(*mp2 <= *mp1);
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<fixed_multi_pass_t> mp1(new fixed_multi_pass_t(a));
- boost::scoped_ptr<fixed_multi_pass_t> mp2(new fixed_multi_pass_t(a));
- BOOST_TEST(*mp1 != *mp2);
- ++*mp1;
- BOOST_TEST(*mp1 != *mp2);
-
- }
-
-}
-
-void test_first_owner_multi_pass()
-{
- res << "-*= test_first_owner_multi_pass =*-\n";
- istream_iterator<char> end;
- boost::scoped_ptr<first_owner_multi_pass_t> mpend(new first_owner_multi_pass_t(end));
-
- {
- sstream_t ss;
- ss << "test string";
-
- istream_iterator<char> a(ss);
- boost::scoped_ptr<first_owner_multi_pass_t> mp1(new first_owner_multi_pass_t(a));
-
- while (*mp1 != *mpend)
- {
- res << *((*mp1)++);
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<first_owner_multi_pass_t> mp2(new first_owner_multi_pass_t(b));
- boost::scoped_ptr<first_owner_multi_pass_t> mp3(new first_owner_multi_pass_t(*mp2));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp3.reset();
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<first_owner_multi_pass_t> mp1(new first_owner_multi_pass_t(a));
- boost::scoped_ptr<first_owner_multi_pass_t> mp2(new first_owner_multi_pass_t(*mp1));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp1;
- ++*mp1;
- }
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- while (*mp1 != *mpend)
- {
- res << **mp1;
- ++*mp1;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<first_owner_multi_pass_t> mp2(new first_owner_multi_pass_t(b));
- boost::scoped_ptr<first_owner_multi_pass_t> mp3(new first_owner_multi_pass_t(*mp2));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp3.reset();
- ++*mp2;
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<first_owner_multi_pass_t> mp1(new first_owner_multi_pass_t(a));
- boost::scoped_ptr<first_owner_multi_pass_t> mp2(new first_owner_multi_pass_t(*mp1));
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- for (int i = 0; i < 4; ++i)
- {
- res << **mp1;
- ++*mp1;
- }
-
- BOOST_TEST(*mp1 != *mp2);
- BOOST_TEST(*mp1 > *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp2 < *mp1);
- BOOST_TEST(*mp2 <= *mp1);
- while (*mp2 != *mp1)
- {
- res << **mp2;
- ++*mp2;
- }
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- while (*mp1 != *mpend)
- {
- res << **mp1;
- ++*mp1;
- }
-
- BOOST_TEST(*mp1 != *mp2);
- BOOST_TEST(*mp1 > *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp2 < *mp1);
- BOOST_TEST(*mp2 <= *mp1);
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- BOOST_TEST(*mp1 == *mp2);
- BOOST_TEST(*mp1 >= *mp2);
- BOOST_TEST(*mp1 <= *mp2);
- res << endl;
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> a(ss);
- boost::scoped_ptr<first_owner_multi_pass_t> mp1(new first_owner_multi_pass_t(a));
- boost::scoped_ptr<first_owner_multi_pass_t> mp2(new first_owner_multi_pass_t(a));
- BOOST_TEST(*mp1 != *mp2);
- ++*mp1;
- BOOST_TEST(*mp1 != *mp2);
-
- }
-
- {
- sstream_t ss;
- ss << "test string";
- istream_iterator<char> b(ss);
- boost::scoped_ptr<first_owner_multi_pass_t> mp2(new first_owner_multi_pass_t(b));
- boost::scoped_ptr<first_owner_multi_pass_t> mp3(new first_owner_multi_pass_t(*mp2));
-
- for (int i = 0; i < 4; ++i)
- {
- res << **mp2;
- ++*mp2;
- }
-
- mp2->clear_queue();
-
- while (*mp2 != *mpend)
- {
- res << **mp2;
- ++*mp2;
- }
-
- try
- {
- res << **mp3; // this should throw illegal_backtracking
- BOOST_TEST(0);
- }
- catch (const boost::spirit::multi_pass_policies::illegal_backtracking& /*e*/)
- {
- }
- res << endl;
- }
-
-}
-
-
-void test_functor_multi_pass()
-{
- res << "-*= test_functor_multi_pass =*-\n";
- functor_multi_pass_t mpend;
-
- {
- functor_multi_pass_t mp1 = functor_multi_pass_t(my_functor());
-
- while (mp1 != mpend)
- {
- res << *(mp1++);
- }
-
- res << endl;
- }
-
- {
- functor_multi_pass_t mp1 = functor_multi_pass_t(my_functor());
- functor_multi_pass_t mp2 = functor_multi_pass_t(mp1);
-
- for (int i = 0; i < 4; ++i)
- {
- res << *mp1;
- ++mp1;
- }
-
- while (mp2 != mpend)
- {
- res << *mp2;
- ++mp2;
- }
-
- while (mp1 != mpend)
- {
- res << *mp1;
- ++mp1;
- }
-
- res << endl;
- }
-
- {
- functor_multi_pass_t mp1 = functor_multi_pass_t(my_functor());
- functor_multi_pass_t mp2 = functor_multi_pass_t(mp1);
-
- BOOST_TEST(mp1 == mp2);
- BOOST_TEST(mp1 >= mp2);
- BOOST_TEST(mp1 <= mp2);
- for (int i = 0; i < 4; ++i)
- {
- res << *mp1;
- ++mp1;
- }
-
- BOOST_TEST(mp1 != mp2);
- BOOST_TEST(mp1 > mp2);
- BOOST_TEST(mp1 >= mp2);
- BOOST_TEST(mp2 < mp1);
- BOOST_TEST(mp2 <= mp1);
- while (mp2 != mp1)
- {
- res << *mp2;
- ++mp2;
- }
-
- BOOST_TEST(mp1 == mp2);
- BOOST_TEST(mp1 >= mp2);
- BOOST_TEST(mp1 <= mp2);
- while (mp1 != mpend)
- {
- res << *mp1;
- ++mp1;
- }
-
- BOOST_TEST(mp1 != mp2);
- BOOST_TEST(mp1 > mp2);
- BOOST_TEST(mp1 >= mp2);
- BOOST_TEST(mp2 < mp1);
- BOOST_TEST(mp2 <= mp1);
- while (mp2 != mpend)
- {
- res << *mp2;
- ++mp2;
- }
-
- BOOST_TEST(mp1 == mp2);
- BOOST_TEST(mp1 >= mp2);
- BOOST_TEST(mp1 <= mp2);
- res << endl;
- }
-
- {
- functor_multi_pass_t mp1 = functor_multi_pass_t(my_functor());
- functor_multi_pass_t mp2 = functor_multi_pass_t(my_functor());
- BOOST_TEST(mp1 != mp2);
- ++mp1;
- BOOST_TEST(mp1 != mp2);
-
- }
-}
-
-int main(int, char**)
-{
-
- test_default_multi_pass();
- test_fixed_multi_pass();
- test_first_owner_multi_pass();
- test_functor_multi_pass();
-
- BOOST_TEST(getstring(res) == "-*= test_default_multi_pass =*-\n"
- "teststring\n"
- "teststring\n"
- "testteststringstring\n"
- "testtring\n"
- "testteststringstring\n"
- "teststring\n"
- "-*= test_fixed_multi_pass =*-\n"
- "teststring\n"
- "teststring\n"
- "testteststringstring\n"
- "testtring\n"
- "testteststringstring\n"
- "-*= test_first_owner_multi_pass =*-\n"
- "teststring\n"
- "teststring\n"
- "testteststringstring\n"
- "testtring\n"
- "testteststringstring\n"
- "teststring\n"
- "-*= test_functor_multi_pass =*-\n"
- "ABCDEFGHIJKL\n"
- "ABCDABCDEFGHIJKLEFGHIJKL\n"
- "ABCDABCDEFGHIJKLEFGHIJKL\n");
-
- return boost::report_errors();
-}
Deleted: trunk/libs/spirit/test/support/multi_pass_compile.cpp
==============================================================================
--- trunk/libs/spirit/test/support/multi_pass_compile.cpp 2009-04-26 10:46:34 EDT (Sun, 26 Apr 2009)
+++ (empty file)
@@ -1,63 +0,0 @@
-/*=============================================================================
- Copyright (c) 2004-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)
-=============================================================================*/
-
-// This is a compile only test for verifying, whether the multi_pass<>
-// iterator works ok with an input iterator, which returns a value_type and not
-// a reference from its dereferencing operator.
-
-#include <cstdio>
-#include <fstream>
-#include <iterator>
-#include <boost/detail/lightweight_test.hpp>
-
-#include <boost/spirit/include/qi_char.hpp>
-#include <boost/spirit/include/qi_numeric.hpp>
-#include <boost/spirit/include/qi_operator.hpp>
-#include <boost/spirit/include/qi_nonterminal.hpp>
-#include <boost/spirit/include/qi_parse.hpp>
-#include <boost/spirit/include/support_multi_pass.hpp>
-
-#if defined(BOOST_HAS_UNISTD_H)
-#include <unistd.h> // unlink()
-#endif
-
-#if defined(__MINGW32__)
-#include <io.h> // unlink()
-#endif
-
-using namespace boost::spirit;
-using namespace boost::spirit::qi;
-using namespace std;
-
-int main ()
-{
- // create a sample file
- {
- ofstream out("./input_file.txt");
- out << 1.0 << "," << 2.0;
- }
-
- // read in the values from the sample file
- {
- ifstream in("./input_file.txt"); // we get our input from this file
-
- typedef multi_pass<istreambuf_iterator<char> > iterator_type;
-
- iterator_type first(make_multi_pass(istreambuf_iterator<char>(in)));
- iterator_type last(make_multi_pass(istreambuf_iterator<char>()));
-
- rule<iterator_type> n_list;
- n_list = double_ >> *(char_(',') >> double_);
- BOOST_TEST(parse(first, last, n_list));
- }
-
-#if !defined(__COMO_VERSION__)
- unlink("./input_file.txt");
-#endif
-
- return boost::report_errors();
-}
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