mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
reports: don't escape the labels
Currently we use "quotearg" to escape the strings output in Dot. As a
result, if the user's locale is C for instance, all the non-ASCII are
escaped. Unfortunately graphviz does not interpret this style of
escaping.
For instance:
5 -> 2 [style=solid label="\"\303\221\303\271\341\271\203\303\251\342\204\235\303\264\""]
was displayed as a sequence of numbers. We now output:
5 -> 2 [style=solid label="\"Ñùṃéℝô\""]
independently of the user's locale.
* src/system.h (obstack_backslash): New.
* src/graphviz.h, src/graphviz.c (escape): Remove, use
obstack_backslash instead.
* src/print-graph.c: Likewise.
* tests/report.at: Adjust.
This commit is contained in:
@@ -72,18 +72,20 @@ output_edge (int source, int destination, char const *label,
|
||||
{
|
||||
fprintf (fout, " %d -> %d [style=%s", source, destination, style);
|
||||
if (label)
|
||||
fprintf (fout, " label=%s", quote (label));
|
||||
{
|
||||
fputs (" label=\"", fout);
|
||||
for (const char *cp = label; *cp; ++cp)
|
||||
switch (*cp)
|
||||
{
|
||||
case '"': fputs ("\\\"", fout); break;
|
||||
case '\\': fputs ("\\\\", fout); break;
|
||||
default: fputc (*cp, fout); break;
|
||||
}
|
||||
fputc ('"', fout);
|
||||
}
|
||||
fputs ("]\n", fout);
|
||||
}
|
||||
|
||||
char const *
|
||||
escape (char const *name)
|
||||
{
|
||||
char *q = quote (name);
|
||||
q[strlen (q) - 1] = '\0';
|
||||
return q + 1;
|
||||
}
|
||||
|
||||
static void
|
||||
no_reduce_bitset_init (state const *s, bitset *no_reduce_set)
|
||||
{
|
||||
@@ -149,7 +151,7 @@ print_token (struct obstack *out, bool first, char const *tok)
|
||||
{
|
||||
if (! first)
|
||||
obstack_sgrow (out, ", ");
|
||||
obstack_sgrow (out, escape (tok));
|
||||
obstack_backslash (out, tok);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -63,10 +63,4 @@ void output_red (state const *s, reductions const *reds, FILE *fout);
|
||||
*/
|
||||
void finish_graph (FILE *fout);
|
||||
|
||||
/** Escape a lookahead token.
|
||||
*
|
||||
* \param name the token.
|
||||
*/
|
||||
char const *escape (char const *name);
|
||||
|
||||
#endif /* ! GRAPHVIZ_H_ */
|
||||
|
||||
@@ -72,19 +72,28 @@ print_core (struct obstack *oout, state *s)
|
||||
obstack_printf (oout, "%*s| ",
|
||||
(int) strlen (previous_lhs->symbol->tag), "");
|
||||
else
|
||||
obstack_printf (oout, "%s: ", escape (r->lhs->symbol->tag));
|
||||
{
|
||||
obstack_backslash (oout, r->lhs->symbol->tag);
|
||||
obstack_printf (oout, ": ");
|
||||
}
|
||||
previous_lhs = r->lhs;
|
||||
|
||||
for (item_number const *sp = r->rhs; sp < sp1; sp++)
|
||||
obstack_printf (oout, "%s ", escape (symbols[*sp]->tag));
|
||||
{
|
||||
obstack_backslash (oout, symbols[*sp]->tag);
|
||||
obstack_1grow (oout, ' ');
|
||||
}
|
||||
|
||||
obstack_1grow (oout, '.');
|
||||
|
||||
if (0 <= *r->rhs)
|
||||
for (item_number const *sp = sp1; 0 <= *sp; ++sp)
|
||||
obstack_printf (oout, " %s", escape (symbols[*sp]->tag));
|
||||
{
|
||||
obstack_1grow (oout, ' ');
|
||||
obstack_backslash (oout, symbols[*sp]->tag);
|
||||
}
|
||||
else
|
||||
obstack_printf (oout, " %%empty");
|
||||
obstack_sgrow (oout, " %empty");
|
||||
|
||||
/* Experimental feature: display the lookahead tokens. */
|
||||
if (report_flag & report_lookahead_tokens
|
||||
@@ -104,7 +113,7 @@ print_core (struct obstack *oout, state *s)
|
||||
BITSET_FOR_EACH (biter, reds->lookahead_tokens[redno], k, 0)
|
||||
{
|
||||
obstack_sgrow (oout, sep);
|
||||
obstack_sgrow (oout, escape (symbols[k]->tag));
|
||||
obstack_backslash (oout, symbols[k]->tag);
|
||||
sep = ", ";
|
||||
}
|
||||
obstack_1grow (oout, ']');
|
||||
|
||||
17
src/system.h
17
src/system.h
@@ -171,6 +171,23 @@ typedef size_t uintptr_t;
|
||||
# define obstack_sgrow(Obs, Str) \
|
||||
obstack_grow (Obs, Str, strlen (Str))
|
||||
|
||||
/* Output Str escaped to be a string.
|
||||
|
||||
For instance "\"foo\"" -> "\\\"foo\\\"". */
|
||||
|
||||
# define obstack_backslash(Obs, Str) \
|
||||
do { \
|
||||
char const *p__; \
|
||||
for (p__ = Str; *p__; p__++) \
|
||||
switch (*p__) \
|
||||
{ \
|
||||
case '"': obstack_sgrow (Obs, "\\\""); break; \
|
||||
case '\\': obstack_sgrow (Obs, "\\\\"); break; \
|
||||
default: obstack_1grow (Obs, *p__); break; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* Output Str escaped for our postprocessing (i.e., escape M4 special
|
||||
characters).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user