[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[8417] split out _check_valid_nesting
From: |
gavinsmith0123 |
Subject: |
[8417] split out _check_valid_nesting |
Date: |
Fri, 26 Oct 2018 17:50:29 -0400 (EDT) |
Revision: 8417
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8417
Author: gavin
Date: 2018-10-26 17:50:29 -0400 (Fri, 26 Oct 2018)
Log Message:
-----------
split out _check_valid_nesting
Modified Paths:
--------------
trunk/ChangeLog
trunk/tp/Texinfo/Parser.pm
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2018-10-26 20:59:05 UTC (rev 8416)
+++ trunk/ChangeLog 2018-10-26 21:50:29 UTC (rev 8417)
@@ -1,5 +1,13 @@
2018-10-26 Gavin Smith <address@hidden>
+ * tp/Texinfo/Parser.pm (_check_valid_nesting): New sub, split
+ out from _parse_texi.
+ (_parser_texi): Call it.
+ (%in_full_line_commands): Remove useless variable, as the same
+ as %in_full_text_commands.
+
+2018-10-26 Gavin Smith <address@hidden>
+
* tp/Texinfo/Parser.pm (%in_full_text_commands): Do not
allow @indent, @noindent.
(%in_full_line_commands): No exception for @indent, @noindent.
Modified: trunk/tp/Texinfo/Parser.pm
===================================================================
--- trunk/tp/Texinfo/Parser.pm 2018-10-26 20:59:05 UTC (rev 8416)
+++ trunk/tp/Texinfo/Parser.pm 2018-10-26 21:50:29 UTC (rev 8417)
@@ -386,12 +386,9 @@
if ($block_commands{$block_command} eq 'conditional');
}
-# commands that may happen on lines where everything is
-# permitted
-my %in_full_line_commands = %in_full_text_commands;
-# commands that may happen on sectioning commands
-my %in_full_line_commands_no_refs = %in_full_line_commands;
+# commands that may appear inside sectioning commands
+my %in_full_line_commands_no_refs = %in_full_text_commands;
foreach my $not_in_full_line_commands_no_refs ('titlefont',
'anchor', 'footnote', 'verb') {
delete $in_full_line_commands_no_refs{$not_in_full_line_commands_no_refs};
@@ -448,7 +445,7 @@
}
# commands that accept almost the same as in full text, except
-# what do not make sense on a line.
+# what does not make sense on a line.
my %full_line_commands;
$full_line_commands{'center'} = 1;
$full_line_commands{'exdent'} = 1;
@@ -455,29 +452,28 @@
$full_line_commands{'item'} = 1;
$full_line_commands{'itemx'} = 1;
-# Fill the valid nestings hash. All commands not in that hash
-# are considered to accept anything within. There are additional
-# context tests, to make sure, for instance that we are testing
-# @-commands on the block, misc or node @-command line and not
+# Fill the valid nestings hash. The keys are the containing commands and
+# the values arrays of commands that are allowed to occur inside those
+# commands. All commands not in this hash are considered to accept anything.
+# There are additional context tests, to make sure, for instance that we are
+# testing @-commands on the block, line or node @-command line and not
# in the content.
-# index entry commands are dynamically set as in_index_commands
+# Index entry commands are dynamically set as %in_index_commands
my %default_valid_nestings;
foreach my $command (keys(%accent_commands)) {
$default_valid_nestings{$command} = \%in_accent_commands;
}
-foreach my $command (keys(%full_text_commands)) {
- $default_valid_nestings{$command} = \%in_full_text_commands;
-}
foreach my $command (keys(%simple_text_commands)) {
$default_valid_nestings{$command} = \%in_simple_text_commands;
}
-foreach my $command (keys(%full_line_commands)) {
- $default_valid_nestings{$command} = \%in_full_line_commands;
+foreach my $command (keys(%full_text_commands), keys(%full_line_commands)) {
+ $default_valid_nestings{$command} = \%in_full_text_commands;
}
foreach my $command (keys(%full_line_commands_no_refs)) {
$default_valid_nestings{$command} = \%in_full_line_commands_no_refs;
}
+
# Only for block commands with line arguments
foreach my $command (keys(%block_commands)) {
if ($block_commands{$command} and $block_commands{$command} ne 'raw'
@@ -494,8 +490,8 @@
$preformatted_contexts{$preformatted_context} = 1;
}
-# contexts on the context_stack stack where empty line don't trigger
-# paragraph
+# contexts on the context_stack stack where empty line doesn't trigger
+# a paragraph
my %no_paragraph_contexts;
foreach my $no_paragraph_context ('math', 'menu', @preformatted_contexts,
'def', 'inlineraw') {
@@ -3434,6 +3430,56 @@
$separator_match, $misc_text);
}
+# Check whether $COMMAND can appear within $CURRENT->{'parent'}.
+sub _check_valid_nesting {
+ my ($self, $current, $command, $line_nr) = @_;
+
+ my $invalid_parent;
+ # error messages for forbidden constructs, like @node in @r,
+ # block command on line command, @xref in @anchor or node...
+ if ($current->{'parent'}) {
+ if ($current->{'parent'}->{'cmdname'}) {
+ if
(defined($self->{'valid_nestings'}->{$current->{'parent'}->{'cmdname'}})
+ and
!$self->{'valid_nestings'}->{$current->{'parent'}->{'cmdname'}}->{$command}
+ # we make sure that we are on a root @-command line and
+ # not in contents
+ and (!$root_commands{$current->{'parent'}->{'cmdname'}}
+ or ($current->{'type'}
+ and $current->{'type'} eq 'line_arg'))
+ # we make sure that we are on a block @-command line and
+ # not in contents
+ and (!($block_commands{$current->{'parent'}->{'cmdname'}})
+ or ($current->{'type'}
+ and $current->{'type'} eq 'block_line_arg'))
+ # we make sure that we are on an @item/@itemx line and
+ # not in an @enumerate, @multitable or @itemize @item.
+ and (($current->{'parent'}->{'cmdname'} ne 'itemx'
+ and $current->{'parent'}->{'cmdname'} ne 'item')
+ or ($current->{'type'}
+ and $current->{'type'} eq 'line_arg'))) {
+ $invalid_parent = $current->{'parent'}->{'cmdname'};
+ }
+ } elsif ($self->{'context_stack'}->[-1] eq 'def'
+ # FIXME instead of hardcoding in_full_line_commands_no_refs
+ # it would be better to use the parent command valid_nesting.
+ and !$in_full_line_commands_no_refs{$command}) {
+ my $def_block = $current;
+ while ($def_block->{'parent'} and (!$def_block->{'parent'}->{'type'}
+ or $def_block->{'parent'}->{'type'} ne 'def_line'))
{
+ $def_block = $def_block->{'parent'};
+ }
+
+ $invalid_parent = $def_block->{'parent'}->{'parent'}->{'cmdname'};
+ }
+ }
+
+ if (defined($invalid_parent)) {
+ $self->line_warn(sprintf(__("address@hidden should not appear in
address@hidden"),
+ $command, $invalid_parent), $line_nr);
+ }
+}
+
+
# the main subroutine
sub _parse_texi($;$)
{
@@ -4036,50 +4082,8 @@
$command), $line_nr);
}
- my $invalid_parent;
- # error messages for forbidden constructs, like @node in @r,
- # block command on line command, @xref in @anchor or node...
- if ($current->{'parent'}) {
- if ($current->{'parent'}->{'cmdname'}) {
- if
(defined($self->{'valid_nestings'}->{$current->{'parent'}->{'cmdname'}})
- and
!$self->{'valid_nestings'}->{$current->{'parent'}->{'cmdname'}}->{$command}
- # we make sure that we are on a root @-command line and
- # not in contents
- and (!$root_commands{$current->{'parent'}->{'cmdname'}}
- or ($current->{'type'}
- and $current->{'type'} eq 'line_arg'))
- # we make sure that we are on a block @-command line and
- # not in contents
- and (!($block_commands{$current->{'parent'}->{'cmdname'}})
- or ($current->{'type'}
- and $current->{'type'} eq 'block_line_arg'))
- # we make sure that we are on an @item/@itemx line and
- # not in an @enumerate, @multitable or @itemize @item.
- and (($current->{'parent'}->{'cmdname'} ne 'itemx'
- and $current->{'parent'}->{'cmdname'} ne 'item')
- or ($current->{'type'}
- and $current->{'type'} eq 'line_arg'))) {
- $invalid_parent = $current->{'parent'}->{'cmdname'};
- }
- } elsif ($self->{'context_stack'}->[-1] eq 'def'
- # FIXME instead of hardcoding in_full_line_commands_no_refs
- # it would be better to use the parent command valid_nesting.
- and !$in_full_line_commands_no_refs{$command}) {
- my $def_block = $current;
- while ($def_block->{'parent'} and
(!$def_block->{'parent'}->{'type'}
- or $def_block->{'parent'}->{'type'} ne
'def_line')) {
- $def_block = $def_block->{'parent'};
- }
+ _check_valid_nesting ($self, $current, $command, $line_nr);
- $invalid_parent = $def_block->{'parent'}->{'parent'}->{'cmdname'};
- }
- }
-
- if (defined($invalid_parent)) {
- $self->line_warn(sprintf(__("address@hidden should not appear in
address@hidden"),
- $command, $invalid_parent), $line_nr);
- }
-
last if ($def_line_continuation);
unless ($self->{'no_paragraph_commands'}->{$command}) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [8417] split out _check_valid_nesting,
gavinsmith0123 <=