[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[8356] separate line commands from other misc commands
From: |
gavinsmith0123 |
Subject: |
[8356] separate line commands from other misc commands |
Date: |
Sat, 20 Oct 2018 12:42:22 -0400 (EDT) |
Revision: 8356
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=8356
Author: gavin
Date: 2018-10-20 12:42:21 -0400 (Sat, 20 Oct 2018)
Log Message:
-----------
separate line commands from other misc commands
Modified Paths:
--------------
trunk/tp/Texinfo/Parser.pm
trunk/tp/t/results/invalid_nestings/recursive_copying.pl
Modified: trunk/tp/Texinfo/Parser.pm
===================================================================
--- trunk/tp/Texinfo/Parser.pm 2018-10-20 16:41:33 UTC (rev 8355)
+++ trunk/tp/Texinfo/Parser.pm 2018-10-20 16:42:21 UTC (rev 8356)
@@ -158,7 +158,7 @@
# input a stack, with last at bottom. Holds the opened files
# or text. Pending macro expansion or text expansion
# is also in that structure.
-# misc_commands the same than %misc_commands in Texinfo::Common,
+# misc_commands the same as %misc_commands in Texinfo::Common,
# but with index entry commands dynamically added
# close_paragraph_commands same than %close_paragraph_commands, but with
# insertcopying removed if INLINE_INSERTCOPYING
@@ -214,6 +214,7 @@
my %no_brace_commands = %Texinfo::Common::no_brace_commands;
my %misc_commands = %Texinfo::Common::misc_commands;
+my %other_commands = %Texinfo::Common::other_commands;
my %brace_commands = %Texinfo::Common::brace_commands;
my %accent_commands = %Texinfo::Common::accent_commands;
my %context_brace_commands = %Texinfo::Common::context_brace_commands;
@@ -4095,8 +4096,154 @@
$current = _end_preformatted($self, $current, $line_nr);
}
- # commands without braces and not block commands, ie no @end
- if (defined($self->{'misc_commands'}->{$command})) {
+ my $line_arg = 0;
+
+ if ($command eq 'item' or $command eq 'itemx') {
+ $line_arg = 1 if _item_line_parent($current);
+ }
+
+ if (!$line_arg and defined($other_commands{$command})) {
+ # noarg skipspace
+ my $arg_spec = $other_commands{$command};
+ my $misc;
+
+ if ($arg_spec eq 'noarg') {
+ my $only_in_headings = 0;
+ if ($in_heading_commands{$command}) {
+ $self->line_error(
+ sprintf(__("address@hidden should only appear in heading or
footing"),
+ $command), $line_nr);
+ $only_in_headings = 1;
+ }
+ $misc = {'cmdname' => $command, 'parent' => $current};
+ push @{$current->{'contents'}}, $misc;
+ $misc->{'extra'}->{'invalid_nesting'} = 1 if ($only_in_headings);
+ _register_global_command($self, $misc, $line_nr);
+ _mark_and_warn_invalid($self, $command, $invalid_parent,
+ $line_nr, $misc);
+ $current = _begin_preformatted($self, $current)
+ if ($close_preformatted_commands{$command});
+ } else {
+ if ($command eq 'item' or $command eq 'itemx'
+ or $command eq 'headitem' or $command eq 'tab') {
+ my $parent;
+ # @itemize or @enumerate
+ if ($parent = _item_container_parent($current)) {
+ if ($command eq 'item') {
+ print STDERR "ITEM_CONTAINER\n" if ($self->{'DEBUG'});
+ $parent->{'items_count'}++;
+ $misc = { 'cmdname' => $command, 'parent' => $parent,
+ 'contents' => [],
+ 'extra' =>
+ {'item_number' => $parent->{'items_count'}} };
+ push @{$parent->{'contents'}}, $misc;
+ $current = $parent->{'contents'}->[-1];
+ } else {
+ $self->line_error(sprintf(__(
+ "address@hidden not meaningful inside
address@hidden' block"),
+ $command, $parent->{'cmdname'}), $line_nr);
+ }
+ $current = _begin_preformatted($self, $current);
+ # @*table
+ } elsif ($parent = _item_line_parent($current)) {
+ $self->line_error(sprintf(__(
+ "address@hidden not meaningful inside address@hidden'
block"),
+ $command, $parent->{'cmdname'}), $line_nr);
+ $current = _begin_preformatted($self, $current);
+ # @multitable
+ } elsif ($parent = _item_multitable_parent($current)) {
+ if ($command eq 'item' or $command eq 'headitem'
+ or $command eq 'tab') {
+ if (!$parent->{'extra'}->{'max_columns'}) {
+ $self->line_warn(
+ sprintf(__("address@hidden in empty multitable"),
+ $command), $line_nr);
+ } elsif ($command eq 'tab') {
+ my $row = $parent->{'contents'}->[-1];
+ die if (!$row->{'type'});
+ if ($row->{'type'} eq 'before_item') {
+ $self->line_error(__("address@hidden before
address@hidden"), $line_nr);
+ } elsif ($row->{'cells_count'} >=
$parent->{'extra'}->{'max_columns'}) {
+ $self->line_error(sprintf(__(
+ "too many columns in multitable item (max %d)"),
+ $parent->{'extra'}->{'max_columns'}), $line_nr);
+ } else {
+ $row->{'cells_count'}++;
+ $misc = { 'cmdname' => $command,
+ 'parent' => $row,
+ 'contents' => [],
+ 'extra' =>
+ {'cell_number' => $row->{'cells_count'}} };
+ push @{$row->{'contents'}}, $misc;
+ $current = $row->{'contents'}->[-1];
+ #$current = $self->_begin_preformatted($current);
+ print STDERR "TAB\n" if ($self->{'DEBUG'});
+ }
+ } else {
+ print STDERR "ROW\n" if ($self->{'DEBUG'});
+ $parent->{'rows_count'}++;
+ my $row = { 'type' => 'row', 'contents' => [],
+ 'cells_count' => 1,
+ 'extra' => {'row_number' =>
$parent->{'rows_count'} },
+ 'parent' => $parent };
+ push @{$parent->{'contents'}}, $row;
+ $misc = { 'cmdname' => $command,
+ 'parent' => $row,
+ 'contents' => [],
+ 'extra' => {'cell_number' => 1}};
+ push @{$row->{'contents'}}, $misc;
+ $current = $row->{'contents'}->[-1];
+ }
+ } else {
+ $self->line_error(sprintf(__(
+ "address@hidden not meaningful inside
address@hidden' block"),
+ $command, $parent->{'cmdname'}), $line_nr);
+ }
+ $current = _begin_preformatted($self, $current);
+ } elsif ($command eq 'tab') {
+ $self->line_error(__(
+ "ignoring address@hidden outside of multitable"),
$line_nr);
+ $current = _begin_preformatted($self, $current);
+ } else {
+ $self->line_error (sprintf(__(
+ "address@hidden outside of table or list"), $command),
$line_nr);
+ $current = _begin_preformatted($self, $current);
+ }
+ $misc->{'line_nr'} = $line_nr if (defined($misc));
+ } else {
+ $misc = { 'cmdname' => $command, 'parent' => $current,
+ 'line_nr' => $line_nr };
+ push @{$current->{'contents'}}, $misc;
+ }
+ $line = _start_empty_line_after_command($line, $current, $misc);
+ if ($command eq 'indent'
+ or $command eq 'noindent') {
+ if ($line !~ /\n/) {
+ my ($new_line, $new_line_nr) =
+ _new_line($self, $line_nr, undef);
+ $line .= $new_line if (defined($new_line));
+ }
+ $line =~ s/^(\s*)//;
+ if ($1) {
+ $current = _merge_text($self, $current, $1);
+ }
+ if ($line ne ''
+ and $current->{'contents'}->[-1]->{'type'} eq
+ 'empty_line_after_command') {
+ $current->{'contents'}->[-1]->{'type'}
+ = 'empty_spaces_after_command';
+ }
+ my $paragraph = _begin_paragraph($self, $current, $line_nr);
+ $current = $paragraph if $paragraph;
+ if ($line eq '') {
+ last;
+ }
+ }
+ _mark_and_warn_invalid($self, $command, $invalid_parent,
+ $line_nr, $misc);
+ }
+ # line commands
+ } elsif ($line_arg or defined($self->{'misc_commands'}->{$command})) {
if ($root_commands{$command} or $command eq 'bye') {
$current = _close_commands($self, $current, $line_nr, undef,
$command);
@@ -4115,13 +4262,14 @@
}
}
- # noarg skipline skipspace text line lineraw /^\d$/
+ # skipline text line lineraw /^\d$/
my $arg_spec = $self->{'misc_commands'}->{$command};
my $misc;
- if ($arg_spec eq 'noarg') {
+ # all the cases using the raw line
+ if ($arg_spec eq 'skipline' or $arg_spec eq 'lineraw'
+ or $arg_spec eq 'special') {
my $ignored = 0;
- my $only_in_headings = 0;
if ($command eq 'insertcopying') {
my $parent = $current;
while ($parent) {
@@ -4134,28 +4282,8 @@
}
$parent = $parent->{'parent'};
}
- } elsif ($in_heading_commands{$command}) {
- $self->line_error(
- sprintf(__("address@hidden should only appear in heading or
footing"),
- $command), $line_nr);
- $only_in_headings = 1;
- }
- if (!$ignored) {
- $misc = {'cmdname' => $command,
- 'parent' => $current};
- push @{$current->{'contents'}}, $misc;
- # also sets invalid_nesting in that case
- $misc->{'extra'}->{'invalid_nesting'} = 1 if ($only_in_headings);
- _register_global_command($self, $misc, $line_nr);
- }
- _mark_and_warn_invalid($self, $command, $invalid_parent,
- $line_nr, $misc);
- $current = _begin_preformatted($self, $current)
- if ($close_preformatted_commands{$command});
+ }
- # all the cases using the raw line
- } elsif ($arg_spec eq 'skipline' or $arg_spec eq 'lineraw'
- or $arg_spec eq 'special') {
# complete the line if there was a user macro expansion
if ($line !~ /\n/) {
my ($new_line, $new_line_nr) = _new_line($self, $line_nr, undef);
@@ -4204,14 +4332,16 @@
'type' => 'spaces_at_end', } ];
push @{$current->{'contents'}}, $misc;
} else {
- push @{$current->{'contents'}}, $misc;
- foreach my $arg (@$args) {
- push @{$misc->{'args'}},
- { 'type' => 'misc_arg', 'text' => $arg,
- 'parent' => $current->{'contents'}->[-1] };
+ if (!$ignored) {
+ push @{$current->{'contents'}}, $misc;
+ foreach my $arg (@$args) {
+ push @{$misc->{'args'}},
+ { 'type' => 'misc_arg', 'text' => $arg,
+ 'parent' => $current->{'contents'}->[-1] };
+ }
+ $misc->{'extra'}->{'misc_args'} = $args
+ if (scalar(@$args) and $arg_spec ne 'skipline');
}
- $misc->{'extra'}->{'misc_args'} = $args
- if (scalar(@$args) and $arg_spec ne 'skipline');
}
if ($command eq 'raisesections') {
$self->{'sections_level'}++;
@@ -4235,105 +4365,14 @@
if ($close_preformatted_commands{$command});
last;
} else {
- # $arg_spec is text, line, skipspace or a number
- my $line_arg = 0;
- $line_arg = 1 if ($arg_spec ne 'skipspace');
- if ($command eq 'item' or $command eq 'itemx'
- or $command eq 'headitem' or $command eq 'tab') {
- my $parent;
- # itemize or enumerate
- if ($parent = _item_container_parent($current)) {
- if ($command eq 'item') {
- print STDERR "ITEM_CONTAINER\n" if ($self->{'DEBUG'});
- $parent->{'items_count'}++;
- $misc = { 'cmdname' => $command, 'parent' => $parent,
- 'contents' => [],
- 'extra' =>
- {'item_number' => $parent->{'items_count'}} };
- push @{$parent->{'contents'}}, $misc;
- $current = $parent->{'contents'}->[-1];
- } else {
- $self->line_error(sprintf(__(
- "address@hidden not meaningful inside
address@hidden' block"),
- $command, $parent->{'cmdname'}), $line_nr);
- }
- $current = _begin_preformatted($self, $current);
- # *table
- } elsif ($parent = _item_line_parent($current)) {
- if ($command eq 'item' or $command eq 'itemx') {
- print STDERR "ITEM_LINE\n" if ($self->{'DEBUG'});
- $current = $parent;
- _gather_previous_item($self, $current, $command, $line_nr);
- $misc = { 'cmdname' => $command, 'parent' => $current };
- push @{$current->{'contents'}}, $misc;
- # since in the %misc_commands hash the entry for those
- # commands is 'skipspace' we set $line_arg here.
- $line_arg = 1;
- } else {
- $self->line_error(sprintf(__(
- "address@hidden not meaningful inside
address@hidden' block"),
- $command, $parent->{'cmdname'}), $line_nr);
- $current = _begin_preformatted($self, $current);
- }
- # multitable
- } elsif ($parent = _item_multitable_parent($current)) {
- if ($command eq 'item' or $command eq 'headitem'
- or $command eq 'tab') {
- if (!$parent->{'extra'}->{'max_columns'}) {
- $self->line_warn(
- sprintf(__("address@hidden in empty multitable"),
- $command), $line_nr);
- } elsif ($command eq 'tab') {
- my $row = $parent->{'contents'}->[-1];
- die if (!$row->{'type'});
- if ($row->{'type'} eq 'before_item') {
- $self->line_error(__("address@hidden before
address@hidden"), $line_nr);
- } elsif ($row->{'cells_count'} >=
$parent->{'extra'}->{'max_columns'}) {
- $self->line_error(sprintf(__(
- "too many columns in multitable item (max %d)"),
- $parent->{'extra'}->{'max_columns'}), $line_nr);
- } else {
- $row->{'cells_count'}++;
- $misc = { 'cmdname' => $command,
- 'parent' => $row,
- 'contents' => [],
- 'extra' =>
- {'cell_number' => $row->{'cells_count'}} };
- push @{$row->{'contents'}}, $misc;
- $current = $row->{'contents'}->[-1];
- #$current = $self->_begin_preformatted($current);
- print STDERR "TAB\n" if ($self->{'DEBUG'});
- }
- } else {
- print STDERR "ROW\n" if ($self->{'DEBUG'});
- $parent->{'rows_count'}++;
- my $row = { 'type' => 'row', 'contents' => [],
- 'cells_count' => 1,
- 'extra' => {'row_number' =>
$parent->{'rows_count'} },
- 'parent' => $parent };
- push @{$parent->{'contents'}}, $row;
- $misc = { 'cmdname' => $command,
- 'parent' => $row,
- 'contents' => [],
- 'extra' => {'cell_number' => 1}};
- push @{$row->{'contents'}}, $misc;
- $current = $row->{'contents'}->[-1];
- }
- } else {
- $self->line_error(sprintf(__(
- "address@hidden not meaningful inside
address@hidden' block"),
- $command, $parent->{'cmdname'}), $line_nr);
- }
- $current = _begin_preformatted($self, $current);
- } elsif ($command eq 'tab') {
- $self->line_error(__(
- "ignoring address@hidden outside of multitable"),
$line_nr);
- $current = _begin_preformatted($self, $current);
- } else {
- $self->line_error (sprintf(__(
- "address@hidden outside of table or list"), $command),
$line_nr);
- $current = _begin_preformatted($self, $current);
- }
+ # $arg_spec is text, line or a number
+ # @item or @itemx in @table
+ if ($command eq 'item' or $command eq 'itemx') {
+ print STDERR "ITEM_LINE\n" if ($self->{'DEBUG'});
+ $current = _item_line_parent($current);
+ _gather_previous_item($self, $current, $command, $line_nr);
+ $misc = { 'cmdname' => $command, 'parent' => $current };
+ push @{$current->{'contents'}}, $misc;
$misc->{'line_nr'} = $line_nr if (defined($misc));
} else {
$misc = { 'cmdname' => $command, 'parent' => $current,
@@ -4378,7 +4417,7 @@
}
# a container for what is on the @-command line, considered to
# be the @-command argument
- if ($line_arg) {
+ if (1) {
$current = $current->{'contents'}->[-1];
$current->{'args'} = [{ 'type' => 'misc_line_arg',
'contents' => [],
@@ -4424,29 +4463,6 @@
unless ($def_commands{$command});
}
$line = _start_empty_line_after_command($line, $current, $misc);
- if ($command eq 'indent'
- or $command eq 'noindent') {
- if ($line !~ /\n/) {
- my ($new_line, $new_line_nr) =
- _new_line($self, $line_nr, undef);
- $line .= $new_line if (defined($new_line));
- }
- $line =~ s/^(\s*)//;
- if ($1) {
- $current = _merge_text($self, $current, $1);
- }
- if ($line ne ''
- and $current->{'contents'}->[-1]->{'type'} eq
- 'empty_line_after_command') {
- $current->{'contents'}->[-1]->{'type'}
- = 'empty_spaces_after_command';
- }
- my $paragraph = _begin_paragraph($self, $current, $line_nr);
- $current = $paragraph if $paragraph;
- if ($line eq '') {
- last;
- }
- }
}
_mark_and_warn_invalid($self, $command, $invalid_parent,
$line_nr, $misc);
Modified: trunk/tp/t/results/invalid_nestings/recursive_copying.pl
===================================================================
--- trunk/tp/t/results/invalid_nestings/recursive_copying.pl 2018-10-20
16:41:33 UTC (rev 8355)
+++ trunk/tp/t/results/invalid_nestings/recursive_copying.pl 2018-10-20
16:42:21 UTC (rev 8356)
@@ -45,23 +45,6 @@
{
'args' => [
{
- 'parent' => {},
- 'text' => '
-',
- 'type' => 'misc_arg'
- }
- ],
- 'cmdname' => 'insertcopying',
- 'line_nr' => {
- 'file_name' => '',
- 'line_nr' => 5,
- 'macro' => ''
- },
- 'parent' => {}
- },
- {
- 'args' => [
- {
'contents' => [
{
'parent' => {},
@@ -132,12 +115,10 @@
$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[2]{'contents'}[0]{'parent'}
= $result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[2];
$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[2]{'parent'} =
$result_trees{'recursive_copying'}{'contents'}[0];
$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[3]{'parent'} =
$result_trees{'recursive_copying'}{'contents'}[0];
+$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[4]{'args'}[0]{'contents'}[0]{'parent'}
= $result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[4]{'args'}[0];
$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[4]{'args'}[0]{'parent'}
= $result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[4];
$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[4]{'parent'} =
$result_trees{'recursive_copying'}{'contents'}[0];
-$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[5]{'args'}[0]{'contents'}[0]{'parent'}
= $result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[5]{'args'}[0];
-$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[5]{'args'}[0]{'parent'}
= $result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[5];
-$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[5]{'parent'} =
$result_trees{'recursive_copying'}{'contents'}[0];
-$result_trees{'recursive_copying'}{'contents'}[0]{'extra'}{'end_command'} =
$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[5];
+$result_trees{'recursive_copying'}{'contents'}[0]{'extra'}{'end_command'} =
$result_trees{'recursive_copying'}{'contents'}[0]{'contents'}[4];
$result_trees{'recursive_copying'}{'contents'}[0]{'parent'} =
$result_trees{'recursive_copying'};
$result_trees{'recursive_copying'}{'contents'}[1]{'parent'} =
$result_trees{'recursive_copying'};
$result_trees{'recursive_copying'}{'contents'}[2]{'args'}[0]{'parent'} =
$result_trees{'recursive_copying'}{'contents'}[2];
@@ -147,7 +128,6 @@
In copying.
address@hidden
@end copying
@insertcopying
@@ -157,7 +137,17 @@
$result_texts{'recursive_copying'} = '
';
-$result_errors{'recursive_copying'} = [];
+$result_errors{'recursive_copying'} = [
+ {
+ 'error_line' => ':5: @insertcopying not allowed inside address@hidden'
block
+',
+ 'file_name' => '',
+ 'line_nr' => 5,
+ 'macro' => '',
+ 'text' => '@insertcopying not allowed inside address@hidden' block',
+ 'type' => 'error'
+ }
+];
1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [8356] separate line commands from other misc commands,
gavinsmith0123 <=