]> git.saurik.com Git - bison.git/commitdiff
obstack_quote: escape and quote for M4
authorAkim Demaille <akim@lrde.epita.fr>
Thu, 26 Jul 2012 10:12:38 +0000 (12:12 +0200)
committerAkim Demaille <akim@lrde.epita.fr>
Thu, 26 Jul 2012 12:20:18 +0000 (14:20 +0200)
* src/system.h (obstack_quote): New.
* src/muscle-tab.c: Use it instead of obstack_escape where applicable.
* src/scan-code.l: Since obstack_quote supports NULL, leave type_name
as NULL instead of defaulting to "".

src/muscle-tab.c
src/scan-code.l
src/system.h

index a498b15b5c69cf421befd7dd26b6f2b1dc310c86..5c624982a9a7795cfd3dfb5b17aa53c5aa97f0fe 100644 (file)
@@ -177,10 +177,10 @@ static void
 muscle_syncline_grow (char const *key, location loc)
 {
   char *extension = NULL;
-  obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, [[", loc.start.line);
-  obstack_escape (&muscle_obstack,
-                  quotearg_style (c_quoting_style, loc.start.file));
-  obstack_sgrow (&muscle_obstack, "]])[");
+  obstack_fgrow1 (&muscle_obstack, "]b4_syncline(%d, ", loc.start.line);
+  obstack_quote (&muscle_obstack,
+                 quotearg_style (c_quoting_style, loc.start.file));
+  obstack_sgrow (&muscle_obstack, ")[");
   obstack_1grow (&muscle_obstack, 0);
   extension = obstack_finish (&muscle_obstack);
   muscle_grow (key, extension, "");
@@ -205,11 +205,11 @@ void muscle_pair_list_grow (const char *muscle,
                            const char *a1, const char *a2)
 {
   char *pair;
-  obstack_sgrow (&muscle_obstack, "[[[");
-  obstack_escape (&muscle_obstack, a1);
-  obstack_sgrow (&muscle_obstack, "]], [[");
-  obstack_escape (&muscle_obstack, a2);
-  obstack_sgrow (&muscle_obstack, "]]]");
+  obstack_sgrow (&muscle_obstack, "[");
+  obstack_quote (&muscle_obstack, a1);
+  obstack_sgrow (&muscle_obstack, "");
+  obstack_quote (&muscle_obstack, a2);
+  obstack_sgrow (&muscle_obstack, "]");
   obstack_1grow (&muscle_obstack, 0);
   pair = obstack_finish (&muscle_obstack);
   muscle_grow (muscle, pair, ",\n");
index 785f386dc8f719af54b48ad72eb822acbf13e4c9..bc2cd58050b0fb112eb90e8da05ac2e247c609c1 100644 (file)
@@ -762,7 +762,6 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
             }
           else
             untyped_var_seen = true;
-          type_name = "";
         }
 
       obstack_fgrow1 (&obstack_for_string,
@@ -783,7 +782,6 @@ handle_action_dollar (symbol_list *rule, char *text, location dollar_loc)
                          cp, quote (effective_rule->content.sym->tag));
           else
             untyped_var_seen = true;
-          type_name = "";
         }
 
       obstack_fgrow3 (&obstack_for_string,
index 06224596b283af564c85167142886184a65f5091..06fd0f0a9d578901a14b14a3e4804dc4f660142d 100644 (file)
@@ -212,6 +212,28 @@ typedef size_t uintptr_t;
   } while (0)
 
 
+/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
+   for our postprocessing (i.e., escape M4 special characters).  If
+   Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
+   programming easier (m4_ifval can be used).
+
+   For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
+
+# define obstack_quote(Obs, Str)                \
+  do {                                          \
+    char const* obstack_quote_p = Str;          \
+    if (obstack_quote_p && obstack_quote_p[0])  \
+      {                                         \
+        obstack_sgrow (Obs, "[[");              \
+        obstack_escape (Obs, obstack_quote_p);  \
+        obstack_sgrow (Obs, "]]");              \
+      }                                         \
+    else                                        \
+      obstack_sgrow (Obs, "[]");                \
+  } while (0)
+
+
+
 
 
 /*-----------------------------------------.