[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Source mark for DEL comments
From: |
Patrice Dumas |
Subject: |
branch master updated: Source mark for DEL comments |
Date: |
Mon, 23 Jan 2023 08:06:02 -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 0271f22dd5 Source mark for DEL comments
0271f22dd5 is described below
commit 0271f22dd5f5597851263e62886ca61420340531
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Jan 23 14:05:47 2023 +0100
Source mark for DEL comments
* tp/Texinfo/ParserNonXS.pm (_next_text, tp/Texinfo/XS/parsetexi/api.c
(store_source_mark_list), tp/Texinfo/XS/parsetexi/input.c (INPUT)
(next_text), tp/Texinfo/XS/parsetexi/source_marks.c
(register_source_mark): add a source mark for DEL comment. Push an empty
text
line with a source mark to process it at the end of the line. Rename
file_source_mark as input_source_mark and use it both for files and
text input. Update functions using file_source_mark. Store the
comment line in a 'line' in the source mark.
* tp/Texinfo/XS/parsetexi/source_marks.c (register_source_mark): use
element text.space > 0 and not text.end to associate source mark to
a string that is set but empty.
* tp/Texinfo/ParserNonXS.pm (_close_current),
tp/Texinfo/XS/parsetexi/close.c (close_current): move nesting code
with context commands code.
---
ChangeLog | 21 +++++++++++
tp/Texinfo/ParserNonXS.pm | 41 ++++++++++++++--------
tp/Texinfo/XS/parsetexi/api.c | 6 ++++
tp/Texinfo/XS/parsetexi/close.c | 8 ++---
tp/Texinfo/XS/parsetexi/input.c | 37 +++++++++++++++----
tp/Texinfo/XS/parsetexi/source_marks.c | 12 +++++--
tp/Texinfo/XS/parsetexi/tree.c | 2 ++
tp/Texinfo/XS/parsetexi/tree_types.h | 6 +++-
tp/t/results/coverage/delcomment.pl | 10 ++++++
.../coverage/delcomment_followed_by_cpp_line.pl | 30 ++++++++++++++++
10 files changed, 146 insertions(+), 27 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 981f449de5..9fa97ae6c9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2023-01-23 Patrice Dumas <pertusus@free.fr>
+
+ Source mark for DEL comments
+
+ * tp/Texinfo/ParserNonXS.pm (_next_text, tp/Texinfo/XS/parsetexi/api.c
+ (store_source_mark_list), tp/Texinfo/XS/parsetexi/input.c (INPUT)
+ (next_text), tp/Texinfo/XS/parsetexi/source_marks.c
+ (register_source_mark): add a source mark for DEL comment. Push an
empty text
+ line with a source mark to process it at the end of the line. Rename
+ file_source_mark as input_source_mark and use it both for files and
+ text input. Update functions using file_source_mark. Store the
+ comment line in a 'line' in the source mark.
+
+ * tp/Texinfo/XS/parsetexi/source_marks.c (register_source_mark): use
+ element text.space > 0 and not text.end to associate source mark to
+ a string that is set but empty.
+
+ * tp/Texinfo/ParserNonXS.pm (_close_current),
+ tp/Texinfo/XS/parsetexi/close.c (close_current): move nesting code
+ with context commands code.
+
2023-01-22 Patrice Dumas <pertusus@free.fr>
Nesting context, @*ref, @footnote, @*caption checking perl parser
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 194c215334..11e7a1cdb7 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -2010,12 +2010,13 @@ sub _close_current($$$;$$)
$expected_context = 'ct_brace_command';
}
$self->_pop_context([$expected_context], $source_info, $current);
- }
- $self->{'nesting_context'}->{'footnote'} -= 1
- if ($current->{'cmdname'} eq 'footnote');
- $self->{'nesting_context'}->{'caption'} -= 1
- if ($current->{'cmdname'} eq 'caption'
+
+ $self->{'nesting_context'}->{'footnote'} -= 1
+ if ($current->{'cmdname'} eq 'footnote');
+ $self->{'nesting_context'}->{'caption'} -= 1
+ if ($current->{'cmdname'} eq 'caption'
or $current->{'cmdname'} eq 'shortcaption');
+ }
$current = _close_brace_command($self, $current, $source_info,
$closed_block_command,
$interrupting_command);
@@ -2327,7 +2328,14 @@ sub _next_text($;$)
$line .= "\n";
}
# DEL as comment character
- $line =~ s/\x{7F}.*\s*//;
+ if ($line =~ s/\x{7F}(.*\s*)//) {
+ _input_push_text($self, '',
+ $input->{'input_source_info'}->{'line_nr'});
+ my $delcomment_source_mark = {'sourcemark_type' => 'delcomment'};
+ $delcomment_source_mark->{'line'} = $1 if ($1 ne '');
+ $self->{'input'}->[0]->{'input_source_mark'}
+ = $delcomment_source_mark;
+ }
$input->{'input_source_info'}->{'line_nr'}++;
return ($line, { %{$input->{'input_source_info'}} });
}
@@ -2353,14 +2361,19 @@ sub _next_text($;$)
$file_name, $!));
}
delete $previous_input->{'fh'};
- if (defined($previous_input->{'file_source_mark'})) {
- my $end_include_source_mark
- = { %{$previous_input->{'file_source_mark'}} };
- $end_include_source_mark->{'status'} = 'end';
- delete $end_include_source_mark->{'element'};
+ if (defined($previous_input->{'input_source_mark'})) {
+ my $end_file_source_mark
+ = { %{$previous_input->{'input_source_mark'}} };
+ $end_file_source_mark->{'status'} = 'end';
+ delete $end_file_source_mark->{'element'};
_register_source_mark($self, $current,
- $end_include_source_mark);
+ $end_file_source_mark);
}
+ } elsif (defined($previous_input->{'input_source_mark'})) {
+ my $end_text_source_mark
+ = { %{$previous_input->{'input_source_mark'}} };
+ _register_source_mark($self, $current,
+ $end_text_source_mark);
}
# keep the first input level to have a permanent source for
# source_info, even when nothing is returned and the first input
@@ -3210,7 +3223,7 @@ sub _end_line_misc_line($$$)
print STDERR "Included $included_file_path\n" if
($self->{'DEBUG'});
$include_source_mark = {'sourcemark_type' => $command,
'status' => 'start'};
- $self->{'input'}->[0]->{'file_source_mark'} = $include_source_mark;
+ $self->{'input'}->[0]->{'input_source_mark'} =
$include_source_mark;
} else {
# FIXME $text does not show the include directory. Using
# $included_file_path would require decoding to character string
@@ -5788,7 +5801,7 @@ sub _process_remaining_on_line($$$$)
# Used in @math
$current = $current->{'parent'};
# the following will not happen for footnote if there is
- # a paragraph withing the footnote
+ # a paragraph within the footnote
} elsif ($current->{'parent'}
and $current->{'parent'}->{'cmdname'}
and exists($self->{'brace_commands'}
diff --git a/tp/Texinfo/XS/parsetexi/api.c b/tp/Texinfo/XS/parsetexi/api.c
index 8342e19406..78760082ed 100644
--- a/tp/Texinfo/XS/parsetexi/api.c
+++ b/tp/Texinfo/XS/parsetexi/api.c
@@ -542,6 +542,11 @@ store_source_mark_list (ELEMENT *e)
element_to_perl_hash (e);
STORE("element", newRV_inc ((SV *)e->hv));
}
+ if (s_mark->line)
+ {
+ SV *sv = newSVpv_utf8 (s_mark->line, 0);
+ STORE("line", sv);
+ }
#define SAVE_S_M_STATUS(X) \
case SM_status_ ## X: \
@@ -577,6 +582,7 @@ store_source_mark_list (ELEMENT *e)
{
SAVE_S_M_TYPE (include)
SAVE_S_M_TYPE (setfilename)
+ SAVE_S_M_TYPE (delcomment)
}
av_push (av, newRV_inc ((SV *)source_mark));
diff --git a/tp/Texinfo/XS/parsetexi/close.c b/tp/Texinfo/XS/parsetexi/close.c
index 1d4323b328..f640eb24e0 100644
--- a/tp/Texinfo/XS/parsetexi/close.c
+++ b/tp/Texinfo/XS/parsetexi/close.c
@@ -282,12 +282,12 @@ close_current (ELEMENT *current,
}
else if (pop_context () != ct_brace_command)
fatal ("context brace command context expected");
+ if (current->cmd == CM_footnote)
+ nesting_context.footnote--;
+ if (current->cmd == CM_caption || current->cmd ==
CM_shortcaption)
+ nesting_context.caption--;
}
- if (current->cmd == CM_footnote)
- nesting_context.footnote--;
- if (current->cmd == CM_caption || current->cmd == CM_shortcaption)
- nesting_context.caption--;
current = close_brace_command (current, closed_block_command,
interrupting_command);
}
diff --git a/tp/Texinfo/XS/parsetexi/input.c b/tp/Texinfo/XS/parsetexi/input.c
index 17b4cc22b4..9d0df207c3 100644
--- a/tp/Texinfo/XS/parsetexi/input.c
+++ b/tp/Texinfo/XS/parsetexi/input.c
@@ -51,7 +51,7 @@ typedef struct {
into lines. */
char *value_flag; /* value flag if the input text is a @value
explansion */
- SOURCE_MARK *file_source_mark;
+ SOURCE_MARK *input_source_mark;
} INPUT;
static char *input_pushback_string;
@@ -462,7 +462,17 @@ next_text (ELEMENT *current)
/* Strip off a comment. */
comment = strchr (line, '\x7F');
if (comment)
- *comment = '\0';
+ {
+ SOURCE_MARK *source_mark
+ = new_source_mark(SM_type_delcomment);
+ *comment = '\0';
+ if (*(comment+1) != '\0')
+ source_mark->line = convert_to_utf8 (strdup (comment+1));
+ else
+ source_mark->line = 0;
+ input_push_text(strdup(""), i->source_info.line_nr, 0, 0);
+ set_input_source_mark(source_mark);
+ }
i->source_info.line_nr++;
current_source_info = i->source_info;
@@ -487,10 +497,10 @@ next_text (ELEMENT *current)
fprintf (stderr, "error on closing %s: %s",
input_stack[input_number - 1].source_info.file_name,
strerror (errno));
- if (input_stack[input_number - 1].file_source_mark)
+ if (input_stack[input_number - 1].input_source_mark)
{
SOURCE_MARK *input_source_mark
- = input_stack[input_number - 1].file_source_mark;
+ = input_stack[input_number - 1].input_source_mark;
SOURCE_MARK *end_include_source_mark
= new_source_mark(input_source_mark->type);
end_include_source_mark->counter
@@ -500,6 +510,20 @@ next_text (ELEMENT *current)
}
}
}
+ else if (input_stack[input_number - 1].input_source_mark)
+ {
+ /* FIXME free the delcomment input_source_mark here, as it is not
+ associated to an element */
+ SOURCE_MARK *input_source_mark
+ = input_stack[input_number - 1].input_source_mark;
+ SOURCE_MARK *end_include_source_mark
+ = new_source_mark(input_source_mark->type);
+ end_include_source_mark->counter
+ = input_source_mark->counter;
+ end_include_source_mark->line
+ = input_source_mark->line;
+ register_source_mark(current, end_include_source_mark);
+ }
input_number--;
}
@@ -539,6 +563,7 @@ input_push_text (char *text, int line_number, char *macro,
char *value_flag)
}
input_stack[input_number].source_info.file_name = save_string (filename);
input_stack[input_number].source_info.macro = save_string (macro);
+ input_stack[input_number].input_source_mark = 0;
input_stack[input_number].value_flag = value_flag;
input_number++;
}
@@ -546,7 +571,7 @@ input_push_text (char *text, int line_number, char *macro,
char *value_flag)
void
set_input_source_mark (SOURCE_MARK *source_mark)
{
- input_stack[input_number - 1].file_source_mark = source_mark;
+ input_stack[input_number - 1].input_source_mark = source_mark;
}
/* For filenames and macro names, it is possible that they won't be referenced
@@ -726,7 +751,7 @@ input_push_file (char *filename)
input_stack[input_number].source_info.file_name = filename;
input_stack[input_number].source_info.line_nr = 0;
input_stack[input_number].source_info.macro = 0;
- input_stack[input_number].file_source_mark = 0;
+ input_stack[input_number].input_source_mark = 0;
input_stack[input_number].text = 0;
input_stack[input_number].ptext = 0;
input_number++;
diff --git a/tp/Texinfo/XS/parsetexi/source_marks.c
b/tp/Texinfo/XS/parsetexi/source_marks.c
index 4d6fcf9cef..2c793e394d 100644
--- a/tp/Texinfo/XS/parsetexi/source_marks.c
+++ b/tp/Texinfo/XS/parsetexi/source_marks.c
@@ -21,6 +21,7 @@
int include_counter = 0;
int setfilename_counter = 0;
+int delcomment_counter = 0;
SOURCE_MARK *
new_source_mark (enum source_mark_type type)
@@ -70,7 +71,6 @@ void
register_source_mark (ELEMENT *e, SOURCE_MARK *source_mark)
{
ELEMENT *mark_element;
- SOURCE_MARK_LIST *s_mark_list;
if (source_mark->counter == -1)
{
@@ -84,12 +84,19 @@ register_source_mark (ELEMENT *e, SOURCE_MARK *source_mark)
setfilename_counter++;
source_mark->counter = setfilename_counter;
}
+ else if (source_mark->type == SM_type_delcomment)
+ {
+ delcomment_counter++;
+ source_mark->counter = delcomment_counter;
+ }
}
if (e->contents.number > 0)
{
ELEMENT *last_child = last_contents_child (e);
- if (last_child->text.end > 0)
+ /* use last_child->text.space and not last_child->text.end
+ to associate to element with set but empty text string */
+ if (last_child->text.space > 0)
{
mark_element = last_child;
source_mark->location = source_mark_location_text;
@@ -117,4 +124,5 @@ source_marks_reset_counters (void)
{
include_counter = 0;
setfilename_counter = 0;
+ delcomment_counter = 0;
}
diff --git a/tp/Texinfo/XS/parsetexi/tree.c b/tp/Texinfo/XS/parsetexi/tree.c
index 3dc029fa15..5bbba62033 100644
--- a/tp/Texinfo/XS/parsetexi/tree.c
+++ b/tp/Texinfo/XS/parsetexi/tree.c
@@ -169,6 +169,8 @@ destroy_source_mark (SOURCE_MARK *source_mark)
{
if (source_mark->element)
destroy_element_and_children (source_mark->element);
+ if (source_mark->line)
+ free (source_mark->line);
free (source_mark);
}
diff --git a/tp/Texinfo/XS/parsetexi/tree_types.h
b/tp/Texinfo/XS/parsetexi/tree_types.h
index 4762cae9c5..1e8e317546 100644
--- a/tp/Texinfo/XS/parsetexi/tree_types.h
+++ b/tp/Texinfo/XS/parsetexi/tree_types.h
@@ -44,7 +44,9 @@ enum extra_type {
to avoid using 0 for easier to debug code */
enum source_mark_type { SM_type_none,
SM_type_include,
- SM_type_setfilename };
+ SM_type_setfilename,
+ SM_type_delcomment
+};
enum source_mark_location { source_mark_location_none,
source_mark_location_text,
@@ -89,6 +91,8 @@ typedef struct SOURCE_MARK {
int counter;
struct ELEMENT *element; /* needed for elements removed
from the tree */
+ char *line; /* used when the information is not available as
+ an element, for DEL comments, for instance */
} SOURCE_MARK;
typedef struct SOURCE_MARK_LIST {
diff --git a/tp/t/results/coverage/delcomment.pl
b/tp/t/results/coverage/delcomment.pl
index 3de5de1dc4..cc076884c6 100644
--- a/tp/t/results/coverage/delcomment.pl
+++ b/tp/t/results/coverage/delcomment.pl
@@ -97,6 +97,16 @@ $result_trees{'delcomment'} = {
'type' => 'empty_line'
},
{
+ 'source_marks' => [
+ {
+ 'counter' => 1,
+ 'line' => ' this is a comment.
+',
+ 'location' => 'text',
+ 'position' => 0,
+ 'sourcemark_type' => 'delcomment'
+ }
+ ],
'text' => '
',
'type' => 'empty_line'
diff --git a/tp/t/results/coverage/delcomment_followed_by_cpp_line.pl
b/tp/t/results/coverage/delcomment_followed_by_cpp_line.pl
index 6fdea076f7..031626380b 100644
--- a/tp/t/results/coverage/delcomment_followed_by_cpp_line.pl
+++ b/tp/t/results/coverage/delcomment_followed_by_cpp_line.pl
@@ -128,6 +128,16 @@ $result_trees{'delcomment_followed_by_cpp_line'} = {
'type' => 'empty_line'
},
{
+ 'source_marks' => [
+ {
+ 'counter' => 2,
+ 'line' => ' this is a comment.
+',
+ 'location' => 'text',
+ 'position' => 2,
+ 'sourcemark_type' => 'delcomment'
+ }
+ ],
'text' => ' ',
'type' => 'spaces_before_paragraph'
},
@@ -166,6 +176,16 @@ $result_trees{'delcomment_followed_by_cpp_line'} = {
{
'contents' => [
{
+ 'source_marks' => [
+ {
+ 'counter' => 3,
+ 'line' => ' this is a comment.
+',
+ 'location' => 'text',
+ 'position' => 2,
+ 'sourcemark_type' => 'delcomment'
+ }
+ ],
'text' => 'a #line 206 "a_file_after_text_space_del_comment"
'
}
@@ -192,6 +212,16 @@ $result_trees{'delcomment_followed_by_cpp_line'} = {
'type' => 'empty_line'
}
],
+ 'source_marks' => [
+ {
+ 'counter' => 1,
+ 'line' => ' this is a comment.
+',
+ 'location' => 'text',
+ 'position' => 0,
+ 'sourcemark_type' => 'delcomment'
+ }
+ ],
'type' => 'before_node_section'
},
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Source mark for DEL comments,
Patrice Dumas <=