Opened 11 years ago

Closed 20 months ago

#6050 closed Patches (invalid)

Make spirit::transform_attribute::post return bool instead of void

Reported by: oakad@… Owned by: Joel de Guzman
Milestone: To Be Determined Component: spirit
Version: Boost 1.47.0 Severity: Problem
Keywords: Cc: hkaiser@…

Description

Currently, when doing attribute transformations, spirit::qi assumes that if "Transformed" attribute parsing succeedes, then assignment to "Exposed" attribute value will inevitably succeed as well, hence transform_attribute::post return value is not provided nor checked for.

However, there are many classes of problems (especially those involving restricted numeric types, such as ranges and strongly typed enums) which can benefit from recoverable parser failures during attribute transformation, if post() was allowed to signal a failure.

The proposed patch to spirit::qi is attached.

Attachments (7)

spirit-transform-attribute-post-bool.diff (7.5 KB ) - added by oakad@… 11 years ago.
Patch to make attribute_transform::post return bool
spirit-transform-attribute-post-bool-v2.diff (9.5 KB ) - added by oakad@… 11 years ago.
Patch to allow transform_attribute::post to fail the parser; compared to previous version this will set back the input iterator if conversion fails.
test_attr.cpp (2.4 KB ) - added by oakad@… 11 years ago.
A short example demonstrating a basic use case for the propoesed change.
spirit-transform-attribute-post-bool-v3.patch (24.3 KB ) - added by oakad@… 11 years ago.
Added test cases, example and updated documentation
spirit-transform-attribute-post-bool-v4.patch (25.8 KB ) - added by oakad@… 11 years ago.
Backtracking in qi::rule now saves the position before the skipper; support for qi::action new attribute transformation behaviour.
spirit-transform-attribute-post-bool-v5.patch (37.8 KB ) - added by oakad@… 10 years ago.
Updated v4 patch to account for some cosmetic differences in the recent qi version + added some examples missing from the v4 patch.
spirit-transform-attribute-post-bool-v6.patch (37.2 KB ) - added by oakad@… 10 years ago.
Fix an unfortunately missed "bit rot" in v5 arising from changed function attribute names.

Download all attachments as: .zip

Change History (13)

by oakad@…, 11 years ago

Patch to make attribute_transform::post return bool

by oakad@…, 11 years ago

Patch to allow transform_attribute::post to fail the parser; compared to previous version this will set back the input iterator if conversion fails.

by oakad@…, 11 years ago

Attachment: test_attr.cpp added

A short example demonstrating a basic use case for the propoesed change.

comment:1 by oakad@…, 11 years ago

Compared to my initial submission, -v2 version of the patch will hold a copy of the input iterator and won't advance it until it can be sure that attribute conversion succeeded. This is analogous to what as<> directive does. Without this minor quirk the facility is not that useful. :-)

I also attached a smallish example which demonstrates the expected functionality.

by oakad@…, 11 years ago

Added test cases, example and updated documentation

by oakad@…, 11 years ago

Backtracking in qi::rule now saves the position before the skipper; support for qi::action new attribute transformation behaviour.

comment:2 by Joel de Guzman, 10 years ago

I tried to apply this patch but there are some parts being rejected. Could you please update the patch? Thanks!

by oakad@…, 10 years ago

Updated v4 patch to account for some cosmetic differences in the recent qi version + added some examples missing from the v4 patch.

comment:3 by oakad@…, 10 years ago

The only problem I encountered with my patch was slightly shifted line numbers due to some header changes.

Unfortunately, I could not retest it as I'm currently traveling abroad.

comment:4 by Joel de Guzman, 10 years ago

I get lots of errors running the tests

by oakad@…, 10 years ago

Fix an unfortunately missed "bit rot" in v5 arising from changed function attribute names.

in reply to:  4 comment:5 by oakad@…, 10 years ago

Replying to djowel:

I get lots of errors running the tests

Sorry for that. I should have not acted hastily when fixing this patch up. All tests seem to pass just fine with the update, apart from match_manip1.cpp (some problem on my side, may be - it fails with bad_alloc) and regression_stream_eof.cpp (seem to be broken as it is).

comment:6 by Joel de Guzman, 20 months ago

Resolution: invalid
Status: newclosed

breaking change, examples are inconclusive for a feature request as the same can be done with exceptions, semantic actions or custom parsers.

Note: See TracTickets for help on using tickets.