- rules[ruleno].action = p->action ? translate_rule_action (p) : NULL;
- rules[ruleno].action_location = p->action_location;
-
- /* If this rule contains midrules, rest assured that
- grammar_midrule_action inserted the midrules into grammar before this
- rule. Thus, the midrule actions have already been scanned in order to
- set `used' flags for this rule's rhs, so grammar_rule_check will work
- properly. */
- grammar_rule_check (p);
-
- for (p = p->next; p && p->sym; p = p->next)
+ rules[ruleno].action = p->action_props.code;
+ rules[ruleno].action_location = p->action_props.location;
+
+ /* If the midrule's $$ is set or its $n is used, remove the `$' from the
+ symbol name so that it's a user-defined symbol so that the default
+ %destructor and %printer apply. */
+ if (p->midrule_parent_rule
+ && (p->action_props.is_value_used
+ || symbol_list_n_get (p->midrule_parent_rule,
+ p->midrule_parent_rhs_index)
+ ->action_props.is_value_used))
+ p->content.sym->tag += 1;
+
+ /* Don't check the generated rule 0. It has no action, so some rhs
+ symbols may appear unused, but the parsing algorithm ensures that
+ %destructor's are invoked appropriately. */
+ if (p != grammar)
+ grammar_rule_check (p);
+
+ for (p = p->next; p && p->content.sym; p = p->next)