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 (%parser_state_initia


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, parser) (simple_parser): put 'regions_stack', 'macro_stack' and 'conditionals_stack' initialization in %parser_state_initialization. remove 'explained_commands' state it is not used anywhere. Merge _setup_parser() in parser().
Date: Sat, 15 Jan 2022 09:15:15 -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 eec62c31d6 * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, 
parser) (simple_parser): put 'regions_stack', 'macro_stack' and 
'conditionals_stack' initialization in %parser_state_initialization. remove 
'explained_commands' state it is not used anywhere. Merge _setup_parser() in 
parser().
eec62c31d6 is described below

commit eec62c31d65db263c919e7c0f7f970ec4d2cc525
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jan 15 15:15:03 2022 +0100

    * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, parser)
    (simple_parser): put 'regions_stack', 'macro_stack' and
    'conditionals_stack' initialization in %parser_state_initialization.
    remove 'explained_commands' state it is not used anywhere.
    Merge _setup_parser() in parser().
---
 ChangeLog                 |  8 +++++
 tp/Texinfo/ParserNonXS.pm | 76 +++++++++++++++++------------------------------
 2 files changed, 36 insertions(+), 48 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8aa697c34e..ad9b1aa785 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-01-15  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, parser)
+       (simple_parser): put 'regions_stack', 'macro_stack' and
+       'conditionals_stack' initialization in %parser_state_initialization.
+       remove 'explained_commands' state it is not used anywhere.
+       Merge _setup_parser() in parser().
+
 2022-01-15  Patrice Dumas  <pertusus@free.fr>
 
        * doc/tp_api/Makefile.am (tp_api_dependencies): add missing modules.
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 964339d02c..dca04b3d02 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -101,43 +101,39 @@ sub N__($)
 }
 
 # these are the default values for the parser state
-# they could become configurable if moved to the next hash, but they
+# some could become configurable if moved to the next hash, but they
 # are not configurable/implemented in the XS parser, so they are best
-# left internal.
+# left internal.  In general they are dynamically modified during parsing.
 my %parser_state_initialization = (
   # these are the user-added indices.  May be an array reference on names
   # or an hash reference in the same format than %index_names below
   'indices' => [],
-  # the following are dynamically modified during the document parsing.
   'aliases' => {},            # key is a command name value is the alias
-  'explained_commands' => {}, # the key is a command name, either acronym
-                              # or abbr, the value is a hash.  The key hash 
-                              # is a normalized first argument of the 
-                              # corresponding command, the value is the 
-                              # contents array of the previous command with
-                              # this first arg and a second arg.
+  'commands_info' => {},      # keys are @-commands names (without @) and
+                              # values are arrays for global multiple 
@-commands
+                              # and a value for non multiple global @-commands.
+  'conditionals_stack' => [], # a stack of conditional commands that are 
expanded.
+  # floats is not really needed, as it would be autogenerated,
+  # but this allows to have an output more similar to the XS parser output.
+  'floats' => {},             # key is the normalized float type, value is
+                              # an array reference holding all the floats
+                              # of that type.
   'labels'          => {},    # keys are normalized label names, as described
                               # in the `HTML Xref' node.  Value should be
                               # a node/anchor or float in the tree.
-  'targets' => [],            # array of elements used to build 'labels'
   'macros' => {},             # the key is the user-defined macro name.  The 
                               # value is the reference on a macro element 
                               # as obtained by parsing the @macro
+  'macro_stack' => [],        # stack of macros being expanded (more recent 
first)
   'merged_indices' => {},     # the key is merged in the value
+  'regions_stack' => [],      # a stack of regions commands elements (in 
%region_commands)
   'sections_level' => 0,      # modified by raise/lowersections
-  # floats is not really needed, as it would be autogenerated,
-  # but this allows to have an output more similar to the XS parser output.
-  'floats' => {},             # key is the normalized float type, value is
-                              # an array reference holding all the floats
-                              # of that type.
-
+  'targets' => [],            # array of elements used to build 'labels'
+  # initialization of information returned by global_informations()
   'info' => {
     'input_encoding_name' => 'utf-8',
     'input_perl_encoding' => 'utf-8'
   },
-  'commands_info' => {},       # keys are @-commands names (without @) and
-                               # values are arrays for global multiple 
@-commands
-                               # and a value for non multiple global 
@-commands.
 );
 
 # configurable parser state
@@ -192,8 +188,6 @@ my %parser_default_configuration = (
 #                         be added each time a context is pushed on
 #                         'context_stack'.  Could be undef if there
 #                         is no @-command associated with the context.
-# conditionals_stack      a stack of conditional commands that are expanded.
-# macro_stack             stack of macros being expanded (more recent first)
 # definfoenclose          an hash, key is the command name, value is an array
 #                         reference with 2 values, beginning and ending.
 # input                   a stack, with last at bottom.  Holds the opened files
@@ -698,16 +692,10 @@ sub parser(;$$)
   my $parser = dclone(\%parser_default_configuration);
   bless $parser;
 
-  return _setup_parser($parser, $conf);
-}
-
-sub _setup_parser {
-  my ($parser, $conf) = @_;
-
   _setup_conf($parser, $conf);
 
   # Now initialize command hash that are dynamically modified, notably
-  # those for index commands, and lists, based on defaults and user provided.
+  # those for index commands, and lists, based on defaults
   $parser->{'line_commands'} = dclone(\%line_commands);
   $parser->{'valid_nestings'} = dclone(\%default_valid_nestings);
   $parser->{'no_paragraph_commands'} = { %default_no_paragraph_commands };
@@ -715,6 +703,14 @@ sub _setup_parser {
   $parser->{'command_index'} = {%command_index};
   $parser->{'close_paragraph_commands'} = {%close_paragraph_commands};
   $parser->{'close_preformatted_commands'} = {%close_preformatted_commands};
+
+  $parser->{'global_commands'} = {%global_multiple_commands};
+
+  # handle user provided state.
+  # REMARK the following code will not be used for user defined state
+  # if the corresponding key is ignored in _setup_conf() which is currently
+  # the case for the user provided informations in codes below.
+  #
   # a hash is simply concatenated.  It should be like %index_names.
   if (ref($parser->{'indices'}) eq 'HASH') {
     %{$parser->{'index_names'}} = (%{$parser->{'index_names'}}, 
@@ -748,15 +744,9 @@ sub _setup_parser {
       }
     }
   }
-  foreach my $explained_command(keys(%explained_commands)) {
-    if (!defined($parser->{'explained_commands'}->{$explained_command})) {
-      $parser->{'explained_commands'}->{$explained_command} = {};
-    }
-  }
+
+  # following is common with simple_parser
   $parser->_init_context_stack();
-  $parser->{'regions_stack'} = [];
-  $parser->{'macro_stack'} = [];
-  $parser->{'conditionals_stack'} = [];
 
   # turn the array to a hash for speed.  Not sure it really matters for such
   # a small array.
@@ -764,8 +754,6 @@ sub _setup_parser {
     $parser->{'expanded_formats_hash'}->{$expanded_format} = 1;
   }
 
-  %{$parser->{'global_commands'}} = %global_multiple_commands;
-
   if (not defined($parser->{'registrar'})) {
     $parser->{'registrar'} = Texinfo::Report::new();
   }
@@ -800,15 +788,9 @@ sub simple_parser(;$)
   $parser->{'close_paragraph_commands'} = 
$simple_parser_close_paragraph_commands;
   $parser->{'close_preformatted_commands'} = 
$simple_parser_close_preformatted_commands;
 
-  foreach my $explained_command(keys(%explained_commands)) {
-    if (!defined($parser->{'explained_commands'}->{$explained_command})) {
-      $parser->{'explained_commands'}->{$explained_command} = {};
-    }
-  }
+  %{$parser->{'global_commands'}} = ();
+
   $parser->_init_context_stack();
-  $parser->{'regions_stack'} = [];
-  $parser->{'macro_stack'} = [];
-  $parser->{'conditionals_stack'} = [];
 
   # turn the array to a hash for speed.  Not sure it really matters for such
   # a small array.
@@ -816,8 +798,6 @@ sub simple_parser(;$)
     $parser->{'expanded_formats_hash'}->{$expanded_format} = 1;
   }
 
-  %{$parser->{'global_commands'}} = ();
-
   if (not defined($parser->{'registrar'})) {
     $parser->{'registrar'} = Texinfo::Report::new();
   }



reply via email to

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