On 07/31/2013 10:03 PM, Agustín K-ballo Bergé wrote:
... For Spirit V2, policies are not required to inherit from the default ones, so any change to them is potentially a breaking change. Although I have yet to see a case where this would happen. If you think this approach would work for your use case and you want to try and make the necessary source and documentation changes, I will be happy to help you through the process.
Thank you. The patch (against svn trunk as of 2013-08-01) I have so far is quite small, so I in-lined it below. Without knowing a whole lot more about Spirit, this is my best guess for the files that would need changing. I built the resultant quickbook and ran the spirit unit tests, though some are failing trunk on my gcc version 4.7.3 setup, but appear to be unrelated to this change. I'm still not 100% sure that this is a proper approach to the problem. For instance, maybe the policy should be initializing the value, and that is incorporated into the begin/init or separate. If you feel that this approach is appropriate, I can do some small additional changes to conform to the code base properly if I know what they are. If there is substantial effort to get where it needs to be, it is probably not worth your time right now and the patch can be archived in the mailing list if it's useful for a later time. Regards, Brian Index: libs/spirit/doc/qi/numeric.qbk =================================================================== --- libs/spirit/doc/qi/numeric.qbk (revision 85183) +++ libs/spirit/doc/qi/numeric.qbk (working copy) @@ -765,6 +765,7 @@ [table [[Expression] [Semantics]] + [[`RP::begin(n)`] [Allows the policy to initialize]] [[`RP::allow_leading_dot`] [Allow leading dot.]] [[`RP::allow_trailing_dot`] [Allow trailing dot.]] [[`RP::expect_dot`] [Require a dot.]] @@ -789,6 +790,8 @@ [[`RP::parse_inf(f, l, n)`] [Parse an Inf. Return `true` if successful, otherwise `false`. If successful, place the result into `n`.]] + [[`RP::end(n,b)`] [Allows the policy to finalize, b is result of parsing. + Return `true` if successful, otherwise `false`.]] ] The `parse_nan` and `parse_inf` functions get called whenever: Index: boost/spirit/home/qi/numeric/detail/real_impl.hpp =================================================================== --- boost/spirit/home/qi/numeric/detail/real_impl.hpp (revision 85183) +++ boost/spirit/home/qi/numeric/detail/real_impl.hpp (working copy) @@ -133,6 +133,7 @@ parse(Iterator& first, Iterator const& last, Attribute& attr, RealPolicies const& p) { + p.begin(attr); if (first == last) return false; Iterator save = first; @@ -258,7 +259,7 @@ traits::assign_to(traits::negate(neg, n), attr); // Success!!! - return true; + return p.end(attr, true); } }; Index: boost/spirit/home/qi/numeric/real_policies.hpp =================================================================== --- boost/spirit/home/qi/numeric/real_policies.hpp (revision 85183) +++ boost/spirit/home/qi/numeric/real_policies.hpp (working copy) @@ -28,6 +28,13 @@ static bool const allow_trailing_dot = true; static bool const expect_dot = false; + // Do any initialization of attr that is needed + template <typename Attribute> + static void + begin(Attribute& attr_) + { + } + template <typename Iterator> static bool parse_sign(Iterator& /*first*/, Iterator const& /*last*/) @@ -154,6 +161,14 @@ } return false; } + + // Do any finalization of attr that is needed + template <typename Attribute> + static bool + end(Attribute& attr_,bool result) + { + return result; + } }; ///////////////////////////////////////////////////////////////////////////