|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55493 - trunk/libs/spirit/example/karma
From: hartmut.kaiser_at_[hidden]
Date: 2009-08-09 15:16:38
Author: hkaiser
Date: 2009-08-09 15:16:38 EDT (Sun, 09 Aug 2009)
New Revision: 55493
URL: http://svn.boost.org/trac/boost/changeset/55493
Log:
Spirit: improved error handling in one of the karma examples
Text files modified:
trunk/libs/spirit/example/karma/mini_xml_karma.cpp | 22 ++++++++++------------
1 files changed, 10 insertions(+), 12 deletions(-)
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-08-09 15:16:38 EDT (Sun, 09 Aug 2009)
@@ -132,15 +132,11 @@
{
mini_xml_generator() : mini_xml_generator::base_type(xml)
{
- node %=
- string [_1 = _string(_val)]
- | xml [_1 = _xml(_val)]
- ;
-
+ node %= string | xml;
xml =
- char_('<') << string[_1 = at_c<0>(_val)] << '>'
- << (*node)[_1 = at_c<1>(_val)]
- << lit("</") << string[_1 = at_c<0>(_val)] << '>'
+ '<' << string[_1 = at_c<0>(_val)] << '>'
+ << (*node)[_1 = at_c<1>(_val)]
+ << "</" << string[_1 = at_c<0>(_val)] << '>'
;
}
@@ -184,8 +180,8 @@
mini_xml_parser xmlin; // Our grammar definition
mini_xml ast; // our tree
- std::string::const_iterator iter = storage.begin();
- std::string::const_iterator end = storage.end();
+ std::string::iterator iter = storage.begin();
+ std::string::iterator end = storage.end();
bool r = qi::phrase_parse(iter, end, xmlin, space, ast);
if (r && iter == end)
@@ -209,8 +205,10 @@
}
else
{
- std::string::const_iterator some = iter+30;
- std::string context(iter, (some>end)?end:some);
+ std::size_t dist = std::distance(storage.begin(), iter);
+ std::string::iterator some =
+ iter + (std::min)(storage.size()-dist, std::size_t(30));
+ std::string context(iter, some);
std::cout << "-------------------------\n";
std::cout << "Parsing failed\n";
std::cout << "stopped at: \": " << context << "...\"\n";
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