texinfo-commits
[Top][All Lists]
Advanced

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

[7523] parsetexi macros


From: gavinsmith0123
Subject: [7523] parsetexi macros
Date: Sun, 20 Nov 2016 18:20:26 +0000 (UTC)

Revision: 7523
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7523
Author:   gavin
Date:     2016-11-20 18:20:26 +0000 (Sun, 20 Nov 2016)
Log Message:
-----------
parsetexi macros

Modified Paths:
--------------
    trunk/tp/parsetexi/errors.c
    trunk/tp/parsetexi/errors.h
    trunk/tp/parsetexi/macro.c
    trunk/tp/parsetexi/macro.h
    trunk/tp/parsetexi/parser.c
    trunk/tp/parsetexi/tree_types.h

Modified: trunk/tp/parsetexi/errors.c
===================================================================
--- trunk/tp/parsetexi/errors.c 2016-11-20 16:45:15 UTC (rev 7522)
+++ trunk/tp/parsetexi/errors.c 2016-11-20 18:20:26 UTC (rev 7523)
@@ -25,8 +25,6 @@
 #include "dump_perl.h"
 #include "errors.h"
 
-enum error_type { error, warning };
-
 typedef struct {
     char *message;
     enum error_type type;
@@ -64,6 +62,16 @@
 }
 
 void
+line_error_ext (enum error_type type, LINE_NR *cmd_line_nr,
+                char *format, ...)
+{
+  va_list v;
+
+  va_start (v, format);
+  line_error_internal (type, cmd_line_nr, format, v);
+}
+
+void
 line_error (char *format, ...)
 {
   va_list v;

Modified: trunk/tp/parsetexi/errors.h
===================================================================
--- trunk/tp/parsetexi/errors.h 2016-11-20 16:45:15 UTC (rev 7522)
+++ trunk/tp/parsetexi/errors.h 2016-11-20 18:20:26 UTC (rev 7523)
@@ -4,5 +4,7 @@
 void command_error (ELEMENT *e, char *format, ...);
 void command_warn (ELEMENT *e, char *format, ...);
 void wipe_errors (void);
+void line_error_ext (enum error_type type, LINE_NR *cmd_line_nr,
+                     char *format, ...);
 
 char *dump_errors (void);

Modified: trunk/tp/parsetexi/macro.c
===================================================================
--- trunk/tp/parsetexi/macro.c  2016-11-20 16:45:15 UTC (rev 7522)
+++ trunk/tp/parsetexi/macro.c  2016-11-20 18:20:26 UTC (rev 7523)
@@ -25,12 +25,6 @@
 #include "input.h"
 #include "errors.h"
 
-typedef struct {
-    char *macro_name;
-    ELEMENT *element;
-    enum command_id cmd;
-} MACRO;
-
 static MACRO *macro_list;
 static size_t macro_number;
 static size_t macro_space;
@@ -38,8 +32,6 @@
 
 /* Macro definition. */
 
-static MACRO *lookup_macro (enum command_id cmd);
-
 void
 new_macro (char *name, ELEMENT *macro)
 {
@@ -154,8 +146,14 @@
         {
           // 1126 - argument is completely whitespace
           if (*q == ',')
-            line_error ("bad or empty @%s formal argument:",
-                        command_name(cmd));
+            {
+              line_error ("bad or empty @%s formal argument: ",
+                          command_name(cmd));
+              arg = new_element (ET_macro_arg);
+              add_to_element_args (macro, arg);
+              text_append_n (&arg->text, "", 0);
+              add_extra_string (macro, "invalid_syntax", "1");
+            }
         }
       else
         {
@@ -243,12 +241,14 @@
   char *pline = line;
   TEXT arg;
   int braces_level = 1;
+  int args_total;
 
   char **arg_list = 0;
   size_t arg_number = 0;
   size_t arg_space = 0;
 
   arg_list = malloc (sizeof (char *));
+  args_total = macro->args.number - 1;
 
   text_init (&arg);
 
@@ -314,30 +314,40 @@
             }
 
           // 2021 check for too many args
+          if (*sep == '}' || arg_number < args_total - 1)
+            {
+              /* Add the last argument read to the list. */
+              if (arg_number == arg_space)
+                {
+                  arg_list = realloc (arg_list,
+                                      (1+(arg_space += 5)) * sizeof (char *));
+                  /* Include space for terminating null element. */
+                  if (!arg_list)
+                    abort ();
+                }
+              if (arg.space > 0)
+                arg_list[arg_number++] = arg.text;
+              else
+                arg_list[arg_number++] = strdup ("");
+              text_init (&arg);
+              // TODO: is "@m {     }" one empty argument or none?
 
-          /* Add the last argument read to the list. */
-          if (arg_number == arg_space)
+              debug ("MACRO NEW ARG");
+              pline = sep + 1;
+
+              if (*sep == ',')
+                pline += strspn (pline, whitespace_chars);
+            }
+          else
             {
-              arg_list = realloc (arg_list,
-                                  (1+(arg_space += 5)) * sizeof (char *));
-              /* Include space for terminating null element. */
-              if (!arg_list)
-                abort ();
+              if (args_total != 1)
+                line_error ("macro `%s' called with too many args",
+                            command_name(cmd));
+              text_append_n (&arg, ",", 1);
+              pline = sep + 1;
             }
-          if (arg.space > 0)
-            arg_list[arg_number++] = arg.text;
-          else
-            arg_list[arg_number++] = strdup ("");
-          text_init (&arg);
-          // TODO: is "@m {     }" one empty argument or none?
-
-          debug ("MACRO NEW ARG");
-          pline = sep + 1;
           break;
         }
-
-      if (*sep == ',')
-        pline += strspn (pline, whitespace_chars);
     }
 
   debug ("END MACRO ARGS EXPANSION");
@@ -430,7 +440,7 @@
     }
 }
 
-static MACRO *
+MACRO *
 lookup_macro (enum command_id cmd)
 {
   int i;

Modified: trunk/tp/parsetexi/macro.h
===================================================================
--- trunk/tp/parsetexi/macro.h  2016-11-20 16:45:15 UTC (rev 7522)
+++ trunk/tp/parsetexi/macro.h  2016-11-20 18:20:26 UTC (rev 7523)
@@ -4,6 +4,8 @@
 ELEMENT *handle_macro (ELEMENT *current, char **line_inout,
                        enum command_id cmd_id);
 void delete_macro (char *name);
+MACRO *lookup_macro (enum command_id cmd);
+
 void store_value (char *name, char *value);
 char *fetch_value (char *name, int len);
 INFO_ENCLOSE *lookup_infoenclose (enum command_id cmd);

Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2016-11-20 16:45:15 UTC (rev 7522)
+++ trunk/tp/parsetexi/parser.c 2016-11-20 18:20:26 UTC (rev 7523)
@@ -847,11 +847,29 @@
                   || (current->parent->cmd != CM_macro
                       && current->parent->cmd != CM_rmacro)))
             {
-              if (!lookup_extra_key (current, "invalid_syntax"))
+              char *name;
+              enum command_id existing;
+              if (current->args.number > 0)
                 {
-                  char *name;
                   name = element_text (args_child_by_index (current, 0));
-                  new_macro (name, current); // 3808
+
+                  existing = lookup_command (name);
+                  if (existing)
+                    {
+                      MACRO *macro;
+                      macro = lookup_macro (existing);
+                      if (macro)
+                        {
+                          line_error_ext (1, &current->line_nr,
+                             "macro `%s' previously defined", name);
+                          line_error_ext (1, &macro->element->line_nr,
+                             "here is the previous definition of `%s'", name);
+                        }
+                    }
+                  if (!lookup_extra_key (current, "invalid_syntax"))
+                    {
+                      new_macro (name, current); // 3808
+                    }
                 }
             }
 

Modified: trunk/tp/parsetexi/tree_types.h
===================================================================
--- trunk/tp/parsetexi/tree_types.h     2016-11-20 16:45:15 UTC (rev 7522)
+++ trunk/tp/parsetexi/tree_types.h     2016-11-20 18:20:26 UTC (rev 7523)
@@ -215,4 +215,12 @@
     char *normalized;
 } EXTRA_FLOAT_TYPE;
 
+enum error_type { error, warning };
 
+typedef struct {
+    char *macro_name;
+    ELEMENT *element;
+    enum command_id cmd;
+} MACRO;
+
+




reply via email to

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