[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Patrice Dumas |
Date: |
Sun, 29 Sep 2024 06:18:22 -0400 (EDT) |
branch: master
commit ac885891c948e70932f04d8f69cec1f40510a9e5
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Jun 17 19:12:06 2024 +0200
* tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line): call with a
pointer on element, not a pointer on pointer. Update callers.
* tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line)
(do_abort_empty_line, merge_text): move do_abort_empty_line out of
abort_empty_line and call it directly in merge_text instead of redoing
the same check of elements again in abort_empty_line. Change
merge_text code to be simpler.
---
ChangeLog | 11 +++
tp/Texinfo/XS/main/element_types.txt | 3 +
tp/Texinfo/XS/parsetexi/close.c | 2 +-
tp/Texinfo/XS/parsetexi/menus.c | 2 +-
tp/Texinfo/XS/parsetexi/parser.c | 157 ++++++++++++++++++-----------------
tp/Texinfo/XS/parsetexi/parser.h | 2 +-
tp/Texinfo/XS/parsetexi/separator.c | 12 +--
7 files changed, 103 insertions(+), 86 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 4ae34d64b4..ad6f84bc8c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2024-06-17 Patrice Dumas <pertusus@free.fr>
+
+ * tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line): call with a
+ pointer on element, not a pointer on pointer. Update callers.
+
+ * tp/Texinfo/XS/parsetexi/parser.c (abort_empty_line)
+ (do_abort_empty_line, merge_text): move do_abort_empty_line out of
+ abort_empty_line and call it directly in merge_text instead of redoing
+ the same check of elements again in abort_empty_line. Change
+ merge_text code to be simpler.
+
2024-06-17 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/XS/parsetexi/parser.c (merge_text): modify code to have
diff --git a/tp/Texinfo/XS/main/element_types.txt
b/tp/Texinfo/XS/main/element_types.txt
index 5657ab4604..1b1658f951 100644
--- a/tp/Texinfo/XS/main/element_types.txt
+++ b/tp/Texinfo/XS/main/element_types.txt
@@ -84,8 +84,11 @@ menu_comment
# Used internally
internal_menu_star text
+# right after a line command or block command
internal_spaces_after_command text
+# after opening brace or comma
internal_spaces_before_argument text
+# on @*index commands line before brace specific @-command
internal_spaces_before_brace_in_index text
internal_spaces_after_cmd_before_arg text
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 5a489705ee..db0c4027ff 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -439,7 +439,7 @@ close_current (ELEMENT *current,
== ET_internal_spaces_before_argument)
{
/* remove spaces element from tree and update extra values */
- abort_empty_line (¤t);
+ abort_empty_line (current);
}
current = current->parent;
break;
diff --git a/tp/Texinfo/XS/parsetexi/menus.c b/tp/Texinfo/XS/parsetexi/menus.c
index 856b94811d..59ed266391 100644
--- a/tp/Texinfo/XS/parsetexi/menus.c
+++ b/tp/Texinfo/XS/parsetexi/menus.c
@@ -131,7 +131,7 @@ handle_menu_entry_separators (ELEMENT **current_inout,
const char **line_inout)
ELEMENT *star;
debug ("MENU STAR");
- abort_empty_line (¤t);
+ abort_empty_line (current);
line++; /* Past the '*'. */
star = new_text_element (ET_internal_menu_star);
diff --git a/tp/Texinfo/XS/parsetexi/parser.c b/tp/Texinfo/XS/parsetexi/parser.c
index 97bef6686d..687851b184 100644
--- a/tp/Texinfo/XS/parsetexi/parser.c
+++ b/tp/Texinfo/XS/parsetexi/parser.c
@@ -569,7 +569,7 @@ parse_texi_document (void)
static int
-begin_paragraph_p (ELEMENT *current)
+begin_paragraph_p (const ELEMENT *current)
{
/* we want to avoid
paragraphs, line_arg, brace_container, brace_arg, root_line,
@@ -705,6 +705,61 @@ end_preformatted (ELEMENT *current,
*/
ELEMENT *internal_space_holder;
+static void
+do_abort_empty_line (ELEMENT *current, ELEMENT *last_elt)
+{
+ if (global_parser_conf.debug)
+ {
+ debug_nonl ("ABORT EMPTY in ");
+ debug_parser_print_element (current, 0);
+ debug_nonl ("(p:%d): %s; ", in_paragraph_context (current_context ()),
+ type_data[last_elt->type].name);
+ debug_nonl ("|%s|",
+ last_elt->e.text->end > 0 ? last_elt->e.text->text : "");
+ debug ("");
+ }
+
+
+ /* Remove element altogether if it's empty. */
+ if (last_elt->e.text->end == 0)
+ {
+ ELEMENT *e = pop_element_from_contents (current);
+ if (e->source_mark_list)
+ {
+ SOURCE_MARK_LIST *source_mark_list = e->source_mark_list;
+
+ int i;
+ for (i = 0; i < source_mark_list->number; i++)
+ place_source_mark (current, source_mark_list->list[i]);
+ free_element_source_mark_list (e);
+ }
+
+ destroy_element (e);
+ }
+ else if (last_elt->type == ET_empty_line)
+ {
+ last_elt->type = begin_paragraph_p (current)
+ ? ET_spaces_before_paragraph : ET_normal_text;
+ }
+ else if (last_elt->type == ET_internal_spaces_after_command
+ || last_elt->type == ET_internal_spaces_before_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;
+ }
+}
+
/* Add LEN_TEXT of TEXT to the contents of CURRENT, maybe starting a new
paragraph.
TEXT may not have a NUL character at TEXT + LEN_TEXT.
@@ -715,7 +770,6 @@ ELEMENT *
merge_text (ELEMENT *current, const char *text, size_t len_text,
ELEMENT *transfer_marks_element)
{
- int no_merge_with_following_text = 0;
int leading_spaces = 0;
ELEMENT *last_element = last_contents_child (current);
@@ -735,6 +789,8 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
|| last_element->type == ET_internal_spaces_before_argument
|| last_element->type == ET_spaces_after_close_brace))
{
+ int no_merge_with_following_text
+ = (last_element->type != ET_empty_line);
if (leading_spaces)
{
if (global_parser_conf.debug)
@@ -750,11 +806,16 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
len_text -= leading_spaces;
}
- if (last_element->type != ET_empty_line)
- no_merge_with_following_text = 1;
- }
+ do_abort_empty_line (current, last_element);
- abort_empty_line (¤t);
+ if (no_merge_with_following_text)
+ /* we do not merge these special types, unset last_element */
+ last_element = 0;
+ else
+ /* need to retrieve the last element in case the one obtained above
+ was removed in do_abort_empty_line */
+ last_element = last_contents_child (current);
+ }
paragraph = begin_paragraph (current);
if (paragraph)
@@ -766,11 +827,7 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
}
}
- /* need to retrieve the last element in case the one obtained above was
- removed in abort_empty_line */
- last_element = last_contents_child (current);
- if (!no_merge_with_following_text
- && last_element
+ if (last_element
/* can actually be normal_text, and some space elements */
&& type_data[last_element->type].flags & TF_text
&& !strchr (last_element->e.text->text, '\n'))
@@ -779,7 +836,8 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
if (transfer_marks_element
&& transfer_marks_element->source_mark_list)
{
- size_t additional_length = count_multibyte
(last_element->e.text->text);
+ size_t additional_length
+ = count_multibyte (last_element->e.text->text);
SOURCE_MARK_LIST *s_mark_list
= transfer_marks_element->source_mark_list;
int i;
@@ -830,11 +888,8 @@ merge_text (ELEMENT *current, const char *text, size_t
len_text,
or merge text, and return true.
*/
int
-abort_empty_line (ELEMENT **current_inout)
+abort_empty_line (ELEMENT *current)
{
- ELEMENT *current = *current_inout;
- int retval;
-
ELEMENT *last_child = last_contents_child (current);
if (last_child
@@ -844,63 +899,11 @@ abort_empty_line (ELEMENT **current_inout)
|| last_child->type == ET_internal_spaces_before_argument
|| last_child->type == ET_spaces_after_close_brace))
{
- retval = 1;
- if (global_parser_conf.debug)
- {
- debug_nonl ("ABORT EMPTY in ");
- debug_parser_print_element (current, 0);
- debug_nonl ("(p:%d): %s; ", in_paragraph_context (current_context
()),
- type_data[last_child->type].name);
- debug_nonl ("|%s|",
- last_child->e.text->end > 0 ? last_child->e.text->text :
"");
- debug ("");
- }
-
-
- /* Remove element altogether if it's empty. */
- if (last_child->e.text->end == 0)
- {
- ELEMENT *e = pop_element_from_contents (current);
- if (e->source_mark_list)
- {
- SOURCE_MARK_LIST *source_mark_list = e->source_mark_list;
-
- int i;
- for (i = 0; i < source_mark_list->number; i++)
- place_source_mark (current, source_mark_list->list[i]);
- free_element_source_mark_list (e);
- }
-
- destroy_element (e);
- }
- else if (last_child->type == ET_empty_line)
- {
- last_child->type = begin_paragraph_p (current)
- ? ET_spaces_before_paragraph : ET_normal_text;
- }
- else if (last_child->type == ET_internal_spaces_after_command
- || last_child->type == ET_internal_spaces_before_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;
- }
+ do_abort_empty_line (current, last_child);
+ return 1;
}
- else
- retval = 0;
- *current_inout = current;
- return retval;
+ return 0;
}
/* The caller verifies that last_elt is a text element */
@@ -2206,7 +2209,7 @@ process_remaining_on_line (ELEMENT **current_inout, const
char **line_inout)
for the converters to handle */
ELEMENT *value_elt;
- abort_empty_line (¤t);
+ abort_empty_line (current);
line_warn ("undefined flag: %s", flag);
@@ -2232,7 +2235,7 @@ process_remaining_on_line (ELEMENT **current_inout, const
char **line_inout)
{ /* CM_txiinternalvalue */
ELEMENT *txiinternalvalue_elt;
- abort_empty_line (¤t);
+ abort_empty_line (current);
txiinternalvalue_elt
= new_value_element (cmd, line, flag_len,
@@ -2281,7 +2284,7 @@ process_remaining_on_line (ELEMENT **current_inout, const
char **line_inout)
/* warn on not appearing at line beginning. Need to do before closing
paragraph as it also closes the empty line */
if (!def_line_continuation
- && !abort_empty_line (¤t)
+ && !abort_empty_line (current)
&& ((cmd == CM_node || cmd == CM_bye)
|| (command_data(cmd).flags & CF_block)
|| ((command_data(cmd).flags & CF_line)
@@ -2348,7 +2351,7 @@ process_remaining_on_line (ELEMENT **current_inout, const
char **line_inout)
}
else
/* an internal and temporary space type that is converted to
- a normal space without type if followed by text or a
+ a normal space if followed by text or a
"spaces_at_end" if followed by spaces only when the
index or subentry command is done. */
{
@@ -2577,7 +2580,7 @@ parse_texi (ELEMENT *root_elt, ELEMENT *current_elt)
== ET_internal_spaces_before_argument)
{
/* Remove this element and update 'info' values. */
- abort_empty_line (¤t);
+ abort_empty_line (current);
}
e = new_text_element (ET_empty_line);
@@ -2606,7 +2609,7 @@ parse_texi (ELEMENT *root_elt, ELEMENT *current_elt)
if (!line)
{
debug ("END LINE in line loop STILL_MORE_TO_PROCESS");
- abort_empty_line (¤t);
+ abort_empty_line (current);
current = end_line (current);
break;
}
diff --git a/tp/Texinfo/XS/parsetexi/parser.h b/tp/Texinfo/XS/parsetexi/parser.h
index 5bd3708374..7eb48e7400 100644
--- a/tp/Texinfo/XS/parsetexi/parser.h
+++ b/tp/Texinfo/XS/parsetexi/parser.h
@@ -72,7 +72,7 @@ CONDITIONAL_STACK_ITEM *pop_conditional_stack (void);
CONDITIONAL_STACK_ITEM *top_conditional_stack (void);
extern size_t conditional_number;
-int abort_empty_line (ELEMENT **current_inout);
+int abort_empty_line (ELEMENT *current);
ELEMENT *end_paragraph (ELEMENT *current,
enum command_id closed_block_command,
enum command_id interrupting_command);
diff --git a/tp/Texinfo/XS/parsetexi/separator.c
b/tp/Texinfo/XS/parsetexi/separator.c
index 607f4cd47d..cb2eac3cf1 100644
--- a/tp/Texinfo/XS/parsetexi/separator.c
+++ b/tp/Texinfo/XS/parsetexi/separator.c
@@ -214,7 +214,7 @@ handle_open_brace (ELEMENT *current, const char
**line_inout)
|| current->parent->flags & EF_def_line))
{
ELEMENT *b, *e;
- abort_empty_line (¤t);
+ abort_empty_line (current);
b = new_element (ET_bracketed_arg);
add_to_element_contents (current, b);
current = b;
@@ -243,7 +243,7 @@ handle_open_brace (ELEMENT *current, const char
**line_inout)
{
ELEMENT *b = new_element (ET_balanced_braces);
ELEMENT *open_brace = new_text_element (ET_normal_text);
- abort_empty_line (¤t);
+ abort_empty_line (current);
b->e.c->source_info = current_source_info;
add_to_element_contents (current, b);
current = b;
@@ -291,7 +291,7 @@ handle_close_brace (ELEMENT *current, const char
**line_inout)
if (current->parent && current->parent->type == ET_brace_command_context
&& current->type == ET_paragraph)
{
- abort_empty_line (¤t);
+ abort_empty_line (current);
debug ("IN BRACE_COMMAND_CONTEXT end paragraph");
current = end_paragraph (current, 0, 0);
}
@@ -303,14 +303,14 @@ handle_close_brace (ELEMENT *current, const char
**line_inout)
}
else if (current->type == ET_bracketed_arg)
{
- abort_empty_line (¤t);
+ abort_empty_line (current);
current = current->parent;
}
else if (command_flags(current->parent) & CF_brace)
{
enum command_id closed_command;
- abort_empty_line (¤t);
+ abort_empty_line (current);
/* determine if trailing spaces are ignored */
if (command_data(current->parent->e.c->cmd).data == BRACE_arguments)
@@ -621,7 +621,7 @@ handle_comma (ELEMENT *current, const char **line_inout)
enum element_type type;
ELEMENT *new_arg, *e;
- abort_empty_line (¤t);
+ abort_empty_line (current);
isolate_last_space (current);
type = current->type;