[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Only allow highlighting commands to be redefined
From: |
Patrice Dumas |
Subject: |
branch master updated: Only allow highlighting commands to be redefined with @definfoenclose |
Date: |
Sun, 18 Feb 2024 18:12:13 -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 b447793774 Only allow highlighting commands to be redefined with
@definfoenclose
b447793774 is described below
commit b4477937743ff89ce7d76cee9de89f92971120d8
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Mon Feb 19 00:12:07 2024 +0100
Only allow highlighting commands to be redefined with @definfoenclose
* tp/Texinfo/ParserNonXS.pm (_parse_line_command_args),
tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args):
before redefining with definfoenclose, verify that the command is not
a builtin command, or, if it is, that it is a brace command and a
style* brace command.
* tp/Makefile.tres, tp/t/03coverage_braces.t
(definfoenclose_texinfo_commands): add tests of redefinition of
builtin @-commands by @definfoenclose.
---
ChangeLog | 14 +
NEWS | 1 +
tp/Makefile.tres | 1 +
tp/Texinfo/ParserNonXS.pm | 43 ++-
tp/Texinfo/XS/parsetexi/end_line.c | 14 +
tp/t/03coverage_braces.t | 14 +
.../definfoenclose_texinfo_commands.pl | 424 +++++++++++++++++++++
7 files changed, 494 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 5ff3f650a2..5a0166b732 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-02-18 Patrice Dumas <pertusus@free.fr>
+
+ Only allow highlighting commands to be redefined with @definfoenclose
+
+ * tp/Texinfo/ParserNonXS.pm (_parse_line_command_args),
+ tp/Texinfo/XS/parsetexi/end_line.c (parse_line_command_args):
+ before redefining with definfoenclose, verify that the command is not
+ a builtin command, or, if it is, that it is a brace command and a
+ style* brace command.
+
+ * tp/Makefile.tres, tp/t/03coverage_braces.t
+ (definfoenclose_texinfo_commands): add tests of redefinition of
+ builtin @-commands by @definfoenclose.
+
2024-02-18 Gavin Smith <gavinsmith0123@gmail.com>
* tp/Texinfo/Convert/Plaintext.pm (_stream_encode):
diff --git a/NEWS b/NEWS
index bda82c752f..16938ca73e 100644
--- a/NEWS
+++ b/NEWS
@@ -32,6 +32,7 @@ See the manual for detailed information.
"texinfo_document" domain
. the us-ascii encoding is not tried anymore when looking for a document
output string locale. Accent @-commands can still be used in translations.
+ . only allow highlighting commands to be redefined with @definfoenclose.
. HTML, Texinfo and raw text output:
An implementation of the conversion in C has been included. Set the
`TEXINFO_XS_CONVERT' environment variable to 1 to use.
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index d29202c4ec..bd8e66358a 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -367,6 +367,7 @@ test_files_generated_list =
$(test_tap_files_generated_list) \
t/results/coverage_braces/caption_not_closed.pl \
t/results/coverage_braces/code_not_closed.pl \
t/results/coverage_braces/contain_plain_text_nestings.pl \
+ t/results/coverage_braces/definfoenclose_texinfo_commands.pl \
t/results/coverage_braces/email_possibilities.pl \
t/results/coverage_braces/empty_commands.pl \
t/results/coverage_braces/empty_images.pl \
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 5be83bb764..3f51479f00 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -7685,24 +7685,33 @@ sub _parse_line_command_args($$$)
} elsif ($line =~
s/^([[:alnum:]][[:alnum:]\-]*)\s*,\s*([^\s,]*)\s*,\s*([^\s,]*)$//) {
$args = [$1, $2, $3 ];
my ($cmd_name, $begin, $end) = ($1, $2, $3);
- $self->{'definfoenclose'}->{$cmd_name} = [ $begin, $end ];
- print STDERR "DEFINFOENCLOSE \@$cmd_name: $begin, $end\n"
+ if ($all_commands{$cmd_name}
+ and (!$brace_commands{$cmd_name}
+ or ($brace_commands{$cmd_name} ne 'style_code'
+ and $brace_commands{$cmd_name} ne 'style_no_code'
+ and $brace_commands{$cmd_name} ne 'style_other'))) {
+ $self->_line_error(sprintf(__("cannot redefine with \@%s: %s"),
+ $command, $cmd_name), $source_info);
+ } else {
+ $self->{'definfoenclose'}->{$cmd_name} = [ $begin, $end ];
+ print STDERR "DEFINFOENCLOSE \@$cmd_name: $begin, $end\n"
if ($self->{'DEBUG'});
- delete $self->{'macros'}->{$cmd_name};
- delete $self->{'aliases'}->{$cmd_name};
- # unset @def*index effect
- delete $self->{'line_commands'}->{$cmd_name};
- #delete $self->{'close_paragraph_commands'}->{$cmd_name};
- delete $self->{'no_paragraph_commands'}->{$cmd_name};
- delete $self->{'basic_inline_commands'}->{$cmd_name};
- delete $self->{'command_index'}->{$cmd_name};
- # consistent with XS parser, value not actually used anywhere.
- $self->{'brace_commands'}->{$cmd_name} = 'style_other';
- # this allows to obtain the same result as the XS parser which checks
- # dynamically the brace_commands type
- $self->{'valid_nestings'}->{$cmd_name} = \%in_full_text_commands;
- # note that a built-in command previously in a hash classifying the
- # @-command otherwise will remain there, possibly having specific
effects.
+ delete $self->{'macros'}->{$cmd_name};
+ delete $self->{'aliases'}->{$cmd_name};
+ # unset @def*index effect
+ delete $self->{'line_commands'}->{$cmd_name};
+ #delete $self->{'close_paragraph_commands'}->{$cmd_name};
+ delete $self->{'no_paragraph_commands'}->{$cmd_name};
+ delete $self->{'basic_inline_commands'}->{$cmd_name};
+ delete $self->{'command_index'}->{$cmd_name};
+ # consistent with XS parser, value not actually used anywhere.
+ $self->{'brace_commands'}->{$cmd_name} = 'style_other';
+ # this allows to obtain the same result as the XS parser which checks
+ # dynamically the brace_commands type
+ $self->{'valid_nestings'}->{$cmd_name} = \%in_full_text_commands;
+ # note that a built-in command previously in a hash classifying the
+ # @-command otherwise will remain there, possibly having specific
effects.
+ }
} else {
$self->_line_error(sprintf(__("bad argument to \@%s"), $command),
$source_info);
diff --git a/tp/Texinfo/XS/parsetexi/end_line.c
b/tp/Texinfo/XS/parsetexi/end_line.c
index 235fad9607..151c4be261 100644
--- a/tp/Texinfo/XS/parsetexi/end_line.c
+++ b/tp/Texinfo/XS/parsetexi/end_line.c
@@ -243,6 +243,19 @@ parse_line_command_args (ELEMENT *line_command)
if (*line == ',')
goto definfoenclose_invalid; /* Too many args. */
+ /* check that it is an highlighting command */
+ new_cmd = lookup_builtin_command (new_command);
+ if (new_cmd &&
+ (!(builtin_command_data[new_cmd].flags & CF_brace)
+ || (builtin_command_data[new_cmd].data != BRACE_style_no_code
+ && builtin_command_data[new_cmd].data != BRACE_style_code
+ && builtin_command_data[new_cmd].data != BRACE_style_other)))
+ {
+ line_error ("cannot redefine with @definfoenclose: %s",
+ new_command);
+ goto definfoenclose_add_args;
+ }
+
/* Remember it. */
new_cmd = add_texinfo_command (new_command);
add_infoenclose (new_cmd, start, end);
@@ -254,6 +267,7 @@ parse_line_command_args (ELEMENT *line_command)
user_defined_command_data[new_cmd].data = BRACE_style_other;
user_defined_command_data[new_cmd].args_number = 1;
+ definfoenclose_add_args:
ADD_ARG(new_command); free (new_command);
ADD_ARG(start); free (start);
ADD_ARG(end); free (end);
diff --git a/tp/t/03coverage_braces.t b/tp/t/03coverage_braces.t
index 888bed124d..179d15817a 100644
--- a/tp/t/03coverage_braces.t
+++ b/tp/t/03coverage_braces.t
@@ -286,6 +286,20 @@ Text @w{@ref{Top, cross in w} text}.
@printindex cp
'],
+['definfoenclose_texinfo_commands',
+'@definfoenclose verb,;;,!!
+@definfoenclose TeX,aa,bb
+@definfoenclose strong,(,)
+@definfoenclose quotation,q,e
+
+@verb{*aaa*}.
+
+@TeX{}. @strong{in strong}.
+
+@quotation important
+in quotation
+@end quotation
+'],
);
my @test_invalid = (
diff --git a/tp/t/results/coverage_braces/definfoenclose_texinfo_commands.pl
b/tp/t/results/coverage_braces/definfoenclose_texinfo_commands.pl
new file mode 100644
index 0000000000..55035b97ab
--- /dev/null
+++ b/tp/t/results/coverage_braces/definfoenclose_texinfo_commands.pl
@@ -0,0 +1,424 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors
+ %result_indices %result_sectioning %result_nodes %result_menus
+ %result_floats %result_converted %result_converted_errors
+ %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'definfoenclose_texinfo_commands'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'verb,;;,!!'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'definfoenclose',
+ 'extra' => {
+ 'misc_args' => [
+ 'verb',
+ ';;',
+ '!!'
+ ]
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'line_nr' => 1
+ }
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'TeX,aa,bb'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'definfoenclose',
+ 'extra' => {
+ 'misc_args' => [
+ 'TeX',
+ 'aa',
+ 'bb'
+ ]
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'line_nr' => 2
+ }
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'strong,(,)'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'definfoenclose',
+ 'extra' => {
+ 'misc_args' => [
+ 'strong',
+ '(',
+ ')'
+ ]
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'line_nr' => 3
+ }
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'quotation,q,e'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'definfoenclose',
+ 'extra' => {
+ 'misc_args' => [
+ 'quotation',
+ 'q',
+ 'e'
+ ]
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'line_nr' => 4
+ }
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'aaa',
+ 'type' => 'raw'
+ }
+ ],
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'verb',
+ 'info' => {
+ 'delimiter' => '*'
+ },
+ 'source_info' => {
+ 'line_nr' => 6
+ }
+ },
+ {
+ 'text' => '.
+'
+ }
+ ],
+ 'type' => 'paragraph'
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'TeX',
+ 'source_info' => {
+ 'line_nr' => 8
+ }
+ },
+ {
+ 'text' => '. '
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'in strong'
+ }
+ ],
+ 'type' => 'brace_command_arg'
+ }
+ ],
+ 'cmdname' => 'strong',
+ 'extra' => {
+ 'begin' => '(',
+ 'end' => ')'
+ },
+ 'info' => {
+ 'command_name' => 'strong'
+ },
+ 'source_info' => {
+ 'line_nr' => 8
+ },
+ 'type' => 'definfoenclose_command'
+ },
+ {
+ 'text' => '.
+'
+ }
+ ],
+ 'type' => 'paragraph'
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'important'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'block_line_arg'
+ }
+ ],
+ 'cmdname' => 'quotation',
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'in quotation
+'
+ }
+ ],
+ 'type' => 'paragraph'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'quotation'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'end',
+ 'extra' => {
+ 'text_arg' => 'quotation'
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'line_nr' => 12
+ }
+ }
+ ],
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'line_nr' => 10
+ }
+ }
+ ],
+ 'type' => 'before_node_section'
+ }
+ ],
+ 'type' => 'document_root'
+};
+
+$result_texis{'definfoenclose_texinfo_commands'} = '@definfoenclose verb,;;,!!
+@definfoenclose TeX,aa,bb
+@definfoenclose strong,(,)
+@definfoenclose quotation,q,e
+
+@verb{*aaa*}.
+
+@TeX{}. @strong{in strong}.
+
+@quotation important
+in quotation
+@end quotation
+';
+
+
+$result_texts{'definfoenclose_texinfo_commands'} = '
+aaa.
+
+TeX. in strong.
+
+important
+in quotation
+';
+
+$result_errors{'definfoenclose_texinfo_commands'} = [
+ {
+ 'error_line' => 'warning: @definfoenclose is obsolete
+',
+ 'line_nr' => 1,
+ 'text' => '@definfoenclose is obsolete',
+ 'type' => 'warning'
+ },
+ {
+ 'error_line' => 'cannot redefine with @definfoenclose: verb
+',
+ 'line_nr' => 1,
+ 'text' => 'cannot redefine with @definfoenclose: verb',
+ 'type' => 'error'
+ },
+ {
+ 'error_line' => 'warning: @definfoenclose is obsolete
+',
+ 'line_nr' => 2,
+ 'text' => '@definfoenclose is obsolete',
+ 'type' => 'warning'
+ },
+ {
+ 'error_line' => 'cannot redefine with @definfoenclose: TeX
+',
+ 'line_nr' => 2,
+ 'text' => 'cannot redefine with @definfoenclose: TeX',
+ 'type' => 'error'
+ },
+ {
+ 'error_line' => 'warning: @definfoenclose is obsolete
+',
+ 'line_nr' => 3,
+ 'text' => '@definfoenclose is obsolete',
+ 'type' => 'warning'
+ },
+ {
+ 'error_line' => 'warning: @definfoenclose is obsolete
+',
+ 'line_nr' => 4,
+ 'text' => '@definfoenclose is obsolete',
+ 'type' => 'warning'
+ },
+ {
+ 'error_line' => 'cannot redefine with @definfoenclose: quotation
+',
+ 'line_nr' => 4,
+ 'text' => 'cannot redefine with @definfoenclose: quotation',
+ 'type' => 'error'
+ }
+];
+
+
+$result_floats{'definfoenclose_texinfo_commands'} = {};
+
+
+
+$result_converted{'plaintext'}->{'definfoenclose_texinfo_commands'} = 'aaa.
+
+ TeX. (in strong).
+
+ important: in quotation
+';
+
+
+$result_converted{'html_text'}->{'definfoenclose_texinfo_commands'} = '
+<p><code class="verb">aaa</code>.
+</p>
+<p>TeX. (in strong).
+</p>
+<blockquote class="quotation">
+<p><b class="b">important:</b> in quotation
+</p></blockquote>
+';
+
+
+$result_converted{'latex_text'}->{'definfoenclose_texinfo_commands'} = '
+\\verb*aaa*.
+
+\\TeX{}. \\textbf{in strong}.
+
+\\begin{quote}
+\\textbf{important:} in quotation
+\\end{quote}
+';
+
+1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Only allow highlighting commands to be redefined with @definfoenclose,
Patrice Dumas <=