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_command_name)


From: Patrice Dumas
Subject: branch master updated: * tp/Texinfo/ParserNonXS.pm (_parse_command_name) (_process_remaining_on_line), tp/Texinfo/XS/MiscXS.xs (xs_parse_command_name), tp/Texinfo/XS/misc.c (xs_parse_command_name): use more similar interface for parse_command_name in the perl parser than in the XS parser.
Date: Wed, 19 Jul 2023 02:45:36 -0400

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 03dc248ca9 * tp/Texinfo/ParserNonXS.pm (_parse_command_name) 
(_process_remaining_on_line), tp/Texinfo/XS/MiscXS.xs (xs_parse_command_name), 
tp/Texinfo/XS/misc.c (xs_parse_command_name): use more similar interface for 
parse_command_name in the perl parser than in the XS parser.
03dc248ca9 is described below

commit 03dc248ca981c5b84d792958c4e80b1f61bb4de1
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Jul 19 08:45:26 2023 +0200

    * tp/Texinfo/ParserNonXS.pm (_parse_command_name)
    (_process_remaining_on_line), tp/Texinfo/XS/MiscXS.xs
    (xs_parse_command_name), tp/Texinfo/XS/misc.c (xs_parse_command_name):
    use more similar interface for parse_command_name in the perl parser
    than in the XS parser.
---
 ChangeLog                 |  8 ++++++++
 tp/Texinfo/ParserNonXS.pm | 48 ++++++++++++++++++++++++++---------------------
 tp/Texinfo/XS/MiscXS.xs   | 10 +++++-----
 tp/Texinfo/XS/misc.c      | 12 +++++++-----
 tp/Texinfo/XS/miscxs.h    |  2 +-
 5 files changed, 48 insertions(+), 32 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8bb761f332..63e605621a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-07-18  Patrice Dumas  <pertusus@free.fr>
+
+       * tp/Texinfo/ParserNonXS.pm (_parse_command_name)
+       (_process_remaining_on_line), tp/Texinfo/XS/MiscXS.xs
+       (xs_parse_command_name), tp/Texinfo/XS/misc.c (xs_parse_command_name):
+       use more similar interface for parse_command_name in the perl parser
+       than in the XS parser.
+
 2023-07-18  Patrice Dumas  <pertusus@free.fr>
 
        * tp/Texinfo/ParserNonXS.pm (_parse_command_name, _parse_texi_regex)
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index e6181dd83e..806bfe54bd 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -4596,7 +4596,15 @@ sub _parse_command_name {
                 |^(["'~\@&\}\{,\.!\? \t\n\*\-\^`=:\|\/\\])
                 /x);
 
-  return ($at_command, $single_letter_command);
+  my $command;
+  my $is_single_letter = 0;
+  if ($single_letter_command) {
+    $command = $single_letter_command;
+    $is_single_letter = 1;
+  } elsif (defined($at_command) and $at_command ne '') {
+    $command = $at_command;
+  }
+  return ($command, $is_single_letter);
 }
 
 # This combines several regular expressions used in '_parse_texi' to
@@ -6578,7 +6586,7 @@ sub _process_remaining_on_line($$$$)
     #}
   }
 
-  my $at_command_length;
+  my $command_length;
   my @line_parsing = _parse_texi_regex($line);
   my ($arobase, $open_brace, $close_brace, $comma,
       $asterisk, $form_feed, $menu_only_separator, $misc_text)
@@ -6595,18 +6603,23 @@ sub _process_remaining_on_line($$$$)
   my $from_alias;
   if ($arobase) {
 
-    my $single_letter_command;
+    my $is_single_letter;
     my $command_string = $line;
     substr($command_string, 0, 1) = '';
-    ($at_command, $single_letter_command) = 
_parse_command_name($command_string);
+    ($command, $is_single_letter) = _parse_command_name($command_string);
 
-    if ($single_letter_command) {
-      $command = $single_letter_command;
-      $at_command_length = 2;
-    } elsif (defined($at_command) and $at_command ne '') {
-      $at_command_length = length($at_command) +1;
-      $command = $at_command;
+    if (defined($command)) {
+      $command_length = length($command) +1;
+    } else {
+      substr($line, 0, 1) = '';
+      # @ was followed by gibberish or by nothing, for instance at the
+      # very end of a string/file.
+      $self->_line_error(__("unexpected \@"), $source_info);
+      return ($current, $line, $source_info, $retval);
+      # goto funexit;  # used in XS code
+    }
 
+    if (! $is_single_letter) {
       if (exists($self->{'aliases'}->{$command})) {
         $from_alias = $command;
         $command = $self->{'aliases'}->{$from_alias};
@@ -6616,7 +6629,7 @@ sub _process_remaining_on_line($$$$)
       # their expansion may lead to changes in the line
       if ($self->{'macros'}->{$command}) {
         my $arg_line = $line;
-        substr($arg_line, 0, $at_command_length) = '';
+        substr($arg_line, 0, $command_length) = '';
 
         ($macro_call_element, $arg_line, $source_info)
           = _handle_macro($self, $current, $arg_line, $source_info, $command);
@@ -6652,7 +6665,7 @@ sub _process_remaining_on_line($$$$)
       # early value expansion may be needed to provide with an argument.
       if ($command eq 'value') {
         my $remaining_line = $line;
-        substr($remaining_line, 0, $at_command_length) = '';
+        substr($remaining_line, 0, $command_length) = '';
         $remaining_line =~ s/^\s*//
            if ($self->{'IGNORE_SPACE_AFTER_BRACED_COMMAND_NAME'});
         # REVALUE
@@ -6686,13 +6699,6 @@ sub _process_remaining_on_line($$$$)
           }
         }
       }
-    } else {
-      substr($line, 0, 1) = '';
-      # @ was followed by gibberish or by nothing, for instance at the
-      # very end of a string/file.
-      $self->_line_error(__("unexpected \@"), $source_info);
-      return ($current, $line, $source_info, $retval);
-      # goto funexit;  # used in XS code
     }
   }
 
@@ -6746,7 +6752,7 @@ sub _process_remaining_on_line($$$$)
       and !$macro_call_element) {
     $self->_line_error(sprintf(__("unknown command `%s'"),
                                   $command), $source_info);
-    substr($line, 0, $at_command_length) = '';
+    substr($line, 0, $command_length) = '';
     return ($current, $line, $source_info, $retval);
     # goto funexit;  # used in XS code
   }
@@ -6882,7 +6888,7 @@ sub _process_remaining_on_line($$$$)
     $current = $current_array_for_ref[0];
   # Any other @-command.
   } elsif ($command) {
-    substr($line, 0, $at_command_length) = '';
+    substr($line, 0, $command_length) = '';
 
     print STDERR "COMMAND \@".Texinfo::Common::debug_command_name($command)
                   ."\n" if ($self->{'DEBUG'});
diff --git a/tp/Texinfo/XS/MiscXS.xs b/tp/Texinfo/XS/MiscXS.xs
index 128d473e97..bac8317c35 100644
--- a/tp/Texinfo/XS/MiscXS.xs
+++ b/tp/Texinfo/XS/MiscXS.xs
@@ -106,16 +106,16 @@ void
 xs_parse_command_name (text)
      SV *text
   PREINIT:
-     char *at_command;
-     char *single_letter_command;
+     char *command;
+     int is_single_letter;
   PPCODE:
-     xs_parse_command_name(text, &at_command, &single_letter_command);
+     xs_parse_command_name(text, &command, &is_single_letter);
      EXTEND(SP,2);
      PUSHs(sv_newmortal());
-     sv_setpv((SV*)ST(0), at_command);
+     sv_setpv((SV*)ST(0), command);
      SvUTF8_on(ST(0));
      PUSHs(sv_newmortal());
-     sv_setpv((SV*)ST(1), single_letter_command);
+     sv_setiv((SV*)ST(1), (IV)is_single_letter);
      SvUTF8_on(ST(1));
 
 
diff --git a/tp/Texinfo/XS/misc.c b/tp/Texinfo/XS/misc.c
index 72a5050dcd..be29da5464 100644
--- a/tp/Texinfo/XS/misc.c
+++ b/tp/Texinfo/XS/misc.c
@@ -285,8 +285,8 @@ xs_entity_text (char *text)
 }
 
 void xs_parse_command_name (SV *text_in,
-                            char **at_command,
-                            char **single_letter_command)
+                            char **command,
+                            int *is_single_letter)
 {
   char *text;
 
@@ -297,7 +297,8 @@ void xs_parse_command_name (SV *text_in,
     sv_utf8_upgrade (text_in);
   text = SvPV_nolen (text_in);
 
-  *at_command = *single_letter_command = 0;
+  *command = 0;
+  *is_single_letter = 0;
 
   if (isalnum(text[0]))
     {
@@ -312,7 +313,7 @@ void xs_parse_command_name (SV *text_in,
       s = realloc (s, q - p + 1);
       memcpy (s, p, q - p);
       s[q - p] = '\0';
-      *at_command = s;
+      *command = s;
     }
   else if (text[0] && strchr ("([\"'~@&}{,.!?"
                               " \t\n"
@@ -320,9 +321,10 @@ void xs_parse_command_name (SV *text_in,
                               text[0]))
     {
       static char a[2];
-      *single_letter_command = a;
+      *command = a;
       a[0] = text[0];
       a[1] = '\0';
+      *is_single_letter = 1;
     }
   return;
 }
diff --git a/tp/Texinfo/XS/miscxs.h b/tp/Texinfo/XS/miscxs.h
index 686fa03520..9768dbab53 100644
--- a/tp/Texinfo/XS/miscxs.h
+++ b/tp/Texinfo/XS/miscxs.h
@@ -3,7 +3,7 @@ char *xs_entity_text (char *);
 char *xs_process_text (char *text);
 void xs_parse_command_name (SV *text,
                             char **,
-                            char **);
+                            int*);
 void xs_parse_texi_regex (SV *text,
                           char **,
                           char **,



reply via email to

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