boostorg / spirit

Boost.org spirit module
http://boost.org/libs/spirit
383 stars 159 forks source link

need for "RHS" transform_attribute #780

Open cppljevans opened 7 months ago

cppljevans commented 7 months ago

<!DOCTYPE html>

Need for "RHS" transform_attribute

Existing use of "external" transform_attribute

The transform_attribute class is used in 2 places

  1. within rule::parse function
  2. The purpose here is to transform the passed-in, or external, attribute type, Attribute_, to the rule's attribute, attribute_type.

  3. within call_rule_definition function
  4. The purpose here is the very same as the purpose above. The only difference is the name of the types. Here, instead of the passed-in attribute type being named Attribute_, the name is ActualAttribute, and instead of the rule's attribute being named attribute_type, the name is simply Attribute.

Proposed use of "RHS" transform_attribute

Currently, the x3 docs require that the rule attribute is "compatible" with the RHS attribute (page 96).

The propsed RHS transform would relieve the end-user of this compatibility constraint by transforming a possibly incompatible rule attribute to the RHS's attribute.

If such a RHS transform_attribute's post returns a bool value, then it could be used to replace some semantic actions and changes to the context, as shown here.

This RHS transform_attribute use could be placed somewhere after the external transform attribute use, possibly in the call_rule_defintion body just before parse_rhs call here.

using rhs_attr= typename traits::attribute_of<RHS,Context>::type ; using transform= traits::transform_attribute_tagged < ActualAttribute , rhs_attr , rule_internal_id<ID> >; using transform_type=typename transform::type; transform_type rhs_actual= transform::pre ( attr_ ); ok_parse = parse_rhs ( rhs , first , last , context , attr_//RContext& //Rule Context, to allow actions to access rule attribute. //see val_context in core/call.hpp. , rhs_actual , has_action_and_not_explicit_propagation_t() ); if(ok_parse) { ok_parse=transform::post(attr_,rhs_actual); }