bug-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch for m4 quoting bug in token names


From: Paul Eggert
Subject: patch for m4 quoting bug in token names
Date: Sun, 06 Mar 2005 22:45:18 -0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux)

Mátyás Forstner (IJ/ETH) <address@hidden> writes:

> If i change the name of TOK_Begin and TOK_End, then everything is
> OK. Perhaps '[' and ']' should be escaped somehow for m4.

Thanks for the bug report.  Your analysis is correct.  I installed
this patch into Bison to fix your problem, plus remove some
unnecessary M4 quoting that I found.

I would have added a test case for your problem, but I couldn't easily
navigate through the M4 quoting issues in autotest.

2005-03-06  Paul Eggert  <address@hidden>

        * src/output.c (escaped_output): Renamed from
        escaped_file_name_output, since we now use it for symbol tags as
        well.  All uses changed.
        (symbol_destructors_output, symbol_printers_output):
        Escape symbol tags too.
        Problem reported by Matyas Forstner in
        <http://lists.gnu.org/archive/html/bug-bison/2005-03/msg00009.html>.

        * src/muscle_tab.c (muscle_code_grow): Don't quote numbers; it's
        not needed.
        * src/output.c (user_actions_output, token_definitions_output,
        symbol_destructors_output, symbol_printers_output): Likewise.
        * src/reader.c (prologue_augment): Likewise.
        * src/scan-gram.l (handle_action_dollar, handle_action_at): Likewise.

Index: src/muscle_tab.c
===================================================================
RCS file: /cvsroot/bison/bison/src/muscle_tab.c,v
retrieving revision 1.33
diff -p -u -r1.33 muscle_tab.c
--- src/muscle_tab.c    10 Dec 2004 07:50:44 -0000      1.33
+++ src/muscle_tab.c    7 Mar 2005 06:38:09 -0000
@@ -1,6 +1,7 @@
 /* Muscle table manager for Bison.
 
-   Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software
+   Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -163,7 +164,7 @@ void
 muscle_code_grow (const char *key, const char *val, location loc)
 {
   char *extension = NULL;
-  obstack_fgrow1 (&muscle_obstack, "]b4_syncline([[%d]], [[", loc.start.line);
+  obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, [[", loc.start.line);
   MUSCLE_OBSTACK_SGROW (&muscle_obstack,
                        quotearg_style (c_quoting_style, loc.start.file));
   obstack_sgrow (&muscle_obstack, "]])[\n");
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.229
diff -p -u -r1.229 output.c
--- src/output.c        17 Dec 2004 20:29:19 -0000      1.229
+++ src/output.c        7 Mar 2005 06:38:09 -0000
@@ -1,6 +1,6 @@
 /* Output the generated parsing program for Bison.
 
-   Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004
+   Copyright (C) 1984, 1986, 1989, 1992, 2000, 2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
@@ -113,17 +113,17 @@ GENERATE_MUSCLE_INSERT_TABLE(muscle_inse
 GENERATE_MUSCLE_INSERT_TABLE(muscle_insert_state_number_table, state_number)
 
 
-/*----------------------------------------------------------------------.
-| Print to OUT a representation of FILENAME escaped both for C and M4.  |
-`----------------------------------------------------------------------*/
+/*--------------------------------------------------------------------.
+| Print to OUT a representation of STRING escaped both for C and M4.  |
+`--------------------------------------------------------------------*/
 
 static void
-escaped_file_name_output (FILE *out, char const *filename)
+escaped_output (FILE *out, char const *string)
 {
   char const *p;
   fprintf (out, "[[");
 
-  for (p = quotearg_style (c_quoting_style, filename); *p; p++)
+  for (p = quotearg_style (c_quoting_style, string); *p; p++)
     switch (*p)
       {
       case '$': fputs ("$][", out); break;
@@ -300,9 +300,9 @@ user_actions_output (FILE *out)
       {
        fprintf (out, "  case %d:\n", r + 1);
 
-       fprintf (out, "]b4_syncline([[%d]], ",
+       fprintf (out, "]b4_syncline(%d, ",
                 rules[r].action_location.start.line);
-       escaped_file_name_output (out, rules[r].action_location.start.file);
+       escaped_output (out, rules[r].action_location.start.file);
        fprintf (out, ")[\n");
        fprintf (out, "    %s\n    break;\n\n",
                 rules[r].action);
@@ -375,7 +375,7 @@ token_definitions_output (FILE *out)
       if (strchr (sym->tag, '.') || strchr (sym->tag, '$'))
        continue;
 
-      fprintf (out, "%s[[[%s]], [%d]]",
+      fprintf (out, "%s[[[%s]], %d]",
               sep, sym->tag, number);
       sep = ",\n";
     }
@@ -404,12 +404,10 @@ symbol_destructors_output (FILE *out)
           destructor, optional typename.  */
        fprintf (out, "%s[", sep);
        sep = ",\n";
-       escaped_file_name_output (out, sym->destructor_location.start.file);
-       fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]]",
-                sym->destructor_location.start.line,
-                sym->tag,
-                sym->number,
-                sym->destructor);
+       escaped_output (out, sym->destructor_location.start.file);
+       fprintf (out, ", %d, ", sym->destructor_location.start.line);
+       escaped_output (out, sym->tag);
+       fprintf (out, ", %d, [[%s]]", sym->number, sym->destructor);
        if (sym->type_name)
          fprintf (out, ", [[%s]]", sym->type_name);
        fputc (']', out);
@@ -439,12 +437,10 @@ symbol_printers_output (FILE *out)
           printer, optional typename.  */
        fprintf (out, "%s[", sep);
        sep = ",\n";
-       escaped_file_name_output (out, sym->printer_location.start.file);
-       fprintf (out, ", [[%d]], [[%s]], [[%d]], [[%s]]",
-                sym->printer_location.start.line,
-                sym->tag,
-                sym->number,
-                sym->printer);
+       escaped_output (out, sym->printer_location.start.file);
+       fprintf (out, ", %d, ", sym->printer_location.start.line);
+       escaped_output (out, sym->tag);
+       fprintf (out, ", %d, [[%s]]", sym->number, sym->printer);
        if (sym->type_name)
          fprintf (out, ", [[%s]]", sym->type_name);
        fputc (']', out);
Index: src/reader.c
===================================================================
RCS file: /cvsroot/bison/bison/src/reader.c,v
retrieving revision 1.235
diff -p -u -r1.235 reader.c
--- src/reader.c        10 Dec 2004 07:50:44 -0000      1.235
+++ src/reader.c        7 Mar 2005 06:38:09 -0000
@@ -1,7 +1,7 @@
 /* Input parser for Bison
 
-   Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002, 2003
-   Free Software Foundation, Inc.
+   Copyright (C) 1984, 1986, 1989, 1992, 1998, 2000, 2001, 2002, 2003,
+   2005 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -74,7 +74,7 @@ prologue_augment (const char *prologue, 
   struct obstack *oout =
     !typed ? &pre_prologue_obstack : &post_prologue_obstack;
 
-  obstack_fgrow1 (oout, "]b4_syncline([[%d]], [[", loc.start.line);
+  obstack_fgrow1 (oout, "]b4_syncline(%d, [[", loc.start.line);
   MUSCLE_OBSTACK_SGROW (oout,
                        quotearg_style (c_quoting_style, loc.start.file));
   obstack_sgrow (oout, "]])[\n");
Index: src/scan-gram.l
===================================================================
RCS file: /cvsroot/bison/bison/src/scan-gram.l,v
retrieving revision 1.70
diff -p -u -r1.70 scan-gram.l
--- src/scan-gram.l     8 Aug 2004 04:57:06 -0000       1.70
+++ src/scan-gram.l     7 Mar 2005 06:38:09 -0000
@@ -1,6 +1,6 @@
 /* Bison Grammar Scanner                             -*- C -*-
 
-   Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
    This file is part of Bison, the GNU Compiler Compiler.
 
@@ -413,7 +413,7 @@ splice       (\\[ \f\t\v]*\n)*
     unsigned long int c = strtoul (yytext + 1, 0, 8);
     if (UCHAR_MAX < c)
       complain_at (*loc, _("invalid escape sequence: %s"), quote (yytext));
-    else if (! c) 
+    else if (! c)
       complain_at (*loc, _("invalid null character: %s"), quote (yytext));
     else
       obstack_1grow (&obstack_for_string, c);
@@ -805,7 +805,7 @@ handle_action_dollar (char *text, locati
          if (!type_name)
            type_name = "";
          obstack_fgrow3 (&obstack_for_string,
-                         "]b4_rhs_value([%d], [%d], [%s])[",
+                         "]b4_rhs_value(%d, %d, [%s])[",
                          rule_length, n, type_name);
        }
       else
@@ -874,7 +874,7 @@ handle_action_at (char *text, location l
       if (INT_MIN <= num && num <= rule_length && ! get_errno ())
        {
          int n = num;
-         obstack_fgrow2 (&obstack_for_string, "]b4_rhs_location([%d], [%d])[",
+         obstack_fgrow2 (&obstack_for_string, "]b4_rhs_location(%d, %d)[",
                          rule_length, n);
        }
       else




reply via email to

[Prev in Thread] Current Thread [Next in Thread]