[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, _next_text) (_handle_macro): register the number of expanded macros in a scalar and go through input to check if a macro is being expanded instead of keeping a stack of expanded macros, also to be more similar with XS parser. |
Date: |
Sat, 08 Jul 2023 04:56:53 -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 a8aa10058b * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization,
_next_text) (_handle_macro): register the number of expanded macros in a scalar
and go through input to check if a macro is being expanded instead of keeping a
stack of expanded macros, also to be more similar with XS parser.
a8aa10058b is described below
commit a8aa10058b3c2445144c714d5ae15927dfe9f095
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jul 8 10:56:43 2023 +0200
* tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, _next_text)
(_handle_macro): register the number of expanded macros in a scalar
and go through input to check if a macro is being expanded instead
of keeping a stack of expanded macros, also to be more similar with
XS parser.
* tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
tp/Texinfo/XS/parsetexi/close.c (close_current),
tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line)
(end_line_starting_block), tp/Texinfo/XS/parsetexi/macro.c
(handle_macro), tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space):
add debug messages in XS parser to match better perl parser.
---
ChangeLog | 15 +++++++++++++
tp/Texinfo/ParserNonXS.pm | 44 ++++++++++++++------------------------
tp/Texinfo/XS/parsetexi/close.c | 3 +++
tp/Texinfo/XS/parsetexi/end_line.c | 8 +++++++
tp/Texinfo/XS/parsetexi/macro.c | 2 ++
tp/Texinfo/XS/parsetexi/parser.c | 17 ++++++++++++---
6 files changed, 58 insertions(+), 31 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ce2b1d676e..98bb464bdd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2023-07-08 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, _next_text)
+ (_handle_macro): register the number of expanded macros in a scalar
+ and go through input to check if a macro is being expanded instead
+ of keeping a stack of expanded macros, also to be more similar with
+ XS parser.
+
+ * tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
+ tp/Texinfo/XS/parsetexi/close.c (close_current),
+ tp/Texinfo/XS/parsetexi/end_line.c (end_line_def_line)
+ (end_line_starting_block), tp/Texinfo/XS/parsetexi/macro.c
+ (handle_macro), tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space):
+ add debug messages in XS parser to match better perl parser.
+
2023-07-08 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Common.pm (debug_print_element),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index cf57380cf0..779a8273d8 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -123,9 +123,6 @@ $VERSION = '7.0dev';
# are not configurable/implemented in the XS parser, so they are best
# 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' => [],
'aliases' => {}, # key is a command name value is the alias
'commands_info' => {}, # keys are @-commands names (without @) and
# values are arrays for global multiple
@@ -143,8 +140,7 @@ my %parser_state_initialization = (
'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)
+ 'macro_expansion_nr' => 0, # number of macros being expanded
'value_stack' => [], # stack of values being expanded (more recent
# first)
'merged_indices' => {}, # the key is merged in the value
@@ -2386,10 +2382,7 @@ sub _next_text($;$)
}
delete $input->{'th'};
if ($input->{'input_source_info'}->{'macro'} ne '') {
- my $top_macro = shift @{$self->{'macro_stack'}};
- print STDERR "SHIFT MACRO_STACK(@{$self->{'macro_stack'}}):"
- ." $top_macro->{'args'}->[0]->{'text'}\n"
- if ($self->{'DEBUG'});
+ $self->{'macro_expansion_nr'}--;
} elsif (defined($input->{'value_flag'})) {
my $top_value = shift @{$self->{'value_stack'}};
print STDERR "SHIFT VALUE_STACK(@{$self->{'value_stack'}}):"
@@ -2823,17 +2816,11 @@ sub _isolate_last_space
my $debug_str;
if ($self->{'DEBUG'}) {
- $debug_str = 'p '
- .Texinfo::Common::debug_print_element($current)."; c ";
- if (scalar(@{$current->{'contents'}})) {
- if ($current->{'contents'}->[-1]->{'type'}) {
- $debug_str .= "($current->{'contents'}->[-1]->{'type'})";
- }
- if (defined($current->{'contents'}->[-1]->{'text'})) {
- $debug_str .= "[T: $current->{'contents'}->[-1]->{'text'}]";
- }
+ $debug_str = 'p '.Texinfo::Common::debug_print_element($current).'; c ';
+ if ($current->{'contents'} and scalar(@{$current->{'contents'}})) {
+ $debug_str .=
+ Texinfo::Common::debug_print_element($current->{'contents'}->[-1]);
}
- $debug_str .= "\n";
}
if (!$current->{'contents'}
@@ -2844,15 +2831,15 @@ sub _isolate_last_space
or ($current->{'type'} ne 'line_arg'
and $current->{'type'} ne 'block_line_arg')))
or $current->{'contents'}->[-1]->{'text'} !~ /\s+$/) {
- print STDERR "NOT ISOLATING ".$debug_str
+ print STDERR "NOT ISOLATING $debug_str\n"
if ($self->{'DEBUG'});
return;
}
my $last_element = $current->{'contents'}->[-1];
- #print STDERR "ISOLATE SPACE ".$debug_str
- # if ($self->{'DEBUG'});
+ print STDERR "ISOLATE SPACE $debug_str\n"
+ if ($self->{'DEBUG'});
if ($current->{'type'} and $current->{'type'} eq 'menu_entry_node') {
_isolate_trailing_space($current, 'space_at_end_menu_node');
@@ -3682,7 +3669,7 @@ sub _end_line_def_line($$$)
# $def_command = $current->{'parent'}->{'extra'}->{'name'};
}
- print STDERR "END DEF LINE $top_context $def_command; current: "
+ print STDERR "END DEF LINE $top_context $def_command; current "
.Texinfo::Common::debug_print_element($current, 1)."\n"
if ($self->{'DEBUG'});
@@ -4852,7 +4839,7 @@ sub _handle_macro($$$$$)
# FIXME same stack for linemacro?
if ($self->{'MAX_MACRO_CALL_NESTING'}
- and scalar(@{$self->{'macro_stack'}}) >=
$self->{'MAX_MACRO_CALL_NESTING'}) {
+ and $self->{'macro_expansion_nr'} >= $self->{'MAX_MACRO_CALL_NESTING'}) {
$self->_line_warn(sprintf(__(
"macro call nested too deeply (set MAX_MACRO_CALL_NESTING to override;
current value %d)"),
$self->{'MAX_MACRO_CALL_NESTING'}), $source_info);
@@ -4861,8 +4848,9 @@ sub _handle_macro($$$$$)
}
if ($expanded_macro->{'cmdname'} ne 'rmacro') {
- foreach my $macro (@{$self->{'macro_stack'}}) {
- if ($macro->{'args'}->[0]->{'text'} eq $command) {
+ foreach my $input (@{$self->{'input'}}[0..$#{$self->{'input'}}-1]) {
+ if (defined($input->{'input_source_info'}->{'macro'})
+ and $input->{'input_source_info'}->{'macro'} eq $command) {
# FIXME different message for linemacro?
$self->_line_error(sprintf(__(
"recursive call of macro %s is not allowed; use \@rmacro if needed"),
@@ -4873,8 +4861,8 @@ sub _handle_macro($$$$$)
}
}
- unshift @{$self->{'macro_stack'}}, $expanded_macro;
- print STDERR "UNSHIFT MACRO_STACK:
$expanded_macro->{'args'}->[0]->{'text'}\n"
+ $self->{'macro_expansion_nr'}++;
+ print STDERR "MACRO NUMBER $self->{'macro_expansion_nr'} $command\n"
if ($self->{'DEBUG'});
if ($expanded_macro->{'cmdname'} eq 'linemacro') {
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 70021d68cd..cdf789da41 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -423,6 +423,9 @@ close_current (ELEMENT *current,
{
enum context c;
ELEMENT *close_brace;
+
+ debug ("CLOSING type %s", element_type_name (current));
+
switch (current->type)
{
case ET_balanced_braces:
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index 1085d0557c..324f399433 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -665,6 +665,11 @@ end_line_def_line (ELEMENT *current)
def_command = top_cmd;
}
+ debug ("END DEF LINE %s %s; current %s",
+ top_context == ct_def ? "ct_def"
+ : top_context == ct_linecommand ? "ct_linecommand" : "",
+ command_name(def_command), print_element_debug (current, 1));
+
def_info = parse_def (def_command, current);
/* def_line or linemacro_call */
@@ -898,6 +903,9 @@ end_line_starting_block (ELEMENT *current)
if (pop_context () != ct_line)
fatal ("line context expected");
+ debug ("END BLOCK LINE: %s", print_element_debug (current, 1));
+
+ /* @multitable args */
if (command == CM_multitable
&& (k = lookup_extra (current->parent, "columnfractions")))
{
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index 87285aa046..85370957bd 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -700,6 +700,8 @@ handle_macro (ELEMENT *current, char **line_inout, enum
command_id cmd)
macro_expansion_nr++;
+ debug ("MACRO NUMBER %d %s", macro_expansion_nr, command_name(cmd));
+
if (macro->cmd == CM_linemacro)
goto funexit;
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 2e3e978bf7..5a0154714f 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -914,7 +914,7 @@ isolate_last_space (ELEMENT *current)
}
if (current->contents.number == 0)
- return;
+ goto no_isolate_space;
last_elt = last_contents_child (current);
text = element_text (last_elt);
@@ -922,17 +922,27 @@ isolate_last_space (ELEMENT *current)
|| (last_elt->type && (!current->type
|| (current->type != ET_line_arg
&& current->type != ET_block_line_arg))))
- return;
+ goto no_isolate_space;
text_len = last_elt->text.end;
/* Does the text end in whitespace? */
if (!strchr (whitespace_chars, text[text_len - 1]))
- return;
+ goto no_isolate_space;
if (current->type == ET_menu_entry_node)
isolate_trailing_space (current, ET_space_at_end_menu_node);
else
isolate_last_space_internal (current);
+
+ debug ("ISOLATE SPACE p %s; c %s", print_element_debug (current, 0),
+ current->contents.number == 0 ? "" : print_element_debug (last_elt, 0));
+
+ return;
+
+no_isolate_space:
+ debug ("NOT ISOLATING p %s; c %s", print_element_debug (current, 0),
+ current->contents.number == 0 ? "" : print_element_debug (last_elt, 0));
+ return;
}
@@ -2140,6 +2150,7 @@ process_remaining_on_line (ELEMENT **current_inout, char
**line_inout)
}
def_line_continuation = (current_context() == ct_def
&& cmd == CM_NEWLINE);
+
/* warn on not appearing at line beginning. Need to do before closing
paragraph as it also closes the empty line */
if (!def_line_continuation
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (%parser_state_initialization, _next_text) (_handle_macro): register the number of expanded macros in a scalar and go through input to check if a macro is being expanded instead of keeping a stack of expanded macros, also to be more similar with XS parser.,
Patrice Dumas <=