Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r56510 - trunk/libs/spirit/test/qi
From: joel_at_[hidden]
Date: 2009-10-02 05:05:06


Author: djowel
Date: 2009-10-02 05:05:05 EDT (Fri, 02 Oct 2009)
New Revision: 56510
URL: http://svn.boost.org/trac/boost/changeset/56510

Log:
kleene, plus and repeat attribute customization points.
Text files modified:
   trunk/libs/spirit/test/qi/kleene.cpp | 24 ++++++++++++++++++++++++
   trunk/libs/spirit/test/qi/list.cpp | 6 ++++++
   trunk/libs/spirit/test/qi/plus.cpp | 26 +++++++++++++++++++++++++-
   trunk/libs/spirit/test/qi/repeat.cpp | 26 ++++++++++++++++++++++++++
   4 files changed, 81 insertions(+), 1 deletions(-)

Modified: trunk/libs/spirit/test/qi/kleene.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/kleene.cpp (original)
+++ trunk/libs/spirit/test/qi/kleene.cpp 2009-10-02 05:05:05 EDT (Fri, 02 Oct 2009)
@@ -24,6 +24,24 @@
 #include <iostream>
 #include "test.hpp"
 
+struct x_attr
+{
+};
+
+namespace boost { namespace spirit { namespace traits
+{
+ template <>
+ struct container_value<x_attr>
+ {
+ typedef char type; // value type of container
+ };
+
+ inline void push_back(x_attr& c, char val)
+ {
+ // push back value type into container
+ }
+}}}
+
 int
 main()
 {
@@ -114,6 +132,12 @@
         BOOST_TEST(test("123 456 789", (*int_)[phx::ref(v) = _1], space) && 3 == v.size() &&
             v[0] == 123 && v[1] == 456 && v[2] == 789);
     }
+
+ { // attribute customization
+
+ x_attr x;
+ test_attr("abcde", *char_, x);
+ }
 
     return boost::report_errors();
 }

Modified: trunk/libs/spirit/test/qi/list.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/list.cpp (original)
+++ trunk/libs/spirit/test/qi/list.cpp 2009-10-02 05:05:05 EDT (Fri, 02 Oct 2009)
@@ -51,6 +51,12 @@
         BOOST_TEST(test_attr("a,b,c,d,e,f,g,h", char_ % ',', s));
         BOOST_TEST(s == "abcdefgh");
     }
+
+ {
+ using boost::spirit::uint_;
+
+ BOOST_TEST(test("1-2", (uint_ % '+') | (uint_ % '-')));
+ }
 
     {
         using boost::spirit::int_;

Modified: trunk/libs/spirit/test/qi/plus.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/plus.cpp (original)
+++ trunk/libs/spirit/test/qi/plus.cpp 2009-10-02 05:05:05 EDT (Fri, 02 Oct 2009)
@@ -24,11 +24,29 @@
 #include <iostream>
 #include "test.hpp"
 
-using namespace spirit_test;
+struct x_attr
+{
+};
+
+namespace boost { namespace spirit { namespace traits
+{
+ template <>
+ struct container_value<x_attr>
+ {
+ typedef char type; // value type of container
+ };
+
+ inline void push_back(x_attr& c, char val)
+ {
+ // push back value type into container
+ }
+}}}
 
 int
 main()
 {
+ using spirit_test::test;
+ using spirit_test::test_attr;
     using namespace boost::spirit::ascii;
     using boost::spirit::qi::int_;
     using boost::spirit::qi::omit;
@@ -101,6 +119,12 @@
         BOOST_TEST(test("1 2 3", (+int_)[phx::ref(v) = _1], space) && 3 == v.size() &&
             v[0] == 1 && v[1] == 2 && v[2] == 3);
     }
+
+ { // attribute customization
+
+ x_attr x;
+ test_attr("abcde", +char_, x);
+ }
 
     return boost::report_errors();
 }

Modified: trunk/libs/spirit/test/qi/repeat.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/repeat.cpp (original)
+++ trunk/libs/spirit/test/qi/repeat.cpp 2009-10-02 05:05:05 EDT (Fri, 02 Oct 2009)
@@ -24,6 +24,23 @@
 #include <iostream>
 #include "test.hpp"
 
+struct x_attr
+{
+};
+
+namespace boost { namespace spirit { namespace traits
+{
+ template <>
+ struct container_value<x_attr>
+ {
+ typedef char type; // value type of container
+ };
+
+ inline void push_back(x_attr& c, char val)
+ {
+ // push back value type into container
+ }
+}}}
 
 int
 main()
@@ -180,6 +197,15 @@
         BOOST_TEST(test("aaaaaa", repeat(val(3), inf)[char_]));
         BOOST_TEST(!test("aa", repeat(3, val(inf))[char_]));
     }
+
+ { // attribute customization
+
+ x_attr x;
+ test_attr("abcde", repeat[char_], x);
+ test_attr("abcde", repeat(5)[char_], x);
+ test_attr("abcde", repeat(1, 5)[char_], x);
+ test_attr("abcde", repeat(1, inf)[char_], x);
+ }
 
     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