|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r68907 - trunk/boost/spirit/home/qi/action
From: joel_at_[hidden]
Date: 2011-02-14 22:20:31
Author: djowel
Date: 2011-02-14 22:20:29 EST (Mon, 14 Feb 2011)
New Revision: 68907
URL: http://svn.boost.org/trac/boost/changeset/68907
Log:
Allow attribute compatibility with semantic actions
Text files modified:
trunk/boost/spirit/home/qi/action/action.hpp | 50 +++++++++++++++++++++++++++++++++++++++
1 files changed, 49 insertions(+), 1 deletions(-)
Modified: trunk/boost/spirit/home/qi/action/action.hpp
==============================================================================
--- trunk/boost/spirit/home/qi/action/action.hpp (original)
+++ trunk/boost/spirit/home/qi/action/action.hpp 2011-02-14 22:20:29 EST (Mon, 14 Feb 2011)
@@ -44,6 +44,7 @@
action(Subject const& subject, Action f)
: subject(subject), f(f) {}
+#ifndef BOOST_SPIRIT_ACTIONS_ALLOW_ATTR_COMPAT
template <typename Iterator, typename Context
, typename Skipper, typename Attribute>
bool parse(Iterator& first, Iterator const& last
@@ -68,12 +69,59 @@
if (traits::action_dispatch<Subject>()(f, attr, context))
return true;
- // reset iterators if semantic action failed the match
+ // reset iterators if semantic action failed the match
// retrospectively
first = save;
}
return false;
}
+#else
+ template <typename Iterator, typename Context
+ , typename Skipper, typename Attribute>
+ bool parse(Iterator& first, Iterator const& last
+ , Context& context, Skipper const& skipper
+ , Attribute& attr) const
+ {
+ Iterator save = first;
+ if (subject.parse(first, last, context, skipper, attr)) // Use the attribute as-is
+ {
+ // call the function, passing the attribute, the context.
+ // The client can return false to fail parsing.
+ if (traits::action_dispatch<Subject>()(f, attr, context))
+ return true;
+
+ // reset iterators if semantic action failed the match
+ // retrospectively
+ first = save;
+ }
+ return false;
+ }
+
+ template <typename Iterator, typename Context
+ , typename Skipper>
+ bool parse(Iterator& first, Iterator const& last
+ , Context& context, Skipper const& skipper
+ , unused_type) const
+ {
+ // synthesize the attribute since one is not supplied
+ typedef typename attribute<Context, Iterator>::type attr_type;
+ typename attr_type attr;
+
+ Iterator save = first;
+ if (subject.parse(first, last, context, skipper, attr))
+ {
+ // call the function, passing the attribute, the context.
+ // The client can return false to fail parsing.
+ if (traits::action_dispatch<Subject>()(f, attr, context))
+ return true;
+
+ // reset iterators if semantic action failed the match
+ // retrospectively
+ first = save;
+ }
+ return false;
+ }
+#endif
template <typename Context>
info what(Context& context) const
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