muscles: fix another occurrence of unescaped type name

* src/output.c (quoted_output): Split into...
(quoted_output, string_output): these.
Use the former when outputting a type_name.
* tests/input.at: Check this case.
* src/symtab.h: Comment changes.
This commit is contained in:
Akim Demaille
2012-07-26 14:41:55 +02:00
parent 0e164d43d1
commit 9a86ee6058
3 changed files with 44 additions and 13 deletions

View File

@@ -110,29 +110,39 @@ GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_item_number_table, item_number)
GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number) GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number)
/*--------------------------------------------------------------------. /*----------------------------------------------------------------.
| Print to OUT a representation of STRING escaped both for C and M4. | | Print to OUT a representation of CP quoted and escaped for M4. |
`--------------------------------------------------------------------*/ `----------------------------------------------------------------*/
static void static void
escaped_output (FILE *out, char const *string) quoted_output (FILE *out, char const *cp)
{ {
char const *p;
fprintf (out, "[["); fprintf (out, "[[");
for (p = quotearg_style (c_quoting_style, string); *p; p++) for (; *cp; cp++)
switch (*p) switch (*cp)
{ {
case '$': fputs ("$][", out); break; case '$': fputs ("$][", out); break;
case '@': fputs ("@@", out); break; case '@': fputs ("@@", out); break;
case '[': fputs ("@{", out); break; case '[': fputs ("@{", out); break;
case ']': fputs ("@}", out); break; case ']': fputs ("@}", out); break;
default: fputc (*p, out); break; default: fputc (*cp, out); break;
} }
fprintf (out, "]]"); fprintf (out, "]]");
} }
/*----------------------------------------------------------------.
| Print to OUT a representation of STRING quoted and escaped both |
| for C and M4. |
`----------------------------------------------------------------*/
static void
string_output (FILE *out, char const *string)
{
quoted_output (out, quotearg_style (c_quoting_style, string));
}
/*------------------------------------------------------------------. /*------------------------------------------------------------------.
| Prepare the muscles related to the symbols: translate, tname, and | | Prepare the muscles related to the symbols: translate, tname, and |
@@ -299,7 +309,7 @@ user_actions_output (FILE *out)
{ {
fprintf (out, "b4_case(%d, [b4_syncline(%d, ", r + 1, fprintf (out, "b4_case(%d, [b4_syncline(%d, ", r + 1,
rules[r].action_location.start.line); rules[r].action_location.start.line);
escaped_output (out, rules[r].action_location.start.file); string_output (out, rules[r].action_location.start.file);
fprintf (out, ")\n[ %s]])\n\n", rules[r].action); fprintf (out, ")\n[ %s]])\n\n", rules[r].action);
} }
fputs ("])\n\n", out); fputs ("])\n\n", out);
@@ -405,12 +415,15 @@ symbol_code_props_output (FILE *out, char const *what,
code, optional typename. */ code, optional typename. */
fprintf (out, "%s[", sep); fprintf (out, "%s[", sep);
sep = ",\n"; sep = ",\n";
escaped_output (out, loc.start.file); string_output (out, loc.start.file);
fprintf (out, ", %d, ", loc.start.line); fprintf (out, ", %d, ", loc.start.line);
escaped_output (out, sym->tag); quoted_output (out, sym->tag);
fprintf (out, ", %d, [[%s]]", sym->number, code); fprintf (out, ", %d, [[%s]]", sym->number, code);
if (sym->type_name) if (sym->type_name)
fprintf (out, ", [[%s]]", sym->type_name); {
fputs (", ", out);
quoted_output (out, sym->type_name);
}
fputc (']', out); fputc (']', out);
} }
} }

View File

@@ -60,7 +60,12 @@ struct symbol
/** The location of its first occurrence. */ /** The location of its first occurrence. */
location location; location location;
/** Its \c \%type. */ /** Its \c \%type.
Beware that this is the type_name as was entered by the user,
including silly things such as "]" if she entered "%token <]> t".
Therefore, when outputting type_name to M4, be sure to escape it
into "@}". See quoted_output for instance. */
uniqstr type_name; uniqstr type_name;
/** Its \c \%type's location. */ /** Its \c \%type's location. */

View File

@@ -1392,6 +1392,19 @@ m4_pushdef([AT_TEST],
$$; $$;
$<$1(DEAD %initial-action)>$ $<$1(DEAD %initial-action)>$
}; };
%printer
{
$$
$<$1(DEAD %printer)>$
} <> <*>;
%lex-param
{
$1(DEAD %lex-param)
};
%parse-param
{
$1(DEAD %parse-param)
};
%% %%
exp: exp:
a a[last] a a[last]