|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63087 - trunk/libs/spirit/test/qi
From: hartmut.kaiser_at_[hidden]
Date: 2010-06-18 17:51:32
Author: hkaiser
Date: 2010-06-18 17:51:30 EDT (Fri, 18 Jun 2010)
New Revision: 63087
URL: http://svn.boost.org/trac/boost/changeset/63087
Log:
Spirit: fixed backtracking problem if semantic action makes parse fail retrospectively, added test
Text files modified:
trunk/libs/spirit/test/qi/actions.cpp | 27 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)
Modified: trunk/libs/spirit/test/qi/actions.cpp
==============================================================================
--- trunk/libs/spirit/test/qi/actions.cpp (original)
+++ trunk/libs/spirit/test/qi/actions.cpp 2010-06-18 17:51:30 EDT (Fri, 18 Jun 2010)
@@ -42,6 +42,23 @@
}
};
+void fail (int, boost::spirit::unused_type, bool& pass)
+{
+ pass = false;
+}
+
+struct setnext
+{
+ setnext(char& next) : next(next) {}
+
+ void operator()(char c, unused_type, unused_type) const
+ {
+ next = c;
+ }
+
+ char& next;
+};
+
int main()
{
namespace qi = boost::spirit::qi;
@@ -81,8 +98,16 @@
char const *s1 = "{42}", *e1 = s1 + std::strlen(s1);
qi::parse(s1, e1, '{' >> int_[lambda::var(x) += lambda::_1] >> '}');
}
-
BOOST_TEST(x == (42*6));
+
+ {
+ std::string input("1234 6543");
+ char next = '\0';
+ BOOST_TEST(qi::phrase_parse(input.begin(), input.end(),
+ qi::int_[fail] | qi::digit[setnext(next)] , qi::space));
+ BOOST_TEST(next == '1');
+ }
+
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