[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/3] muscles: fix another occurrence of unescaped type name
From: |
Akim Demaille |
Subject: |
[PATCH 1/3] muscles: fix another occurrence of unescaped type name |
Date: |
Fri, 27 Jul 2012 17:13:21 +0200 |
* 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.
---
src/output.c | 37 +++++++++++++++++++++++++------------
src/symtab.h | 7 ++++++-
tests/input.at | 13 +++++++++++++
3 files changed, 44 insertions(+), 13 deletions(-)
diff --git a/src/output.c b/src/output.c
index e157460..d52a711 100644
--- a/src/output.c
+++ b/src/output.c
@@ -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)
-/*--------------------------------------------------------------------.
-| 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
-escaped_output (FILE *out, char const *string)
+quoted_output (FILE *out, char const *cp)
{
- char const *p;
fprintf (out, "[[");
- for (p = quotearg_style (c_quoting_style, string); *p; p++)
- switch (*p)
+ for (; *cp; cp++)
+ switch (*cp)
{
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, "]]");
}
+/*----------------------------------------------------------------.
+| 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 |
@@ -299,7 +309,7 @@ user_actions_output (FILE *out)
{
fprintf (out, "b4_case(%d, [b4_syncline(%d, ", r + 1,
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);
}
fputs ("])\n\n", out);
@@ -405,12 +415,15 @@ symbol_code_props_output (FILE *out, char const *what,
code, optional typename. */
fprintf (out, "%s[", sep);
sep = ",\n";
- escaped_output (out, loc.start.file);
+ string_output (out, loc.start.file);
fprintf (out, ", %d, ", loc.start.line);
- escaped_output (out, sym->tag);
+ quoted_output (out, sym->tag);
fprintf (out, ", %d, [[%s]]", sym->number, code);
if (sym->type_name)
- fprintf (out, ", [[%s]]", sym->type_name);
+ {
+ fputs (", ", out);
+ quoted_output (out, sym->type_name);
+ }
fputc (']', out);
}
}
diff --git a/src/symtab.h b/src/symtab.h
index abcafa6..7d8cf98 100644
--- a/src/symtab.h
+++ b/src/symtab.h
@@ -60,7 +60,12 @@ struct symbol
/** The location of its first occurrence. */
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;
/** Its \c \%type's location. */
diff --git a/tests/input.at b/tests/input.at
index eb98cca..82d97f5 100644
--- a/tests/input.at
+++ b/tests/input.at
@@ -1392,6 +1392,19 @@ m4_pushdef([AT_TEST],
$$;
$<$1(DEAD %initial-action)>$
};
+%printer
+{
+ $$
+ $<$1(DEAD %printer)>$
+} <> <*>;
+%lex-param
+{
+ $1(DEAD %lex-param)
+};
+%parse-param
+{
+ $1(DEAD %parse-param)
+};
%%
exp:
a a[last]
--
1.7.11.3