[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: |
Sun, 29 Jan 2023 18:57:32 +0000 |
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.
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 6f16e685ec..f18a1d3be0 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -626,7 +626,6 @@ foreach my $no_paragraph_context ('math', 'preformatted',
'rawpreformatted',
my %nesting_context_init = (
'footnote' => 0,
'caption' => 0,
- 'xref' => 0
);
# Interface and internal functions for input management
@@ -657,6 +656,7 @@ sub parser(;$$)
# other initializations
$parser->{'definfoenclose'} = {};
$parser->{'nesting_context'} = {%nesting_context_init};
+ $parser->{'nesting_context'}->{'basic_inline_stack'} = [];
# handle user provided state.
@@ -4327,11 +4327,10 @@ sub _check_valid_nesting_context
$self->_line_warn(sprintf(
__("\@%s should not appear anywhere inside caption"),
$command), $source_info);
- } elsif ($Texinfo::Commands::ref_commands{$command}
- and $self->{'nesting_context'}->{'xref'}) {
- $self->_line_warn(sprintf(
- __("\@%s should not appear anywhere inside cross-reference"),
- $command), $source_info);
+ } elsif (@{$self->{'nesting_context'}->{'basic_inline_stack'}} > 0
+ and !$in_basic_inline_commands{$command}) {
+ $invalid_context
+ = $self->{'nesting_context'}->{'basic_inline_stack'}->[-1];
}
$self->_line_warn(sprintf(
__("\@%s should not appear anywhere inside \@%s"),
@@ -5774,7 +5773,8 @@ sub _process_remaining_on_line($$$$)
}
$self->_push_context('ct_inlineraw', $command)
if ($command eq 'inlineraw');
- $self->{'nesting_context'}->{'xref'} += 1
+ push @{$self->{'nesting_context'}->{'basic_inline_stack'}},
+ $command
if ($Texinfo::Commands::ref_commands{$command});
}
print STDERR "OPENED \@$current->{'parent'}->{'cmdname'}, remaining: "
@@ -5874,7 +5874,7 @@ sub _process_remaining_on_line($$$$)
}
} elsif ($ref_commands{$current->{'parent'}->{'cmdname'}}) {
my $ref = $current->{'parent'};
- $self->{'nesting_context'}->{'xref'} -= 1;
+ pop @{$self->{'nesting_context'}->{'basic_inline_stack'}};
if (@{$ref->{'args'}}) {
my @args;
for $a (@{$ref->{'args'}}) {
- Re: Texinfo command nesting and syntax checking: nested @ref, (continued)
- Re: Texinfo command nesting and syntax checking: nested @ref, Patrice Dumas, 2023/01/18
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/18
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/18
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/18
- Re: Texinfo command nesting and syntax checking: nested @ref, Patrice Dumas, 2023/01/18
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/21
- Re: Texinfo command nesting and syntax checking: nested @ref, Patrice Dumas, 2023/01/21
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/22
- Re: Texinfo command nesting and syntax checking: nested @ref, Patrice Dumas, 2023/01/24
- Re: Texinfo command nesting and syntax checking: nested @ref,
Gavin Smith <=
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/30
- Re: Texinfo command nesting and syntax checking: nested @ref, Patrice Dumas, 2023/01/30
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/23
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/24
- Re: Texinfo command nesting and syntax checking: nested @ref, Gavin Smith, 2023/01/25
Name of "simple text", Gavin Smith, 2023/01/25