[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/ParserNonXS.pm (_relocate_source_mar
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/ParserNonXS.pm (_relocate_source_marks), tp/Texinfo/XS/parsetexi/source_marks.c (relocate_source_marks): relocate source marks within a range, with the first source mark not necessarily in range. Move relocate_source_marks from def.c to source_marks.c. |
Date: |
Wed, 08 Feb 2023 11:16:37 -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 0fb51499dd * tp/Texinfo/ParserNonXS.pm (_relocate_source_marks),
tp/Texinfo/XS/parsetexi/source_marks.c (relocate_source_marks): relocate source
marks within a range, with the first source mark not necessarily in range.
Move relocate_source_marks from def.c to source_marks.c.
0fb51499dd is described below
commit 0fb51499dd100bbf002245699dc72d36928feba6
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Wed Feb 8 17:16:26 2023 +0100
* tp/Texinfo/ParserNonXS.pm (_relocate_source_marks),
tp/Texinfo/XS/parsetexi/source_marks.c (relocate_source_marks):
relocate source marks within a range, with the first source mark not
necessarily in range. Move relocate_source_marks from def.c to
source_marks.c.
* tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space_internal):
relocate source marks corresponding to the new spaces element.
* tp/Texinfo/XS/parsetexi/source_marks.c
(remove_from_source_mark_list): move remove_from_source_mark_list from
tree.c to source_marks.c.
---
ChangeLog | 16 +++++
tp/Texinfo/ParserNonXS.pm | 77 ++++++++++++++++------
tp/Texinfo/XS/parsetexi/def.c | 23 -------
tp/Texinfo/XS/parsetexi/parser.c | 9 +++
tp/Texinfo/XS/parsetexi/source_marks.c | 55 ++++++++++++++++
tp/Texinfo/XS/parsetexi/source_marks.h | 2 +
tp/Texinfo/XS/parsetexi/tree.c | 18 -----
tp/Texinfo/XS/parsetexi/tree.h | 1 -
tp/t/results/def/end_of_line_end_file.pl | 7 ++
tp/t/results/include/double_include.pl | 12 ++--
tp/t/results/macro/macro_in_misc_commands.pl | 12 ++--
tp/t/results/macro/space_macro_after_end.pl | 14 ++--
.../macro/space_macro_after_end_verbatim.pl | 14 ++--
13 files changed, 171 insertions(+), 89 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0fd1736689..fcd7618be1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2023-02-08 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (_relocate_source_marks),
+ tp/Texinfo/XS/parsetexi/source_marks.c (relocate_source_marks):
+ relocate source marks within a range, with the first source mark not
+ necessarily in range. Move relocate_source_marks from def.c to
+ source_marks.c.
+
+ * tp/Texinfo/ParserNonXS.pm (_isolate_last_space),
+ tp/Texinfo/XS/parsetexi/parser.c (isolate_last_space_internal):
+ relocate source marks corresponding to the new spaces element.
+
+ * tp/Texinfo/XS/parsetexi/source_marks.c
+ (remove_from_source_mark_list): move remove_from_source_mark_list from
+ tree.c to source_marks.c.
+
2023-02-07 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/ParserNonXS.pm (_new_line, _process_remaining_on_line),
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index f83bd6e977..d9a44e0ca1 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2826,6 +2826,8 @@ sub _isolate_last_space
return;
}
+ my $last_element = $current->{'contents'}->[-1];
+
print STDERR "ISOLATE SPACE ".$debug_str
if ($self->{'DEBUG'});
@@ -2834,7 +2836,7 @@ sub _isolate_last_space
} else {
# Store final spaces in 'spaces_after_argument'.
#$current->{'info'} = {} if (!$current->{'info'});
- if ($current->{'contents'}->[-1]->{'text'} !~ /\S/) {
+ if ($last_element->{'text'} !~ /\S/) {
my $spaces_after_argument = _pop_element_from_contents($self, $current);
my $new_space_element = {'text' => $spaces_after_argument->{'text'},};
_transfer_source_marks($spaces_after_argument, $new_space_element);
@@ -2842,11 +2844,18 @@ sub _isolate_last_space
$current->{'info'}->{'spaces_after_argument'}
= $new_space_element;
} else {
- # FIXME transfer source marks that are located in the spaces
- # put in spaces_after_argument
- $current->{'contents'}->[-1]->{'text'} =~ s/(\s+)$//;
+ my $end_position = length($last_element->{'text'});
+ $last_element->{'text'} =~ s/(\s+)$//;
+ my $new_space_element = {'text' => $1,};
+ if ($last_element->{'source_marks'}) {
+ my $begin_position = length($last_element->{'text'});
+ _relocate_source_marks($last_element->{'source_marks'},
$new_space_element,
+ $begin_position, $end_position);
+ delete $last_element->{'source_marks'}
+ if (!scalar(@{$last_element->{'source_marks'}}));
+ }
$current->{'info'} = {} if (!exists($current->{'info'}));
- $current->{'info'}->{'spaces_after_argument'} = {'text' => $1,};
+ $current->{'info'}->{'spaces_after_argument'} = $new_space_element;
}
}
}
@@ -2872,22 +2881,42 @@ sub _parse_node_manual($)
return $parsed_node_manual;
}
+# relocate $SOURCE_MARKS source marks with position between
+# $BEGIN_POSITION and $END_POSITION to be relative to $BEGIN_POSITION,
+# and move to element $E.
sub _relocate_source_marks($$$$)
{
- my $remaining_source_marks = shift;
+ my $source_marks = shift;
my $e = shift;
- my $previous_position = shift;
- my $current_position = shift;
-
- while (scalar(@$remaining_source_marks)
- and ($remaining_source_marks->[0]->{'position'} > $previous_position
- or $remaining_source_marks->[0]->{'position'} == 0)
- and $remaining_source_marks->[0]->{'position'} <= $current_position) {
- my $source_mark = shift(@$remaining_source_marks);
- $source_mark->{'position'}
- = $source_mark->{'position'} - $previous_position;
- $e->{'source_marks'} = [] if (! defined($e->{'source_marks'}));
- push @{$e->{'source_marks'}}, $source_mark;
+ my $begin_position = shift;
+ my $end_position = shift;
+
+ my @indices_to_remove;
+ # collect source marks to remove starting from the beginning to keep
+ # the correct order in the $e element. Order indices to remove
+ # in the reverse order to start from the last in order not to change
+ # the array order when the entry is splice'd away.
+ for (my $i = 0; $i < scalar(@$source_marks); $i++) {
+ my $source_mark = $source_marks->[$i];
+ if (($begin_position == 0
+ and (!defined($source_marks->[$i]->{'position'})
+ # this should never happen
+ or $source_marks->[$i]->{'position'} == 0))
+ or ($source_marks->[$i]->{'position'} > $begin_position
+ and $source_marks->[$i]->{'position'} <= $end_position)) {
+ unshift @indices_to_remove, $i;
+ $source_mark->{'position'}
+ = $source_mark->{'position'} - $begin_position;
+ $e->{'source_marks'} = [] if (! defined($e->{'source_marks'}));
+ push @{$e->{'source_marks'}}, $source_mark;
+ } elsif ($source_marks->[$i]->{'position'} > $end_position) {
+ # only correct if positions are always monotonically increasing
+ # but should be the case for now
+ last;
+ }
+ }
+ foreach my $i (@indices_to_remove) {
+ splice (@$source_marks, $i, 1);
}
}
@@ -2937,7 +2966,10 @@ sub _split_delimiters
}
}
if (scalar(@remaining_source_marks)) {
- $self->_bug_message("Remaining source mark in _split_delimiters",
+ my $source_marks_str
+ = join ('|', map {_debug_show_source_mark($_)}
(@remaining_source_marks));
+ $self->_bug_message(
+ "Remaining source mark in _split_delimiters: $source_marks_str",
$source_info, $current);
}
return @elements;
@@ -2967,7 +2999,7 @@ sub _split_def_args
$previous_position = 0;
$root->{'source_marks'} = undef;
}
- for my $t (@split_text) {
+ foreach my $t (@split_text) {
my $e = {'text' => $t };
if (scalar(@remaining_source_marks)) {
$current_position += length($t);
@@ -2987,7 +3019,10 @@ sub _split_def_args
}
}
if (scalar(@remaining_source_marks)) {
- $self->_bug_message("Remaining source mark in _split_def_args",
+ my $source_marks_str
+ = join ('|', map {_debug_show_source_mark($_)} @remaining_source_marks);
+ $self->_bug_message(
+ "Remaining source mark in _split_def_args: $source_marks_str",
$source_info, $current);
}
return @elements;
diff --git a/tp/Texinfo/XS/parsetexi/def.c b/tp/Texinfo/XS/parsetexi/def.c
index 689632d2f5..20ec3c749a 100644
--- a/tp/Texinfo/XS/parsetexi/def.c
+++ b/tp/Texinfo/XS/parsetexi/def.c
@@ -147,29 +147,6 @@ DEF_ALIAS def_aliases[] = {
0, 0, 0
};
-void
-relocate_source_marks (SOURCE_MARK_LIST *source_mark_list, ELEMENT *new_e,
- size_t previous_position, size_t current_position)
-{
- int i;
- while (source_mark_list->number)
- {
- SOURCE_MARK *source_mark
- = source_mark_list->list[0];
- if ((source_mark->position > previous_position
- || source_mark->position == 0)
- && source_mark->position <= current_position)
- {
- source_mark->position
- = source_mark->position - previous_position;
- add_source_mark (source_mark, new_e);
- remove_from_source_mark_list (source_mark_list, 0);
- }
- else
- break;
- }
-}
-
/* Split non-space text elements into strings without [ ] ( ) , and single
character strings with one of them. */
static void
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 411582db8b..15a0a45e87 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -805,6 +805,7 @@ isolate_last_space_internal (ELEMENT *current)
else
{
int i, trailing_spaces;
+ size_t end_position;
static TEXT t;
text_reset (&t);
@@ -819,7 +820,15 @@ isolate_last_space_internal (ELEMENT *current)
text + text_len - trailing_spaces,
trailing_spaces);
+ if (last_elt->source_mark_list.number > 0)
+ end_position = count_convert_u8 (text);
text[text_len - trailing_spaces] = '\0';
+ if (last_elt->source_mark_list.number > 0)
+ {
+ size_t begin_position = count_convert_u8 (text);
+ relocate_source_marks (&(last_elt->source_mark_list), spaces_element,
+ begin_position, end_position);
+ }
last_elt->text.end -= trailing_spaces;
text_append (&spaces_element->text, t.text);
diff --git a/tp/Texinfo/XS/parsetexi/source_marks.c
b/tp/Texinfo/XS/parsetexi/source_marks.c
index c1871b9cf9..a3c535d451 100644
--- a/tp/Texinfo/XS/parsetexi/source_marks.c
+++ b/tp/Texinfo/XS/parsetexi/source_marks.c
@@ -154,3 +154,58 @@ source_marks_reset_counters (void)
macro_expansion_counter = 0;
value_expansion_counter = 0;
}
+
+SOURCE_MARK *
+remove_from_source_mark_list (SOURCE_MARK_LIST *list, int where)
+{
+ SOURCE_MARK *removed;
+
+ if (where < 0)
+ where = list->number + where;
+
+ if (where < 0 || where > list->number)
+ fatal ("source marks list index out of bounds");
+
+ removed = list->list[where];
+ memmove (&list->list[where], &list->list[where + 1],
+ (list->number - (where+1)) * sizeof (SOURCE_MARK *));
+ list->number--;
+ return removed;
+}
+
+/* relocate SOURCE_MARKS source marks with position between
+ BEGIN_POSITION and END_POSITION to be relative to BEGIN_POSITION,
+ and move to element E. */
+void
+relocate_source_marks (SOURCE_MARK_LIST *source_mark_list, ELEMENT *new_e,
+ size_t begin_position, size_t end_position)
+{
+ int i;
+ int list_number = source_mark_list->number;
+ int *indices_to_remove;
+
+ indices_to_remove = malloc (sizeof(int) * list_number);
+ memset (indices_to_remove, 0, list_number);
+
+ for (i = 0; i < list_number; i++)
+ {
+ SOURCE_MARK *source_mark
+ = source_mark_list->list[i];
+ if ((begin_position == 0 && source_mark->position == 0)
+ || (source_mark->position > begin_position
+ && source_mark->position <= end_position))
+ {
+ indices_to_remove[i] = 1;
+ source_mark->position
+ = source_mark->position - begin_position;
+ add_source_mark (source_mark, new_e);
+ }
+ else if (source_mark->position > end_position)
+ break;
+ }
+ for (i = list_number - 1; i >= 0; i--)
+ {
+ if (indices_to_remove[i] == 1)
+ remove_from_source_mark_list (source_mark_list, i);
+ }
+}
diff --git a/tp/Texinfo/XS/parsetexi/source_marks.h
b/tp/Texinfo/XS/parsetexi/source_marks.h
index c995608b66..52add981fa 100644
--- a/tp/Texinfo/XS/parsetexi/source_marks.h
+++ b/tp/Texinfo/XS/parsetexi/source_marks.h
@@ -24,6 +24,8 @@ void source_marks_reset_counters (void);
void transfer_source_marks (ELEMENT *from_e, ELEMENT *e);
void add_source_mark (SOURCE_MARK *source_mark, ELEMENT *e);
void place_source_mark (ELEMENT *e, SOURCE_MARK *source_mark);
+void relocate_source_marks (SOURCE_MARK_LIST *source_mark_list, ELEMENT *new_e,
+ size_t previous_position, size_t current_position);
#endif
diff --git a/tp/Texinfo/XS/parsetexi/tree.c b/tp/Texinfo/XS/parsetexi/tree.c
index d9f80eef13..6349a89bed 100644
--- a/tp/Texinfo/XS/parsetexi/tree.c
+++ b/tp/Texinfo/XS/parsetexi/tree.c
@@ -428,21 +428,3 @@ args_child_by_index (ELEMENT *e, int index)
return e->args.list[index];
}
-
-SOURCE_MARK *
-remove_from_source_mark_list (SOURCE_MARK_LIST *list, int where)
-{
- SOURCE_MARK *removed;
-
- if (where < 0)
- where = list->number + where;
-
- if (where < 0 || where > list->number)
- fatal ("source marks list index out of bounds");
-
- removed = list->list[where];
- memmove (&list->list[where], &list->list[where + 1],
- (list->number - (where+1)) * sizeof (SOURCE_MARK *));
- list->number--;
- return removed;
-}
diff --git a/tp/Texinfo/XS/parsetexi/tree.h b/tp/Texinfo/XS/parsetexi/tree.h
index 55525174a0..1e58ec933b 100644
--- a/tp/Texinfo/XS/parsetexi/tree.h
+++ b/tp/Texinfo/XS/parsetexi/tree.h
@@ -15,7 +15,6 @@ void insert_slice_into_contents (ELEMENT *to, int idx,
ELEMENT *from,
int start, int end);
ELEMENT *remove_from_contents (ELEMENT *parent, int where);
void remove_slice_from_contents (ELEMENT *parent, int start, int end);
-SOURCE_MARK *remove_from_source_mark_list (SOURCE_MARK_LIST *list, int where);
ELEMENT *last_args_child (ELEMENT *current);
ELEMENT *last_contents_child (ELEMENT *current);
ELEMENT *pop_element_from_args (ELEMENT *parent);
diff --git a/tp/t/results/def/end_of_line_end_file.pl
b/tp/t/results/def/end_of_line_end_file.pl
index 407540292c..2748b561a1 100644
--- a/tp/t/results/def/end_of_line_end_file.pl
+++ b/tp/t/results/def/end_of_line_end_file.pl
@@ -51,6 +51,13 @@ $result_trees{'end_of_line_end_file'} = {
],
'info' => {
'spaces_after_argument' => {
+ 'source_marks' => [
+ {
+ 'counter' => 1,
+ 'position' => 1,
+ 'sourcemark_type' => 'defline_continuation'
+ }
+ ],
'text' => ' '
}
},
diff --git a/tp/t/results/include/double_include.pl
b/tp/t/results/include/double_include.pl
index 8a27e5cc12..8a34f0037b 100644
--- a/tp/t/results/include/double_include.pl
+++ b/tp/t/results/include/double_include.pl
@@ -18,6 +18,11 @@ $result_trees{'double_include'} = {
{
'contents' => [
{
+ 'text' => 'inc_file.texi'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
'source_marks' => [
{
'counter' => 1,
@@ -53,16 +58,11 @@ $result_trees{'double_include'} = {
'macro' => ''
}
},
- 'position' => 14,
+ 'position' => 1,
'sourcemark_type' => 'include',
'status' => 'start'
}
],
- 'text' => 'inc_file.texi'
- }
- ],
- 'info' => {
- 'spaces_after_argument' => {
'text' => ' '
}
},
diff --git a/tp/t/results/macro/macro_in_misc_commands.pl
b/tp/t/results/macro/macro_in_misc_commands.pl
index a036dec206..3ab0009bff 100644
--- a/tp/t/results/macro/macro_in_misc_commands.pl
+++ b/tp/t/results/macro/macro_in_misc_commands.pl
@@ -3030,19 +3030,19 @@ $result_trees{'macro_in_misc_commands'} = {
{
'contents' => [
{
+ 'text' => 'separate'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
'source_marks' => [
{
'counter' => 27,
- 'position' => 9,
+ 'position' => 1,
'sourcemark_type' => 'macro_expansion',
'status' => 'end'
}
],
- 'text' => 'separate'
- }
- ],
- 'info' => {
- 'spaces_after_argument' => {
'text' => '
'
}
diff --git a/tp/t/results/macro/space_macro_after_end.pl
b/tp/t/results/macro/space_macro_after_end.pl
index 5fd0530a31..fd3e849b30 100644
--- a/tp/t/results/macro/space_macro_after_end.pl
+++ b/tp/t/results/macro/space_macro_after_end.pl
@@ -99,6 +99,11 @@ $result_trees{'space_macro_after_end'} = {
{
'contents' => [
{
+ 'text' => 'html'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
'source_marks' => [
{
'counter' => 1,
@@ -113,22 +118,17 @@ $result_trees{'space_macro_after_end'} = {
},
'type' => 'macro_call'
},
- 'position' => 5,
+ 'position' => 1,
'sourcemark_type' => 'macro_expansion',
'status' => 'start'
},
{
'counter' => 1,
- 'position' => 7,
+ 'position' => 3,
'sourcemark_type' => 'macro_expansion',
'status' => 'end'
}
],
- 'text' => 'html'
- }
- ],
- 'info' => {
- 'spaces_after_argument' => {
'text' => ' '
}
},
diff --git a/tp/t/results/macro/space_macro_after_end_verbatim.pl
b/tp/t/results/macro/space_macro_after_end_verbatim.pl
index 4491696d3f..f87bcb6731 100644
--- a/tp/t/results/macro/space_macro_after_end_verbatim.pl
+++ b/tp/t/results/macro/space_macro_after_end_verbatim.pl
@@ -95,6 +95,11 @@ $result_trees{'space_macro_after_end_verbatim'} = {
{
'contents' => [
{
+ 'text' => 'verbatim'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
'source_marks' => [
{
'counter' => 1,
@@ -109,22 +114,17 @@ $result_trees{'space_macro_after_end_verbatim'} = {
},
'type' => 'macro_call'
},
- 'position' => 9,
+ 'position' => 1,
'sourcemark_type' => 'macro_expansion',
'status' => 'start'
},
{
'counter' => 1,
- 'position' => 9,
+ 'position' => 1,
'sourcemark_type' => 'macro_expansion',
'status' => 'end'
}
],
- 'text' => 'verbatim'
- }
- ],
- 'info' => {
- 'spaces_after_argument' => {
'text' => ' '
}
},
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (_relocate_source_marks), tp/Texinfo/XS/parsetexi/source_marks.c (relocate_source_marks): relocate source marks within a range, with the first source mark not necessarily in range. Move relocate_source_marks from def.c to source_marks.c.,
Patrice Dumas <=