texinfo-commits
[Top][All Lists]
Advanced

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

branch master updated: * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _p


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _parse_texi_document), tp/Texinfo/XS/parsetexi/api.c (parse_file), tp/Texinfo/XS/parsetexi/parser.c (parse_texi_document): split the entry point for parse_texi_file, using parse_texi_document() for the part doing the parsing. In the XS parser move the code related to file opening to parse_file() and remove parse_texi_file().
Date: Sun, 09 Jan 2022 13:15:26 -0500

This is an automated email from the git hooks/post-receive script.

pertusus pushed a commit to branch master
in repository texinfo.

The following commit(s) were added to refs/heads/master by this push:
     new ad02815ce2 * tp/Texinfo/ParserNonXS.pm (parse_texi_file, 
_parse_texi_document), tp/Texinfo/XS/parsetexi/api.c (parse_file), 
tp/Texinfo/XS/parsetexi/parser.c (parse_texi_document): split the entry point 
for parse_texi_file, using parse_texi_document() for the part doing the 
parsing.  In the XS parser move the code related to file opening to 
parse_file() and remove parse_texi_file().
ad02815ce2 is described below

commit ad02815ce26bfb74978b3fcfb905963c347e9bc2
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jan 9 19:15:10 2022 +0100

    * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _parse_texi_document),
    tp/Texinfo/XS/parsetexi/api.c (parse_file),
    tp/Texinfo/XS/parsetexi/parser.c (parse_texi_document):
    split the entry point for parse_texi_file, using parse_texi_document()
    for the part doing the parsing.  In the XS parser move the code
    related to file opening to parse_file() and remove parse_texi_file().
    
    * tp/Texinfo/ParserNonXS.pm (parse_texi_text): simplify possibilities
    for arguments.
---
 ChangeLog                        | 12 ++++++++++
 tp/Texinfo/ParserNonXS.pm        | 50 +++++++++++++++-------------------------
 tp/Texinfo/XS/parsetexi/api.c    | 33 ++++++++++++++++++++++++--
 tp/Texinfo/XS/parsetexi/parser.c | 28 +---------------------
 tp/Texinfo/XS/parsetexi/parser.h |  2 +-
 5 files changed, 63 insertions(+), 62 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 86832ed044..f6016ad422 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2022-01-09  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (parse_texi_file, _parse_texi_document),
+       tp/Texinfo/XS/parsetexi/api.c (parse_file),
+       tp/Texinfo/XS/parsetexi/parser.c (parse_texi_document):
+       split the entry point for parse_texi_file, using parse_texi_document()
+       for the part doing the parsing.  In the XS parser move the code
+       related to file opening to parse_file() and remove parse_texi_file().
+
+       * tp/Texinfo/ParserNonXS.pm (parse_texi_text): simplify possibilities
+       for arguments.
+
 2022-01-09  Gavin Smith  <gavinsmith0123@gmail.com>
 
        Remove old TODO
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 724644a88a..59e63a7571 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -877,24 +877,16 @@ sub parse_texi_text($$;$$$$)
 
   return undef if (!defined($text));
 
-  my $lines_array = [];
   if (ref($text) eq '') {
     $text = _text_to_lines($text);
   }
-  $lines_nr = 1 if (!defined($lines_nr));
-  if (ref($lines_nr) eq '') {
-    # $lines_nr is the first line number
-    $lines_array = _complete_line_nr($text, $lines_nr, $file,
-                                     $macro, $fixed_line_number);
-  } else {
-    # $lines_nr is an array of line numbers
-    while (@$text) {
-      my $line_nr = shift @$lines_nr;
-      my $line = shift @$text;
-      push @$lines_array, [$line, $line_nr];
-    }
+  if (not defined($lines_nr)) {
+    $lines_nr = 1;
   }
 
+  my $lines_array = _complete_line_nr($text, $lines_nr, $file,
+                                     $macro, $fixed_line_number);
+
   $self = parser() if (!defined($self));
   $self->{'input'} = [{'pending' => $lines_array}];
 
@@ -966,6 +958,13 @@ sub parse_texi_file($$)
        'fh' => $filehandle
         }];
 
+  return $self->_parse_texi_document();
+}
+
+sub _parse_texi_document($)
+{
+  my $self = shift;
+
   my ($document_root, $before_node_section)
      = _setup_document_root_and_before_node_section();
 
@@ -6159,25 +6158,12 @@ the line number of the first text line, if undef, it 
will be set to 1.
 I<$text> may be either an array reference of lines, or a text.
 
 The other arguments are optional and allow specifying the position
-information of the Texinfo code.  There are two distinct cases for
-I<$line_numbers_specification>.
-
-=over
-
-=item 1.
-
-If it is an array reference, it is considered to hold objects describing
-the position information of each text line.
-
-=item 2.
-
-If I<$line_numbers_specification> is a scalar, it is the line number of
-the first text line.  In that case I<$file_name> is the name of the file the
-text comes from.  and I<$macro> is for the user-defined macro name the text is
-expanded from.  If I<$fixed_line_number> is set, the line number is not
-increased for the different lines, as if the text was the expansion of a macro.
-
-=back
+information of the Texinfo code.  I<$first_line_number> is the line number
+of the first text line.  I<$file_name> is the name of the file the
+text comes from.  I<$macro> is for the user-defined macro name the text
+is expanded from.  If I<$fixed_line_number> is set, the line number is
+not increased for the different lines, as if the text was the expansion
+of a macro.
 
 =end comment
 
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 59d4ded019..a81282a440 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -156,14 +156,43 @@ reset_parser (void)
   global_accept_internalvalue = 0;
 }
 
-/* Set ROOT to root of tree obtained by parsing FILENAME. */
+/* Determine directory path based on file name.
+   Set ROOT to root of tree obtained by parsing FILENAME.
+   Used for parse_texi_file. */
 int
 parse_file (char *filename)
 {
   /*
   debug_output = 0;
   */
-  Root = parse_texi_file (filename);
+  char *p, *q;
+  char c;
+
+  int status;
+  
+  status = input_push_file (filename);
+  if (status)
+    return 0;
+
+  /* Strip off a leading directory path, by looking for the last
+     '/' in filename. */
+  p = 0;
+  q = strchr (filename, '/');
+  while (q)
+    {
+      p = q;
+      q = strchr (q + 1, '/');
+    }
+
+  if (p)
+    {
+      c = *p;
+      *p = '\0';
+      add_include_directory (filename);
+      *p = c;
+    }
+
+  Root = parse_texi_document ();
   if (Root)
     return 0;
   return 1;
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index e03a5fd441..4faab5ce40 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -353,38 +353,12 @@ setup_document_root_and_before_node_section ()
 
 
 ELEMENT *
-parse_texi_file (char *filename)
+parse_texi_document (void)
 {
-  char *p, *q;
   char *linep, *line = 0;
   ELEMENT *before_node_section = setup_document_root_and_before_node_section 
();
   ELEMENT *preamble_before_beginning = 0;
   ELEMENT *document_root = before_node_section->parent;
-  char c;
-
-  int status;
-  
-  status = input_push_file (filename);
-  if (status)
-    return 0;
-
-  /* Strip off a leading directory path, by looking for the last
-     '/' in filename. */
-  p = 0;
-  q = strchr (filename, '/');
-  while (q)
-    {
-      p = q;
-      q = strchr (q + 1, '/');
-    }
-
-  if (p)
-    {
-      c = *p;
-      *p = '\0';
-      add_include_directory (filename);
-      *p = c;
-    }
 
   /* Put all the empty lines up to a line starting "\input" inside a
      "preamble_before_beginning" element. */
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index 44ce393b1f..186e31f7fa 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -145,7 +145,7 @@ ELEMENT *parse_texi (ELEMENT *root_elt, ELEMENT 
*current_elt);
 void push_conditional_stack (enum command_id cond);
 enum command_id pop_conditional_stack (void);
 extern size_t conditional_number;
-ELEMENT *parse_texi_file (char *filename);
+ELEMENT *parse_texi_document (void);
 int abort_empty_line (ELEMENT **current_inout, char *additional);
 ELEMENT *end_paragraph (ELEMENT *current,
                         enum command_id closed_command,



reply via email to

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