bison-patches
[Top][All Lists]
Advanced

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

FYI: Exp: literalchar


From: Akim Demaille
Subject: FYI: Exp: literalchar
Date: 14 Dec 2001 16:33:16 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Civil Service)

Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * src/lex.c (literalchar): Don't escape the special characters,
        just decode them, and keep them as char (before, eol was output as
        the 2 char string `\n' etc.).
        * src/output.c (output_rule_data): Use quotearg to output the
        token strings.

Index: src/lex.c
===================================================================
RCS file: /cvsroot/bison/bison/src/lex.c,v
retrieving revision 1.47
diff -u -u -r1.47 lex.c
--- src/lex.c 28 Nov 2001 22:28:01 -0000 1.47
+++ src/lex.c 14 Dec 2001 15:38:12 -0000
@@ -140,24 +140,16 @@
 }
 
 
-/*------------------------------------------------------------------.
-| Read one literal character from finput.  Process \ escapes.       |
-| Append the normalized string version of the char to OUT.  Assign  |
-| the character code to *PCODE. Return 1 unless the character is an |
-| unescaped `term' or \n report error for \n.                       |
-`------------------------------------------------------------------*/
-
-/* FIXME: We could directly work in the obstack, but that would make
-   it more difficult to move to quotearg some day.  So for the time
-   being, I prefer have literalchar behave like quotearg, and change
-   my mind later if I was wrong.  */
+/*-----------------------------------------------------------------.
+| Read one literal character from FINPUT.  Process \-escapes.      |
+| Append the char to OUT and assign it *PCODE. Return 1 unless the |
+| character is an unescaped `term' or \n report error for \n.      |
+`-----------------------------------------------------------------*/
 
 int
 literalchar (struct obstack *out, int *pcode, char term)
 {
   int c;
-  char buf[4096];
-  char *cp;
   int code;
   int wasquote = 0;
 
@@ -249,71 +241,8 @@
        }
     }                          /* has \ */
 
-  /* now fill BUF with the canonical name for this character as a
-     literal token.  Do not use what the user typed, so that `\012'
-     and `\n' can be interchangeable.  */
-
-  cp = buf;
-  if (code == term && wasquote)
-    *cp++ = code;
-  else if (code == '\\')
-    {
-      *cp++ = '\\';
-      *cp++ = '\\';
-    }
-  else if (code == '\'')
-    {
-      *cp++ = '\\';
-      *cp++ = '\'';
-    }
-  else if (code == '\"')
-    {
-      *cp++ = '\\';
-      *cp++ = '\"';
-    }
-  else if (code >= 040 && code < 0177)
-    *cp++ = code;
-  else if (code == '\t')
-    {
-      *cp++ = '\\';
-      *cp++ = 't';
-    }
-  else if (code == '\n')
-    {
-      *cp++ = '\\';
-      *cp++ = 'n';
-    }
-  else if (code == '\r')
-    {
-      *cp++ = '\\';
-      *cp++ = 'r';
-    }
-  else if (code == '\v')
-    {
-      *cp++ = '\\';
-      *cp++ = 'v';
-    }
-  else if (code == '\b')
-    {
-      *cp++ = '\\';
-      *cp++ = 'b';
-    }
-  else if (code == '\f')
-    {
-      *cp++ = '\\';
-      *cp++ = 'f';
-    }
-  else
-    {
-      *cp++ = '\\';
-      *cp++ = code / 0100 + '0';
-      *cp++ = ((code / 010) & 07) + '0';
-      *cp++ = (code & 07) + '0';
-    }
-  *cp = '\0';
-
   if (out)
-    obstack_sgrow (out, buf);
+    obstack_1grow (out, code);
   *pcode = code;
   return !wasquote;
 }
Index: src/output.c
===================================================================
RCS file: /cvsroot/bison/bison/src/output.c,v
retrieving revision 1.87
diff -u -u -r1.87 output.c
--- src/output.c 11 Dec 2001 20:19:44 -0000 1.87
+++ src/output.c 14 Dec 2001 15:38:13 -0000
@@ -234,22 +234,14 @@
 
   j = 0;
   for (i = 0; i < nsyms; i++)
-    /* this used to be i<=nsyms, but that output a final "" symbol
-       almost by accident */
     {
+      /* Be sure not to use twice the same quotearg slot. */
+      const char *cp =
+       quotearg_n_style (1, c_quoting_style,
+                         quotearg_style (escape_quoting_style, tags[i]));
       /* Width of the next token, including the two quotes, the coma
         and the space.  */
-      int strsize = 4;
-      char *p;
-
-      for (p = tags[i]; p && *p; p++)
-       if (*p == '"' || *p == '\\' || *p == '\n' || *p == '\t'
-           || *p == '\b')
-         strsize += 2;
-       else if (*p < 040 || *p >= 0177)
-         strsize += 4;
-       else
-         strsize++;
+      int strsize = strlen (cp) + 2;
 
       if (j + strsize > 75)
        {
@@ -257,24 +249,8 @@
          j = 2;
        }
 
-      obstack_1grow (&output_obstack, '\"');
-      for (p = tags[i]; p && *p; p++)
-       {
-         if (*p == '"' || *p == '\\')
-           obstack_fgrow1 (&output_obstack, "\\%c", *p);
-         else if (*p == '\n')
-           obstack_sgrow (&output_obstack, "\\n");
-         else if (*p == '\t')
-           obstack_sgrow (&output_obstack, "\\t");
-         else if (*p == '\b')
-           obstack_sgrow (&output_obstack, "\\b");
-         else if (*p < 040 || *p >= 0177)
-           obstack_fgrow1 (&output_obstack, "\\%03o", *p);
-         else
-           obstack_1grow (&output_obstack, *p);
-       }
-
-      obstack_sgrow (&output_obstack, "\", ");
+      obstack_sgrow (&output_obstack, cp);
+      obstack_sgrow (&output_obstack, ", ");
       j += strsize;
     }
   /* add a NULL entry to list of tokens */



reply via email to

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