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

@@ -239,15 +239,15 @@ void state_transitions_set (state *s, int num, state **dst);
/* Set the reductions of STATE. */
void state_reductions_set (state *s, int num, rule **reds);
int state_reduction_find (state *s, rule *r);
int state_reduction_find (state *s, rule const *r);
/* Set the errs of STATE. */
void state_errs_set (state *s, int num, symbol **errors);
/* Print on OUT all the lookahead tokens such that this STATE wants to
reduce R. */
void state_rule_lookahead_tokens_print (state *s, rule *r, FILE *out);
void state_rule_lookahead_tokens_print_xml (state *s, rule *r,
void state_rule_lookahead_tokens_print (state *s, rule const *r, FILE *out);
void state_rule_lookahead_tokens_print_xml (state *s, rule const *r,
FILE *out, int level);
/* Create/destroy the states hash table. */