Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r70550 - in trunk/libs/spirit: doc test test/qi
From: hartmut.kaiser_at_[hidden]
Date: 2011-03-25 21:01:42


Author: hkaiser
Date: 2011-03-25 21:01:41 EDT (Fri, 25 Mar 2011)
New Revision: 70550
URL: http://svn.boost.org/trac/boost/changeset/70550

Log:
Spirit: fixing iterator handling in stream parser, added test
Added:
   trunk/libs/spirit/test/qi/stream.cpp (contents, props changed)
Text files modified:
   trunk/libs/spirit/doc/spirit2.qbk | 4 +++-
   trunk/libs/spirit/doc/what_s_new.qbk | 3 +++
   trunk/libs/spirit/test/Jamfile | 1 +
   3 files changed, 7 insertions(+), 1 deletions(-)

Modified: trunk/libs/spirit/doc/spirit2.qbk
==============================================================================
--- trunk/libs/spirit/doc/spirit2.qbk (original)
+++ trunk/libs/spirit/doc/spirit2.qbk 2011-03-25 21:01:41 EDT (Fri, 25 Mar 2011)
@@ -216,7 +216,7 @@
 [template karma_string[str] [link spirit.karma.reference.string [str]]]
 [template karma_symbols[str] [link spirit.karma.reference.string.symbols [str]]]
 
-[template karma_stream[str] [link spirit.karma.reference.stream [str]]]
+[template karma_stream[str] [link spirit.karma.reference.stream.stream [str]]]
 
 [template karma_auto[str] [link spirit.karma.reference.auto [str]]]
 [def __create_generator__ [link spirit.karma.reference.generate_api.create_generator `create_generator`]]
@@ -421,6 +421,8 @@
 [def __qi_sequence__ [link spirit.qi.reference.operator.sequence Sequence]]
 [def __qi_sequential_or__ [link spirit.qi.reference.operator.sequential_or Sequential Or]]
 
+[def __qi_stream__ [link spirit.qi.reference.stream.stream `stream`]]
+
 [/ nonterminal]
 [def __qi_rule__ [link spirit.qi.reference.nonterminal.rule rule]]
 [def __qi_rules__ [link spirit.qi.reference.nonterminal.rule rules]]

Modified: trunk/libs/spirit/doc/what_s_new.qbk
==============================================================================
--- trunk/libs/spirit/doc/what_s_new.qbk (original)
+++ trunk/libs/spirit/doc/what_s_new.qbk 2011-03-25 21:01:41 EDT (Fri, 25 Mar 2011)
@@ -57,6 +57,9 @@
   the __karma__ [karma_symbols `symbols<>`] generator to properly handle
   container attributes. Those have been broken in Boost V1.46.1 (thanks to
   Aaron Graham and Joerg Becker for reporting those).
+* Fixed the __qi_stream__ parser to properly adjust the iterator of the
+ underlying input stream in the case when the stream parser component was
+ successful.
 
 [heading Breaking Changes]
 

Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2011-03-25 21:01:41 EDT (Fri, 25 Mar 2011)
@@ -85,6 +85,7 @@
      [ run qi/sequence.cpp : : : : qi_sequence ]
      [ run qi/sequential_or.cpp : : : : qi_sequential_or ]
      [ run qi/skip.cpp : : : : qi_skip ]
+ [ run qi/stream.cpp : : : : qi_stream ]
      [ run qi/symbols1.cpp : : : : qi_symbols1 ]
      [ run qi/symbols2.cpp : : : : qi_symbols2 ]
      [ run qi/terminal_ex.cpp : : : : qi_terminal_ex ]

Added: trunk/libs/spirit/test/qi/stream.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/qi/stream.cpp 2011-03-25 21:01:41 EDT (Fri, 25 Mar 2011)
@@ -0,0 +1,60 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Hartmut Kaiser
+ Copyright (c) 2011 Brian O'Kennedy
+
+ 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/qi_char.hpp>
+#include <boost/spirit/include/qi_numeric.hpp>
+#include <boost/spirit/include/qi_stream.hpp>
+#include <boost/spirit/include/qi_operator.hpp>
+
+#include "test.hpp"
+
+struct complex
+{
+ complex (double a = 0.0, double b = 0.0) : a(a), b(b) {}
+ double a, b;
+};
+
+std::istream& operator>> (std::istream& is, complex& z)
+{
+ char lbrace = '\0', comma = '\0', rbrace = '\0';
+ is >> lbrace >> z.a >> comma >> z.b >> rbrace;
+ if (lbrace != '{' || comma != ',' || rbrace != '}')
+ is.setstate(std::ios_base::failbit);
+
+ return is;
+}
+
+int main()
+{
+ using spirit_test::test_attr;
+
+ {
+ using boost::spirit::qi::blank;
+ using boost::spirit::qi::double_;
+ using boost::spirit::qi::stream;
+ using boost::spirit::qi::stream_parser;
+ using boost::fusion::at_c;
+
+ complex c;
+ BOOST_TEST(test_attr("{1.0,2.5}",
+ stream_parser<char, complex>(), c, blank) &&
+ c.a == 1.0 && c.b == 2.5);
+
+ boost::fusion::vector<complex, double> d;
+ BOOST_TEST(test_attr("{1.0,2.5},123.456",
+ stream >> ',' >> double_, d, blank) &&
+ at_c<0>(d).a == 1.0 && at_c<0>(d).b == 2.5 && at_c<1>(d) == 123.456);
+ }
+
+ 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