texinfo-commits
[Top][All Lists]
Advanced

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

texinfo/tp/Texinfo Parser.pm Report.pm Structur...


From: Patrice Dumas
Subject: texinfo/tp/Texinfo Parser.pm Report.pm Structur...
Date: Sun, 30 Oct 2011 23:03:33 +0000

CVSROOT:        /sources/texinfo
Module name:    texinfo
Changes by:     Patrice Dumas <pertusus>        11/10/30 23:03:33

Modified files:
        tp/Texinfo     : Parser.pm Report.pm Structuring.pm 
        tp/Texinfo/Convert: Converter.pm DocBook.pm XML.pm 

Log message:
        Better code for initialization of a parser as a duplicate of another 
parser.
        
        In gdt take informations from the current parser.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Parser.pm?cvsroot=texinfo&r1=1.327&r2=1.328
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Report.pm?cvsroot=texinfo&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.101&r2=1.102
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/Converter.pm?cvsroot=texinfo&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/DocBook.pm?cvsroot=texinfo&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Convert/XML.pm?cvsroot=texinfo&r1=1.48&r2=1.49

Patches:
Index: Parser.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Parser.pm,v
retrieving revision 1.327
retrieving revision 1.328
diff -u -b -r1.327 -r1.328
--- Parser.pm   30 Oct 2011 10:41:45 -0000      1.327
+++ Parser.pm   30 Oct 2011 23:03:32 -0000      1.328
@@ -111,8 +111,6 @@
   # this is the initial context.  It is put at the bottom of the 
   # 'context_stack'
   'context' => '_root',
-  # the stack of the macros being expanded (more recent are first)
-  'macro_stack' => [],
   # 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' => [],
@@ -143,6 +141,8 @@
   'documentlanguage' => undef, 
                               # Current documentlanguage set by 
                               # @documentlanguage
+  # This is not used directly, but passed to Convert::Text through 
+  # Texinfo::Common::_convert_text_options
   'ENABLE_ENCODING' => 1,     # output accented and special characters
                               # based on @documentencoding
   'CPP_LINE_DIRECTIVES' => 1, # handle cpp like synchronization lines
@@ -153,6 +153,11 @@
   'GLOBAL_COMMANDS' => [],    # list of commands registered 
 );
 
+my %tree_informations;
+foreach my $tree_information ('values', 'macros', 'explained_commands', 
'labels') {
+  $tree_informations{$tree_information} = 1;
+}
+
 # The commands in initialization_overrides are not set in the document if
 # set at the parser initialization.
 my %initialization_overrides = (
@@ -177,6 +182,7 @@
 #                         'math', 'footnote', 'caption', 'shortcaption' are 
 #                         also added when in those commands
 # 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
@@ -492,7 +498,19 @@
     # called on an existing parser, interpreted as a duplication
     my $old_parser = $class;
     $class = ref($class);
-    $parser = _deep_copy($old_parser);
+    foreach my $key (keys(%default_configuration)) {
+      if ($tree_informations{$key}) {
+        if (defined($old_parser->{$key})) {
+          foreach my $info_key (keys(%{$old_parser->{$key}})) {
+            $parser->{$key}->{$info_key}
+              = $old_parser->{$key}->{$info_key};
+          }
+        }
+      } else {
+        $parser->{$key} = _deep_copy($old_parser->{$key});
+      }
+    }
+    #$parser = _deep_copy($old_parser);
     $parser->{'gettext'} = $old_parser->{'gettext'};
     bless $parser, $class;
     $conf = shift;
@@ -556,6 +574,7 @@
   }
   $parser->{'context_stack'} = [ $parser->{'context'} ];
   $parser->{'regions_stack'} = [];
+  $parser->{'macro_stack'} = [];
   # turn the array to a hash for speed.  Not sure it really matters for such
   # a small array.
   foreach my $expanded_format(@{$parser->{'expanded_formats'}}) {

Index: Report.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Report.pm,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- Report.pm   1 Oct 2011 10:29:25 -0000       1.15
+++ Report.pm   30 Oct 2011 23:03:32 -0000      1.16
@@ -149,7 +149,8 @@
   $self->{'error_nrs'}++;
 }
 
-sub file_line_warn($$$;$) {
+sub file_line_warn($$$;$)
+{
   my $self = shift;
   my $text = shift;
   return if ($self->{'ignore_notice'});
@@ -198,8 +199,6 @@
   my $context = shift;
   my $conf = shift;
 
-  my $encoding = $self->{'encoding_name'};
-
   my $re = join '|', map { quotemeta $_ } keys %$context
       if (defined($context) and ref($context));
 
@@ -211,6 +210,10 @@
 #  my $saved_LC_MESSAGES = POSIX::setlocale (LC_MESSAGES);
 
   Locale::Messages::textdomain($strings_textdomain);
+
+  # FIXME do that only once when encoding is seen (or at beginning)
+  # instead of here, each time that gdt is called?
+  my $encoding = $self->{'encoding_name'};
   Locale::Messages::bind_textdomain_codeset($strings_textdomain, $encoding)
     if ($encoding and $encoding ne 'us-ascii');
   if (!($encoding and $encoding eq 'us-ascii') and $self->{'perl_encoding'}) {
@@ -218,7 +221,8 @@
       \&_encode_i18n_string, $self->{'perl_encoding'});
   }
 
-  # FIXME do that in the converters when @documentlanguage is found.
+  # FIXME do that once when @documentlanguage changes (or at beginning)
+  # instead of here, each time that gdt is called?
   my $lang = $self->get_conf('documentlanguage');
   $lang = $DEFAULT_LANGUAGE if (!defined($lang));
   my @langs = ($lang);
@@ -249,11 +253,13 @@
 
   Locale::Messages::nl_putenv("LANGUAGE=$locales");
 
-  my $result;
+  my $translation_result;
   if (!defined($context) or ref($context)) {
-    $result = Locale::Messages::gettext($message);
+    $translation_result = Locale::Messages::gettext($message);
   } else {
-    $result = Locale::Messages::pgettext($context, $message);
+    # In practice this is not used anywhere, context is always a HASH.
+    # for strings substitution not a context for translation.
+    $translation_result = Locale::Messages::pgettext($context, $message);
   }
 
   Locale::Messages::textdomain($messages_textdomain);
@@ -288,28 +294,48 @@
   my $parser_conf;
   # we change the substituted brace-enclosed strings to values, that
   # way they are substituted, including when they are Texinfo trees.
+  # a _ is prepended to avoid clashing with other values, although since
+  # the parser is a new one there should not be any problem anyway.
   if (defined($re)) {
     # next line taken from libintl perl, copyright Guido. sub __expand
-    $result =~ s/\{($re)\}/address@hidden/g;
+    $translation_result =~ s/\{($re)\}/address@hidden/g;
     foreach my $substitution(keys %$context) {
-      #print STDERR "$result $substitution $context->{$substitution}\n";
-      $parser_conf->{'values'}->{$substitution} = $context->{$substitution};
+      #print STDERR "$translation_result $substitution 
$context->{$substitution}\n";
+      $parser_conf->{'values'}->{'_'.$substitution} = 
$context->{$substitution};
+    }
     }
+
+  # Don't reuse the current parser itself, as (tested) the parsing goes 
+  # wrong, certainly because the parsed text can affect the parser state.
+  my $current_parser;
+  if (ref($self) eq 'Texinfo::Parser') {
+    $current_parser = $self;
+  } elsif ($self->{'parser'}) {
+    $current_parser = $self->{'parser'};
+  }
+
+  if ($current_parser) {
+    # not sure 'gettext' could in fact be useful in parser for
+    # translated fragments.  'TEST' can be used fot @today{} expansion.
+    foreach my $duplicated_conf ('clickstyle', 'kbdinputstyle', 'DEBUG',
+                                 'TEST', 'gettext') {
+      $parser_conf->{$duplicated_conf} = $current_parser->{$duplicated_conf}
+        if (defined($current_parser->{$duplicated_conf}));
   }
-  # FIXME reuse a parser?
-  if ($self->get_conf('DEBUG')) {
-    $parser_conf->{'DEBUG'} = 1;
-    print STDERR "GDT $result\n";
   }
   my $parser = Texinfo::Parser::parser($parser_conf);
+  if ($parser->{'DEBUG'}) {
+    print STDERR "GDT $translation_result\n";
+  }
 
-  # FIXME it doesn't seems to be used anywhere.
-  if ($conf->{'paragraph'}) {
-    $result = $parser->parse_texi_text($result);
+  my $tree;
+  # Right now this is not used anywhere.
+  if ($conf->{'translated_paragraph'}) {
+    $tree = $parser->parse_texi_text($translation_result);
   } else {
-    $result = $parser->parse_texi_line($result);
+    $tree = $parser->parse_texi_line($translation_result);
   }
-  return $result;
+  return $tree;
 }
 
 

Index: Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -b -r1.101 -r1.102
--- Structuring.pm      30 Oct 2011 10:41:45 -0000      1.101
+++ Structuring.pm      30 Oct 2011 23:03:32 -0000      1.102
@@ -716,7 +716,9 @@
   }
 }
 
-# FIXME node not existing
+# undef in argument should be an error.  Thus only node existing should be
+# passed to this function.  Even if not existing the value returned should
+# be undef.
 sub _node_element($)
 {
   my $node = shift;

Index: Convert/Converter.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/Converter.pm,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- Convert/Converter.pm        30 Oct 2011 10:13:19 -0000      1.57
+++ Convert/Converter.pm        30 Oct 2011 23:03:32 -0000      1.58
@@ -260,7 +260,6 @@
 {
   my $self = shift;
   my $multiple_commands_index = shift;
-  # FIXME 0 (first) or -1 (last)?
   $multiple_commands_index = 0 if (!defined($multiple_commands_index));
 
   foreach my $global_command ($self->converter_global_commands()) {
@@ -371,8 +370,8 @@
         and 
defined($self->{'extra'}->{'setfilename'}->{'extra'}->{'text_arg'}));
 
   # FIXME use TOP_FILE?
-  # FIXME PREFIX is the same as setfilename, maybe override setfilename 
-  # instead?
+  # FIXME PREFIX overrides setfilename, maybe override setfilename 
+  # directly instead?
   if (defined($self->get_conf('PREFIX'))) {
     $setfilename = undef;
     $input_basename = $self->get_conf('PREFIX');

Index: Convert/DocBook.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/DocBook.pm,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- Convert/DocBook.pm  30 Oct 2011 10:13:19 -0000      1.24
+++ Convert/DocBook.pm  30 Oct 2011 23:03:32 -0000      1.25
@@ -524,7 +524,7 @@
           $arg_tree = $root->{'args'}->[0];
         }
         $result .= "<term>";
-        # Is it automaticcally entered in docbook?  No.
+        # Is it automatically entered in docbook?  No.
         #$result .= $self->_index_entry($root);
         # FIXME
         my $in_code;

Index: Convert/XML.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Convert/XML.pm,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -b -r1.48 -r1.49
--- Convert/XML.pm      30 Oct 2011 10:13:20 -0000      1.48
+++ Convert/XML.pm      30 Oct 2011 23:03:32 -0000      1.49
@@ -137,13 +137,11 @@
   'documentlanguage' => 'xml:lang',
 );
 
-# FIXME printindex is special?
 my %misc_command_numbered_arguments_attributes = (
   'definfoenclose' => [ 'command', 'open', 'close' ],
   'alias' => [ 'new', 'existing' ],
   'syncodeindex' => [ 'from', 'to' ],
   'synindex' => [ 'from', 'to' ],
-#  'sp' => [ 'lines' ],
 );
 
 my %xml_misc_commands = %Texinfo::Common::misc_commands;



reply via email to

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