[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: * tp/Texinfo/ParserNonXS.pm (_merge_text), tp/Tex
From: |
Patrice Dumas |
Subject: |
branch master updated: * tp/Texinfo/ParserNonXS.pm (_merge_text), tp/Texinfo/XS/parsetexi/parser.c (merge_text): handle especially the case of no last element, as there cannot be paragraph or special text elements handling in that case. |
Date: |
Sun, 29 Sep 2024 08:03:52 -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 650de228a0 * tp/Texinfo/ParserNonXS.pm (_merge_text),
tp/Texinfo/XS/parsetexi/parser.c (merge_text): handle especially the case of no
last element, as there cannot be paragraph or special text elements handling in
that case.
650de228a0 is described below
commit 650de228a0d2335f58becab413218526c6dfc9a1
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sun Jun 23 17:58:14 2024 +0200
* tp/Texinfo/ParserNonXS.pm (_merge_text),
tp/Texinfo/XS/parsetexi/parser.c (merge_text): handle especially the
case of no last element, as there cannot be paragraph or special text
elements handling in that case.
* tp/Texinfo/ParserNonXS.pm (_close_current)
(_move_last_space_to_element, _abort_empty_line, _end_line),
tp/Texinfo/XS/parsetexi/close.c (close_current),
tp/Texinfo/XS/parsetexi/end_line.c (end_line),
tp/Texinfo/XS/parsetexi/parser.c (move_last_space_to_element)
(do_abort_empty_line): separate code moving a last space children as
info spaces_before_argument in element out of abort_empty_line to
move_last_space_to_element, and call directly
move_last_space_to_element when relevant.
---
ChangeLog | 17 +++++++++
tp/Texinfo/ParserNonXS.pm | 53 ++++++++++++++++++---------
tp/Texinfo/XS/parsetexi/close.c | 2 +-
tp/Texinfo/XS/parsetexi/end_line.c | 2 +-
tp/Texinfo/XS/parsetexi/parser.c | 73 ++++++++++++++++++++++----------------
tp/Texinfo/XS/parsetexi/parser.h | 1 +
6 files changed, 98 insertions(+), 50 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 6b56fa0ba7..7a67934fe4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2024-06-23 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/ParserNonXS.pm (_merge_text),
+ tp/Texinfo/XS/parsetexi/parser.c (merge_text): handle especially the
+ case of no last element, as there cannot be paragraph or special text
+ elements handling in that case.
+
+ * tp/Texinfo/ParserNonXS.pm (_close_current)
+ (_move_last_space_to_element, _abort_empty_line, _end_line),
+ tp/Texinfo/XS/parsetexi/close.c (close_current),
+ tp/Texinfo/XS/parsetexi/end_line.c (end_line),
+ tp/Texinfo/XS/parsetexi/parser.c (move_last_space_to_element)
+ (do_abort_empty_line): separate code moving a last space children as
+ info spaces_before_argument in element out of abort_empty_line to
+ move_last_space_to_element, and call directly
+ move_last_space_to_element when relevant.
+
2024-06-23 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/ParserNonXS.pm (_abort_empty_line): define more variables
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 8616d05b26..f758a42e81 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2126,7 +2126,7 @@ sub _close_current($$$;$$)
and $current->{'contents'}->[0]->{'type'}
eq 'internal_spaces_before_argument') {
# remove spaces element from tree and update extra values
- _abort_empty_line($self, $current);
+ _move_last_space_to_element($self, $current);
}
$current = $current->{'parent'};
} elsif ($current->{'type'} eq 'balanced_braces') {
@@ -2226,12 +2226,25 @@ sub _close_commands($$$;$$)
sub _merge_text {
my ($self, $current, $text, $transfer_marks_element) = @_;
- my $last_element;
-
- if ($current->{'contents'}) {
- $last_element = $current->{'contents'}->[-1];
+ # paragraphs are only started in empty lines or in context brace
+ # commands, if there is nothing in the current element, cannot
+ # be in a case where a paragraph is started.
+ # Also, elements without anything in them are only brace_container
+ # or menu_entry_name, otherwise there is always some kind of element
+ # leading added for leading spaces when the element is created
+ if (!$current->{'contents'}) {
+ my $new_element = { 'text' => $text, 'parent' => $current };
+ _transfer_source_marks($transfer_marks_element, $new_element)
+ if ($transfer_marks_element);
+ $current->{'contents'} = [];
+ push @{$current->{'contents'}}, $new_element;
+ print STDERR "NEW TEXT (merge): $text|||\n"
+ if ($self->{'conf'}->{'DEBUG'});
+ return $current;
}
+ my $last_element = $current->{'contents'}->[-1];
+
my $paragraph;
my $no_merge_with_following_text = 0;
@@ -2957,10 +2970,25 @@ sub _pop_element_from_contents($$)
return $popped_element;
}
+sub _move_last_space_to_element($$) {
+ my ($self, $current) = @_;
+
+ # Remove element from main tree. It will still be referenced in
+ # the 'info' hash as 'spaces_before_argument'.
+ my $spaces_before_argument = _pop_element_from_contents($self, $current);
+ delete $spaces_before_argument->{'type'};
+ delete $spaces_before_argument->{'parent'};
+ my $owning_element = $self->{'internal_space_holder'};
+ $owning_element->{'info'} = {} if (!exists($owning_element->{'info'}));
+ $owning_element->{'info'}->{'spaces_before_argument'}
+ = $spaces_before_argument;
+ $self->{'internal_space_holder'} = undef;
+}
+
# each time a new line appeared, a container is opened to hold the text
# consisting only of spaces. This container is removed here, typically
# this is called when non-space happens on a line.
-sub _abort_empty_line {
+sub _abort_empty_line($$) {
my ($self, $current) = @_;
if ($current->{'contents'}) {
@@ -3011,16 +3039,7 @@ sub _abort_empty_line {
} elsif ($type eq 'internal_spaces_after_command'
or $type eq 'internal_spaces_before_argument'
or $type eq 'internal_spaces_before_context_argument') {
- # Remove element from main tree. It will still be referenced in
- # the 'info' hash as 'spaces_before_argument'.
- my $spaces_before_argument = _pop_element_from_contents($self,
$current);
- delete $spaces_before_argument->{'type'};
- delete $spaces_before_argument->{'parent'};
- my $owning_element = $self->{'internal_space_holder'};
- $owning_element->{'info'} = {} if
(!exists($owning_element->{'info'}));
- $owning_element->{'info'}->{'spaces_before_argument'}
- = $spaces_before_argument;
- $self->{'internal_space_holder'} = undef;
+ _move_last_space_to_element($self, $current);
}
return 1;
}
@@ -4637,7 +4656,7 @@ sub _end_line($$$)
eq 'internal_spaces_before_context_argument')) {
# Empty spaces after brace or comma till the end of line.
# Remove this element and update 'extra' values.
- _abort_empty_line($self, $current);
+ _move_last_space_to_element($self, $current);
}
# this happens if there is a nesting of line @-commands on a line.
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index d666b521c8..ba33f99bd9 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -443,7 +443,7 @@ close_current (ELEMENT *current,
== ET_internal_spaces_before_argument)
{
/* remove spaces element from tree and update extra values */
- abort_empty_line (current);
+ move_last_space_to_element (current);
}
current = current->parent;
break;
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index ff12fb3051..162dfe02dd 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -1936,7 +1936,7 @@ end_line (ELEMENT *current)
{
/* Empty spaces after brace or comma till the end of line.
Remove this element and update 'extra' values. */
- abort_empty_line (current);
+ move_last_space_to_element (current);
}
/* 'line' or 'def' at top of "context stack" - this happens when
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 6924e402cb..4256e271e6 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -703,6 +703,23 @@ end_preformatted (ELEMENT *current,
*/
ELEMENT *internal_space_holder;
+void
+move_last_space_to_element (ELEMENT *current)
+{
+ /* Remove element from main tree. It will still be referenced in
+ the 'info' hash as 'spaces_before_argument'. */
+ ELEMENT *owning_element;
+ ELEMENT *e = pop_element_from_contents (current);
+ owning_element = internal_space_holder;
+ e->type = ET_other_text;
+ e->parent = 0;
+ if (owning_element->type != ET_context_brace_command)
+ owning_element->elt_info[eit_spaces_before_argument] = e;
+ else
+ owning_element->elt_info[eit_brace_content_spaces_before_argument] = e;
+ internal_space_holder = 0;
+}
+
static void
do_abort_empty_line (ELEMENT *current, ELEMENT *last_elt)
{
@@ -740,19 +757,7 @@ do_abort_empty_line (ELEMENT *current, ELEMENT *last_elt)
|| last_elt->type == ET_internal_spaces_before_argument
|| last_elt->type == ET_internal_spaces_before_context_argument)
{
- /* Remove element from main tree. It will still be referenced in
- the 'info' hash as 'spaces_before_argument'. */
- ELEMENT *owning_element;
- ELEMENT *e = pop_element_from_contents (current);
- owning_element = internal_space_holder;
- e->type = ET_other_text;
- e->parent = 0;
- if (owning_element->type != ET_context_brace_command)
- owning_element->elt_info[eit_spaces_before_argument] = e;
- else
- owning_element->elt_info[eit_brace_content_spaces_before_argument]
- = e;
- internal_space_holder = 0;
+ move_last_space_to_element (current);
}
}
@@ -770,6 +775,17 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
ELEMENT *e;
ELEMENT *last_element = last_contents_child (current);
+ /* paragraphs are only started in empty lines or in context brace
+ commands, if there is nothing in the current element, cannot
+ be in a case where a paragraph is started.
+ Also, elements without anything in them are only brace_container
+ or menu_entry_name, otherwise there is always some kind of element
+ leading added for leading spaces when the element is created */
+ if (!last_element)
+ goto new_text;
+
+ enum element_type last_elt_type = last_element->type;
+
/* determine the number of leading characters in whitespace_chars */
for (; leading_spaces < len_text
&& strchr (whitespace_chars, text[leading_spaces]);
@@ -779,17 +795,13 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
if (leading_spaces < len_text)
{
ELEMENT *paragraph;
- if (last_element
- && (last_element->type == ET_empty_line
- || last_element->type == ET_ignorable_spaces_after_command
- || last_element->type == ET_internal_spaces_after_command
- || last_element->type == ET_internal_spaces_before_argument
- || last_element->type
- == ET_internal_spaces_before_context_argument
- || last_element->type == ET_spaces_after_close_brace))
- {
- int no_merge_with_following_text
- = (last_element->type != ET_empty_line);
+ if ((last_elt_type == ET_empty_line
+ || last_elt_type == ET_ignorable_spaces_after_command
+ || last_elt_type == ET_internal_spaces_after_command
+ || last_elt_type == ET_internal_spaces_before_argument
+ || last_elt_type == ET_internal_spaces_before_context_argument
+ || last_elt_type == ET_spaces_after_close_brace))
+ {
if (leading_spaces)
{
if (global_parser_conf.debug)
@@ -797,7 +809,7 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
char *additional_text_dbg = strndup (text, leading_spaces);
debug ("MERGE_TEXT ADD leading empty |%s| to %s",
additional_text_dbg,
- type_data[last_element->type].name);
+ type_data[last_elt_type].name);
free (additional_text_dbg);
}
text_append_n (last_element->e.text, text, leading_spaces);
@@ -812,6 +824,7 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
*/
e = pop_element_from_contents (current);
e->type = ET_normal_text;
+
paragraph = begin_paragraph (current);
if (paragraph)
{
@@ -823,10 +836,10 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
/* since last_element cannot be empty as this case is
handled just above, the last_element is
always kept in current in do_abort_empty_line
- for an empty_line; its type may have changed */
+ for an empty_line; its type may change */
do_abort_empty_line (current, last_element);
- if (no_merge_with_following_text)
+ if (last_elt_type != ET_empty_line)
/* we do not merge these special types, unset last_element */
last_element = 0;
}
@@ -838,9 +851,7 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
space as handled just above, or after a no_paragraph
command outside of a paragraph or after a non expanded @value
outside of a paragraph (here), because
- - there is always an element where a paragraph can begin, since
- elements without anything in them are only brace_container
- or menu/preformatted contexts
+ - there is always an element where a paragraph can begin
- if the element is not a special space nor a no_paragraph
command, we are already in a paragraph if a paragraph can
be opened.
@@ -854,7 +865,7 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
if (last_element
/* can actually be normal_text, and some space elements */
- && type_data[last_element->type].flags & TF_text
+ && type_data[last_elt_type].flags & TF_text
&& !strchr (last_element->e.text->text, '\n'))
{
/* Transfer source marks */
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index 7eb48e7400..c9145841f1 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -72,6 +72,7 @@ CONDITIONAL_STACK_ITEM *pop_conditional_stack (void);
CONDITIONAL_STACK_ITEM *top_conditional_stack (void);
extern size_t conditional_number;
+void move_last_space_to_element (ELEMENT *current);
int abort_empty_line (ELEMENT *current);
ELEMENT *end_paragraph (ELEMENT *current,
enum command_id closed_block_command,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: * tp/Texinfo/ParserNonXS.pm (_merge_text), tp/Texinfo/XS/parsetexi/parser.c (merge_text): handle especially the case of no last element, as there cannot be paragraph or special text elements handling in that case.,
Patrice Dumas <=