bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Texinfo command nesting and syntax checking: nested @ref


From: Gavin Smith
Subject: Re: Texinfo command nesting and syntax checking: nested @ref
Date: Fri, 3 Feb 2023 20:19:16 +0000

On Sun, Jan 29, 2023 at 06:57:33PM +0000, Gavin Smith wrote:
> On Tue, Jan 24, 2023 at 07:48:29AM +0100, Patrice Dumas wrote:
> 
> > > However, this appears to be also an issue for all of the commands
> > > that are marked "contain_simple_text" in command_data.txt.  Would
> > > it make sense to replace the nesting_context.xref counter with
> > > a nesting_context.simple_text counter and use it for all of the
> > > contain_simple_text commands?
> > 
> > I think so.  The implementation I had in mind replaced
> > check_valid_nesting by a check on the whole command stack.  Replacing
> > check_valid_nesting by a forwarding of the nesting context is equally good.
> > 
> > > Perhaps we should also keep a stack of which commands incremented this
> > > counter so we can report the invalid nesting in an error message?
> > 
> > It is a necessity, in my opinion.
> 
> I've started work on this in the patch below.
> 
> When I have time, I will make the corresponding change to the XS code.
> Then it should be straightforward to extend this to all commands
> that should only contain basic inline content.

I've done this latter point.  The next step will be to eliminate
the warnings for immediate nestings.  For example,

  Text @w{@ref{Top, cross in w} text}.

generates duplicate warnings

  test.texi:5: warning: @ref should not appear in @w
  test.texi:5: warning: @ref should not appear anywhere inside @w

with the second warning being the newer one.

The change will probably look like the patch at the bottom of this
mail, but I have to investigate some test suite result changes first.

Some of the other categories could be checked the same way with stacks
or counters.

%contain_basic_inline_with_refs_commands 

This contains sectioning and heading commands, so that

  @section Changes in @ref{SubModule}

is allowed.  I found this mail in the archives with the rationale
for allowing such usage:

https://lists.gnu.org/archive/html/texinfo-devel/2012-03/msg00000.html

It seems questionable to me, but it is allowed in the corresponding
HTML and DocBook output.

This could be implemented by having a separate stack for commands that
forbid cross-reference commands.  It would of course be much simpler
to eliminate this separate class of commands and forbid @ref etc.
inside @section and other commands.  Could we consider this again?

The %contain_full_text_commands and %contain_full_line_commands
categories could be combined as they defined to contain the same
commands as each other.



diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 9ae903dc12..326c6b3175 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -471,8 +471,7 @@ my %contain_basic_inline_with_refs_commands = 
(%sectioning_heading_commands,
 # commands that accept full text, but no block or top-level commands
 my %contain_full_text_commands;
 foreach my $brace_command (keys (%brace_commands)) {
-  next if (exists($contain_basic_inline_commands{$brace_command})
-           or exists($contain_plain_text_commands{$brace_command}));
+  next if (exists($contain_plain_text_commands{$brace_command}));
   if ($brace_commands{$brace_command} eq 'style_code'
       or $brace_commands{$brace_command} eq 'style_other'
       or $brace_commands{$brace_command} eq 'style_no_code') {
@@ -500,9 +499,14 @@ my %default_valid_nestings;
 foreach my $command (keys(%contain_plain_text_commands)) {
   $default_valid_nestings{$command} = \%in_plain_text_commands;
 }
-foreach my $command (keys(%contain_basic_inline_commands)) {
-  $default_valid_nestings{$command} = \%in_basic_inline_commands;
-}
+
+# These commands are now checked for basic inline content using
+# the stack of commands in 'nesting_context'.
+#
+# foreach my $command (keys(%contain_basic_inline_commands)) {
+#   $default_valid_nestings{$command} = \%in_basic_inline_commands;
+# }
+
 foreach my $command (keys(%contain_full_text_commands),
                      keys(%contain_full_line_commands)) {
   $default_valid_nestings{$command} = \%in_full_text_commands;









reply via email to

[Prev in Thread] Current Thread [Next in Thread]