texinfo-commits
[Top][All Lists]
Advanced

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

[7141] parsetexi update (input stack re-jig)


From: Gavin D. Smith
Subject: [7141] parsetexi update (input stack re-jig)
Date: Wed, 27 Apr 2016 21:09:01 +0000

Revision: 7141
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7141
Author:   gavin
Date:     2016-04-27 21:09:00 +0000 (Wed, 27 Apr 2016)
Log Message:
-----------
parsetexi update (input stack re-jig)

Modified Paths:
--------------
    trunk/tp/parsetexi/api.c
    trunk/tp/parsetexi/handle_commands.c
    trunk/tp/parsetexi/input.c
    trunk/tp/parsetexi/input.h
    trunk/tp/parsetexi/macro.c
    trunk/tp/parsetexi/parser.c

Modified: trunk/tp/parsetexi/api.c
===================================================================
--- trunk/tp/parsetexi/api.c    2016-04-26 16:50:27 UTC (rev 7140)
+++ trunk/tp/parsetexi/api.c    2016-04-27 21:09:00 UTC (rev 7141)
@@ -57,7 +57,7 @@
 void
 parse_file (char *filename)
 {
-  debug_output = 1;
+  debug_output = 0;
   reset_parser ();
   parse_texi_file (filename);
 }
@@ -76,7 +76,7 @@
   ELEMENT *root;
   reset_parser ();
   root = new_element (ET_root_line);
-  input_push_text (strdup (string));
+  input_push_text (strdup (string), 0);
   Root = parse_texi (root);
 }
 
@@ -87,7 +87,7 @@
   ELEMENT *root;
   reset_parser ();
   root = new_element (ET_text_root);
-  input_push_text_with_line_nos (strdup (string));
+  input_push_text_with_line_nos (strdup (string), 1);
   Root = parse_texi (root);
 }
 
@@ -518,8 +518,12 @@
           STORE("line_nr", newSViv (line_nr->line_nr));
         }
 
-      /* TODO: macro. */
-      STORE("macro", newSVpv ("", 0));
+      if (line_nr->macro)
+        {
+          STORE("macro", newSVpv (line_nr->macro, 0));
+        }
+      else
+        STORE("macro", newSVpv ("", 0));
 #undef STORE
     }
 }

Modified: trunk/tp/parsetexi/handle_commands.c
===================================================================
--- trunk/tp/parsetexi/handle_commands.c        2016-04-26 16:50:27 UTC (rev 
7140)
+++ trunk/tp/parsetexi/handle_commands.c        2016-04-27 21:09:00 UTC (rev 
7141)
@@ -169,7 +169,7 @@
       if (!strchr (line, '\n'))
         {
           char *line2;
-          input_push_text (strdup (line));
+          input_push_text (strdup (line), 0);
           line2 = new_line ();
           if (line2)
             line = line2;
@@ -309,7 +309,6 @@
                 }
               else
                 {
-                  line_error ("@%s not meaningful within address@hidden' 
block");
                   line_error ("@%s not meaningful within address@hidden' 
block",
                               command_name(cmd),
                               command_name(parent->cmd));
@@ -552,12 +551,14 @@
           /* Check if if we should change an ET_empty_line_after_command
              element to ET_empty_spaces_after_command by looking ahead
              to see what comes next. */
-#if 0
           if (!strchr (line, '\n'))
             {
-              new_line ();
+              char *line2;
+              input_push_text (strdup (line), 0);
+              line2 = new_line ();
+              if (line2)
+                line = line2;
             }
-#endif
           spaces = strspn (line, whitespace_chars);
           if (spaces > 0)
             {

Modified: trunk/tp/parsetexi/input.c
===================================================================
--- trunk/tp/parsetexi/input.c  2016-04-26 16:50:27 UTC (rev 7140)
+++ trunk/tp/parsetexi/input.c  2016-04-27 21:09:00 UTC (rev 7141)
@@ -28,22 +28,21 @@
 enum input_type { IN_file, IN_text };
 
 typedef struct {
-    enum input_type type; /* IN_file or IN_text */
+    enum input_type type;
 
     FILE *file;
-    char *filename;
+    LINE_NR line_nr;
 
     char *text;  /* Input text to be parsed as Texinfo. */
     char *ptext; /* How far we are through 'text'.  Used to split 'text'
                     into lines. */
-    int line_number;
 } INPUT;
 
 static INPUT *input_stack = 0;
 static size_t input_number = 0;
 static size_t input_space = 0;
 
-/* Current filename and line number. */
+/* Current filename and line number.  Used for reporting. */
 LINE_NR line_nr;
 
 // 1961
@@ -104,6 +103,7 @@
               free (i->text);
               break;
             }
+          /* Split off a line of input. */
           p = strchrnul (i->ptext, '\n');
           new = strndup (i->ptext, p - i->ptext + 1);
           if (*p)
@@ -111,11 +111,12 @@
           else
             i->ptext = p; /* The next time, we will pop the input source. */
 
-          if (line_nr.line_nr != -1)
-            line_nr.line_nr++;
+          if (!i->line_nr.macro)
+            i->line_nr.line_nr++;
 
+          line_nr = i->line_nr;
+
           return new;
-          // what if it doesn't end in a newline ?
 
           break;
         case IN_file: // 1911
@@ -146,7 +147,9 @@
 
               // 1920 CPP_LINE_DIRECTIVES
 
-              line_nr.line_nr++;
+              i->line_nr.line_nr++;
+              line_nr = i->line_nr;
+
               return line;
             }
           free (line); line = 0;
@@ -168,35 +171,13 @@
             }
         }
       input_number--;
-      if (input_number > 0 && input_stack[input_number - 1].type == IN_file)
-        {
-          /* Restore LINE_NR. */
-          line_nr.line_nr = input_stack[input_number - 1].line_number;
-          line_nr.file_name = input_stack[input_number - 1].filename;
-        }
     }
   return 0;
 }
 
-static void
-save_line_nr (void)
-{
-  if (input_number == 0)
-    return;
-
-  if (input_stack[input_number - 1].type == IN_file)
-    {
-      input_stack[input_number - 1].line_number = line_nr.line_nr;
-    }
-}
-
-/* Store TEXT as a source for Texinfo content.  TEXT will be later free'd
-   and must be allocated on the heap. */
 void
-input_push_text (char *text)
+input_push (char *text, char *macro, char *filename, int line_number)
 {
-  save_line_nr ();
-
   if (input_number == input_space)
     {
       input_space++; input_space *= 1.5;
@@ -206,22 +187,34 @@
     }
 
   input_stack[input_number].type = IN_text;
+  input_stack[input_number].file = 0;
   input_stack[input_number].text = text;
   input_stack[input_number].ptext = text;
+
+  if (!macro)
+    line_number--;
+  input_stack[input_number].line_nr.line_nr = line_number;
+  input_stack[input_number].line_nr.file_name = filename;
+  input_stack[input_number].line_nr.macro = macro;
   input_number++;
+}
 
-  /* TODO: What goes in LINE_NR?  It depends whether this text is the result 
of 
-     a macro expansion, or was pushed back when reading the file preamble. */
+/* Store TEXT as a source for Texinfo content.  TEXT will be later free'd
+   and must be allocated on the heap.  MACRO is the name of a macro that
+   the text came from. */
+void
+input_push_text (char *text, char *macro)
+{
+  input_push (text, macro, 0, line_nr.line_nr);
 }
 
 /* Used in tests - like input_push_text, but the lines from the text have
    line numbers. */
 void
-input_push_text_with_line_nos (char *text)
+input_push_text_with_line_nos (char *text, int starting)
 {
-  input_push_text (text);
-  line_nr.line_nr = 0;
-  line_nr.file_name = 0;
+  input_push (text, 0, 0, starting);
+  input_stack[input_number - 1].type = IN_text;
 }
 
 
@@ -248,8 +241,6 @@
   FILE *stream;
   int i;
 
-  save_line_nr ();
-
   for (i = 0; i < include_dirs_number; i++)
     {
       /* TODO: The Perl code (in Common.pm, 'locate_include_file') handles a 
@@ -280,13 +271,13 @@
 
   input_stack[input_number].type = IN_file;
   input_stack[input_number].file = stream;
-  input_stack[input_number].filename = filename;
-  input_stack[input_number].line_number = 0;
+  input_stack[input_number].line_nr.file_name = filename;
+  input_stack[input_number].line_nr.line_nr = 0;
+  input_stack[input_number].line_nr.macro = 0;
+  input_stack[input_number].text = 0;
+  input_stack[input_number].ptext = 0;
   input_number++;
 
-  line_nr.line_nr = 0;
-  line_nr.file_name = filename;
-
   return;
 }
 

Modified: trunk/tp/parsetexi/input.h
===================================================================
--- trunk/tp/parsetexi/input.h  2016-04-26 16:50:27 UTC (rev 7140)
+++ trunk/tp/parsetexi/input.h  2016-04-27 21:09:00 UTC (rev 7141)
@@ -3,8 +3,9 @@
 char *new_line (void);
 char *next_text (void);
 
-void input_push_text (char *line);
-void input_push_text_with_line_nos (char *text);
+void input_push (char *text, char *macro, char *filename, int line_number);
+void input_push_text (char *line, char *macro);
+void input_push_text_with_line_nos (char *text, int starting);
 void input_push_file (char *filename);
 
 extern LINE_NR line_nr;

Modified: trunk/tp/parsetexi/macro.c
===================================================================
--- trunk/tp/parsetexi/macro.c  2016-04-26 16:50:27 UTC (rev 7140)
+++ trunk/tp/parsetexi/macro.c  2016-04-27 21:09:00 UTC (rev 7141)
@@ -415,6 +415,7 @@
 }
 
 // 3898
+/* CMD is the macro command. */
 ELEMENT *
 handle_macro (ELEMENT *current, char **line_inout, enum command_id cmd)
 {
@@ -471,9 +472,9 @@
 
   // 3961
   /* Put expansion in front of the current line. */
-  input_push_text (strdup (line));
+  input_push_text (strdup (line), 0);
   line = strchr (line, '\0');
-  input_push_text (expanded.text);
+  input_push_text (expanded.text, command_name(cmd));
 
   *line_inout = line;
   return current;

Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2016-04-26 16:50:27 UTC (rev 7140)
+++ trunk/tp/parsetexi/parser.c 2016-04-27 21:09:00 UTC (rev 7141)
@@ -164,9 +164,7 @@
         {
           /* This line is not part of the preamble.  Shove back
              into input stream. */
-          input_push_text (line);
-          if (line_nr.line_nr > 0)
-            line_nr.line_nr--;
+          input_push (line, 0, line_nr.file_name, line_nr.line_nr);
           break;
         }
 
@@ -1116,8 +1114,8 @@
                      in Report.pm.  */
 
                   line++; /* past '}' */
-                  input_push_text (strdup (line));
-                  input_push_text (strdup (value));
+                  input_push_text (strdup (line), 0);
+                  input_push_text (strdup (value), 0);
                   line = new_line ();
                 }
               retval = 1;




reply via email to

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