|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60154 - in trunk/libs/spirit/test: . support
From: hartmut.kaiser_at_[hidden]
Date: 2010-03-04 13:58:28
Author: hkaiser
Date: 2010-03-04 13:58:28 EST (Thu, 04 Mar 2010)
New Revision: 60154
URL: http://svn.boost.org/trac/boost/changeset/60154
Log:
Spirit: Fixed return value for expect parser if exceptions are not enabled.
Added:
trunk/libs/spirit/test/support/multi_pass_regression003.cpp (contents, props changed)
Text files modified:
trunk/libs/spirit/test/Jamfile | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
Modified: trunk/libs/spirit/test/Jamfile
==============================================================================
--- trunk/libs/spirit/test/Jamfile (original)
+++ trunk/libs/spirit/test/Jamfile 2010-03-04 13:58:28 EST (Thu, 04 Mar 2010)
@@ -143,6 +143,7 @@
# support tests
[ compile support/multi_pass_regression001.cpp : : support_multi_pass_regression001 ]
[ compile support/multi_pass_regression002.cpp : : support_multi_pass_regression002 ]
+ [ compile support/multi_pass_regression003.cpp : : support_multi_pass_regression003 ]
# regression tests
Added: trunk/libs/spirit/test/support/multi_pass_regression003.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/spirit/test/support/multi_pass_regression003.cpp 2010-03-04 13:58:28 EST (Thu, 04 Mar 2010)
@@ -0,0 +1,61 @@
+// Copyright (c) 2010 Peter Schueller
+// Copyright (c) 2001-2010 Hartmut Kaiser
+//
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#include <boost/config/warning_disable.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <vector>
+#include <istream>
+#include <sstream>
+#include <iostream>
+
+#include <boost/spirit/include/qi.hpp>
+#include <boost/spirit/include/support_multi_pass.hpp>
+
+namespace qi = boost::spirit::qi;
+namespace ascii = boost::spirit::ascii;
+
+std::vector<double> parse(std::istream& input)
+{
+ // iterate over stream input
+ typedef std::istreambuf_iterator<char> base_iterator_type;
+ base_iterator_type in_begin(input);
+
+ // convert input iterator to forward iterator, usable by spirit parser
+ typedef boost::spirit::multi_pass<base_iterator_type> forward_iterator_type;
+ forward_iterator_type fwd_begin = boost::spirit::make_default_multi_pass(in_begin);
+ forward_iterator_type fwd_end;
+
+ // prepare output
+ std::vector<double> output;
+
+ // parse
+ bool r = qi::phrase_parse(
+ fwd_begin, fwd_end, // iterators over input
+ qi::double_ >> *(',' >> qi::double_) >> qi::eoi, // recognize list of doubles
+ ascii::space | '#' >> *(ascii::char_ - qi::eol) >> qi::eol, // comment skipper
+ output); // doubles are stored into this object
+
+ // error detection
+ if( !r || fwd_begin != fwd_end )
+ throw std::runtime_error("parse error");
+
+ // return result
+ return output;
+}
+
+int main()
+{
+ try {
+ std::stringstream str("1.0,2.0\n");
+ std::vector<double> values = parse(str);
+ BOOST_TEST(values.size() == 2 && values[0] == 1.0 && values[1] == 2.0);
+ }
+ catch(std::exception const&) {
+ BOOST_TEST(false);
+ }
+ 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