bison-patches
[Top][All Lists]
Advanced

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

style: avoid lengthy actions


From: Akim Demaille
Subject: style: avoid lengthy actions
Date: Tue, 20 Nov 2018 20:05:13 +0100

commit e0de1020ea44acb561d559fa6236abd19a4570e6
Author: Akim Demaille <address@hidden>
Date:   Tue Nov 20 13:56:01 2018 +0100

    style: avoid lengthy actions
    
    We also lack a consistent naming for directive implementations.
    `directive_skeleton` is too long, `percent_skeleton` is not very nice
    looking, `process_skeleton` looks ambiguous, `do_skeleton` is somewhat
    ambiguous too, but seems a better track.
    
    * src/parse-gram.y (version_check): Rename as...
    (do_require): this.
    (do_skeleton): New.
    Use it.

diff --git a/src/parse-gram.y b/src/parse-gram.y
index f8716f59..11b2432f 100644
--- a/src/parse-gram.y
+++ b/src/parse-gram.y
@@ -82,7 +82,11 @@
      string from the scanner (should be CODE). */
   static char const *translate_code_braceless (char *code, location loc);
 
-  static void version_check (location const *loc, char const *version);
+  /* Handle a %require directive.  */
+  static void do_require (location const *loc, char const *version);
+
+  /* Handle a %skeleton directive.  */
+  static void do_skeleton (location const *loc, char const *skel);
 
   static void gram_error (location const *, char const *);
 
@@ -308,31 +312,8 @@ prologue_declaration:
 | "%nondeterministic-parser"    { nondeterministic_parser = true; }
 | "%output" STRING              { spec_outfile = $2; }
 | "%param" { current_param = $1; } params { current_param = param_none; }
-| "%require" STRING             { version_check (&@2, $2); }
-| "%skeleton" STRING
-    {
-      char const *skeleton_user = $2;
-      if (strchr (skeleton_user, '/'))
-        {
-          size_t dir_length = strlen (current_file);
-          char *skeleton_build;
-          while (dir_length && current_file[dir_length - 1] != '/')
-            --dir_length;
-          while (dir_length && current_file[dir_length - 1] == '/')
-            --dir_length;
-          skeleton_build =
-            xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
-          if (dir_length > 0)
-            {
-              memcpy (skeleton_build, current_file, dir_length);
-              skeleton_build[dir_length++] = '/';
-            }
-          strcpy (skeleton_build + dir_length, skeleton_user);
-          skeleton_user = uniqstr_new (skeleton_build);
-          free (skeleton_build);
-        }
-      skeleton_arg (skeleton_user, grammar_prio, @1);
-    }
+| "%require" STRING             { do_require (&@2, $2); }
+| "%skeleton" STRING            { do_skeleton (&@2, $2); }
 | "%token-table"                { token_table_flag = true; }
 | "%verbose"                    { report_flag |= report_states; }
 | "%yacc"                       { yacc_flag = true; }
@@ -802,7 +783,7 @@ add_param (param_type type, char *decl, location loc)
 
 
 static void
-version_check (location const *loc, char const *version)
+do_require (location const *loc, char const *version)
 {
   /* Changes of behavior are only on minor version changes, so "3.0.5"
      is the same as "3.0". */
@@ -839,6 +820,32 @@ version_check (location const *loc, char const *version)
     }
 }
 
+static void
+do_skeleton (location const *loc, char const *skel)
+{
+  char const *skeleton_user = skel;
+  if (strchr (skeleton_user, '/'))
+    {
+      size_t dir_length = strlen (current_file);
+      while (dir_length && current_file[dir_length - 1] != '/')
+        --dir_length;
+      while (dir_length && current_file[dir_length - 1] == '/')
+        --dir_length;
+      char *skeleton_build =
+        xmalloc (dir_length + 1 + strlen (skeleton_user) + 1);
+      if (dir_length > 0)
+        {
+          memcpy (skeleton_build, current_file, dir_length);
+          skeleton_build[dir_length++] = '/';
+        }
+      strcpy (skeleton_build + dir_length, skeleton_user);
+      skeleton_user = uniqstr_new (skeleton_build);
+      free (skeleton_build);
+    }
+  skeleton_arg (skeleton_user, grammar_prio, *loc);
+}
+
+
 static void
 gram_error (location const *loc, char const *msg)
 {




reply via email to

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