gram: factor the printing of items and the computation of their rule

There are several places where we need to recover the rule from an
item, let's factor that into item_rule.  We also want to print items
in a nice way: we do it when generating the *output file, but it is
also useful in debug messages.

* src/gram.h, src/gram.c (item_rule, item_print): New.
* src/print.c (print_core): Use them.
* src/state.h, src/state.c: Propagate constness.
This commit is contained in:
Akim Demaille
2019-01-28 19:05:38 +01:00
parent c4f143eb96
commit e1783bc686
6 changed files with 53 additions and 31 deletions

View File

@@ -166,6 +166,7 @@ item_number_is_rule_number (item_number i)
return i < 0;
}
/*--------.
| Rules. |
`--------*/
@@ -207,6 +208,15 @@ typedef struct
extern rule *rules;
/* Get the rule associated to this item. ITEM points inside RITEM. */
rule const *item_rule (item_number const *item);
/* Pretty-print this ITEM (as in the report). ITEM points inside
RITEM. PREVIOUS_RULE is used to see if the lhs is common, in which
case LHS is factored. Passing NULL is fine. */
void item_print (item_number *item, rule const *previous_rule,
FILE *out);
/* A function that selects a rule. */
typedef bool (*rule_filter) (rule const *);