[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6181] parsetexi gather_previous_item
From: |
Gavin D. Smith |
Subject: |
[6181] parsetexi gather_previous_item |
Date: |
Sat, 07 Mar 2015 19:28:55 +0000 |
Revision: 6181
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6181
Author: gavin
Date: 2015-03-07 19:28:54 +0000 (Sat, 07 Mar 2015)
Log Message:
-----------
parsetexi gather_previous_item
Modified Paths:
--------------
trunk/parsetexi/ChangeLog
trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
trunk/parsetexi/close.c
trunk/parsetexi/handle_commands.c
trunk/parsetexi/multitable.c
trunk/parsetexi/parser.h
trunk/parsetexi/separator.c
Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog 2015-03-06 21:40:09 UTC (rev 6180)
+++ trunk/parsetexi/ChangeLog 2015-03-07 19:28:54 UTC (rev 6181)
@@ -1,3 +1,10 @@
+2015-03-07 Gavin Smith <address@hidden>
+
+ * Parsetexi/lib/Parsetexi.pm (parse_texi_file): Handle warnings
+ as well as error messages.
+ * close.c (close_command_cleanup) <CF_blockitem>: More complete.
+ * multitable.c (gather_previous_item): Implement.
+
2015-03-06 Gavin Smith <address@hidden>
* counter.c: New file.
Modified: trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
===================================================================
--- trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2015-03-06 21:40:09 UTC (rev
6180)
+++ trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2015-03-07 19:28:54 UTC (rev
6181)
@@ -305,7 +305,11 @@
$tree_stream = dump_errors();
eval $tree_stream;
for my $error (@{$ERRORS}) {
- $self->line_error ($error->{'message'}, $error->{'line_nr'});
+ if ($error->{'type'} eq 'error') {
+ $self->line_error ($error->{'message'}, $error->{'line_nr'});
+ } else {
+ $self->line_warn ($error->{'message'}, $error->{'line_nr'});
+ }
}
Modified: trunk/parsetexi/close.c
===================================================================
--- trunk/parsetexi/close.c 2015-03-06 21:40:09 UTC (rev 6180)
+++ trunk/parsetexi/close.c 2015-03-07 19:28:54 UTC (rev 6181)
@@ -43,25 +43,101 @@
container. */
if (command_data(current->cmd).flags & CF_def)
{
- /* "At this point the end command hasn't been added to the command
- contents, so checks cannot be done at this point." */
gather_def_item (current);
}
- /* "item_line" commands */
if (current->cmd == CM_table
|| current->cmd == CM_ftable
|| current->cmd == CM_vtable)
{
- /* "At this point the end command hasn't been added to the command
- contents, so checks cannot be done at this point." */
if (current->contents.number > 0)
- ;//gather_previous_item (current);
+ gather_previous_item (current, 0);
}
// 1570
- if (command_data(current->cmd).flags & CF_blockitem)
+ /* Block commands that contain @item's - e.g. @multitable, @table,
+ @itemize. */
+ if (command_data(current->cmd).flags & CF_blockitem
+ && current->contents.number > 0)
{
+ int have_leading_spaces = 0;
+ ELEMENT *before_item;
+ if (current->contents.number >= 0
+ && current->contents.list[0]->type == ET_empty_line_after_command
+ && current->contents.list[1]->type == ET_before_item)
+ {
+ have_leading_spaces = 1;
+ before_item = current->contents.list[1];
+ }
+ else
+ {
+ before_item = current->contents.list[0];
+ /* TODO: before_item is ELEMENT or ELEMENT * ? */
+ }
+
+ /* Perl code here checks if before_item exists, but it already assumed
+ that it existed by accessing 'type' key on it. */
+
+ // 1585
+ /* Reparent @end from a ET_before_item to the block command */
+ {
+ KEY_PAIR *k = lookup_extra_key (current, "end_command");
+ ELEMENT *e = k ? k->value : 0;
+ if (k && last_contents_child (before_item)
+ && last_contents_child (before_item) == e)
+ {
+ add_to_element_contents (current,
+ pop_element_from_contents (before_item));
+ }
+ }
+
+ /* Now if the ET_before_item is empty, remove it. */
+ if (before_item->contents.number == 0)
+ {
+ destroy_element (remove_from_contents (current,
+ have_leading_spaces ? 1 : 0));
+ }
+ else /* Non-empty ET_before_item */
+ {
+ int empty_before_item = 1, i;
+ /* Check if contents consist soley of @comment's. */
+ for (i = 0; i < before_item->contents.number; i++)
+ {
+ enum command_id c = before_item->contents.list[i]->cmd;
+ if (c != CM_c && c != CM_comment)
+ {
+ empty_before_item = 0;
+ }
+ }
+
+ if (!empty_before_item)
+ {
+ int empty_format = 1;
+ /* Check for an element that could represent an @item in the
+ block. The type of this element will depend on the block
+ command we are in. */
+ for (i = 0; i < current->contents.number; i++)
+ {
+ ELEMENT *e = current->contents.list[i];
+ if (e == before_item)
+ continue;
+ if (e->cmd != CM_NONE
+ && (e->cmd != CM_c && e->cmd != CM_comment
+ && e->cmd != CM_end)
+ || e->type != CM_NONE
+ && e->type != ET_empty_line_after_command)
+ {
+ empty_format = 0;
+ break;
+ }
+ }
+
+ if (empty_format)
+ line_warnf ("@%s has text but no @item",
+ command_name(current->cmd));
+ }
+ }
+
} // 1635
}
Modified: trunk/parsetexi/handle_commands.c
===================================================================
--- trunk/parsetexi/handle_commands.c 2015-03-06 21:40:09 UTC (rev 6180)
+++ trunk/parsetexi/handle_commands.c 2015-03-07 19:28:54 UTC (rev 6181)
@@ -172,7 +172,7 @@
{
ELEMENT *misc, *parent;
- // itemize or enumerate 4443
+ /* @itemize or @enumerate */ // 4443
if ((parent = item_container_parent (current)))
{
if (cmd == CM_item)
@@ -192,24 +192,28 @@
}
else
{
- // error
- abort ();
+ line_errorf ("@%s not meaningful within address@hidden'
block");
}
- //begin_preformatted ();
+ current = begin_preformatted (current);
}
- // *table
+ /* @table, @vtable, @ftable */
else if ((parent = item_line_parent (current)))
{
if (cmd == CM_item || cmd == CM_itemx)
{
debug ("ITEM_LINE");
current = parent;
- // gather_previous_item ();
+ gather_previous_item (current, cmd);
misc = new_element (ET_NONE);
misc->cmd = cmd;
add_to_element_contents (current, misc);
line_arg = 1;
}
+ else
+ {
+ line_errorf ("@%s not meaningful within address@hidden'
block");
+ current = begin_preformatted (current);
+ }
}
/* In a @multitable */
else if ((parent = item_multitable_parent (current))) // 4477
@@ -223,9 +227,11 @@
}
else
{ /* 4480 */
- // check for empty multitable
- /* if
+ /* TODO - need the max_columns value for this
+ if (counter_value (max_columns, parent) == 0)
{
+ line_warnf ("@%s in empty multitable",
+ command_name(cmd));
}
else */ if (cmd == CM_tab)
{ // 4484
@@ -235,8 +241,8 @@
if (row->type == ET_before_item)
line_error ("@tab before @item");
/* TODO 4489
- else if (counter_value (&count_cells, row)
- >= counter_value (&max_columns, parent))
+ else if (counter_value (&count_cells, parent)
+ >= counter_value (&max_columns, parent))
{
line_error ("too many columns in multitable item"
" (max %d)",
Modified: trunk/parsetexi/multitable.c
===================================================================
--- trunk/parsetexi/multitable.c 2015-03-06 21:40:09 UTC (rev 6180)
+++ trunk/parsetexi/multitable.c 2015-03-07 19:28:54 UTC (rev 6181)
@@ -15,6 +15,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "parser.h"
+#include "errors.h"
/* Return the parent if in an item_line command, @*table */
ELEMENT *
@@ -52,3 +53,90 @@
return 0;
}
+
+// 1381
+/* Put the contents of a @table row in a ET_table_entry container, containing
+ a ET_table_term element and a ET_table_item element. The elements of
+ this row currently occur the end of the contents of CURRENT as immediate
+ children.
+
+ NEXT_COMMAND is the command that ends this row, usually CM_item. It is
null
+ at the end of a @table. If NEXT_COMMAND is given as CM_itemx, gather a
+ ET_inter_item container instead. */
+void
+gather_previous_item (ELEMENT *current, enum command_id next_command)
+{
+ ELEMENT *gathered;
+ enum command_id type;
+ int i, contents_count;
+
+ if (last_contents_child(current)
+ && last_contents_child(current)->type == ET_before_item)
+ {
+ if (next_command == CM_itemx)
+ line_warnf ("@itemx should not begin @%s", command_name(current->cmd));
+ return;
+ }
+
+ type = next_command != CM_itemx ? ET_table_item : ET_inter_item;
+ gathered = new_element (type);
+
+ /* Starting from the end, collect everything that is not a ET_item
+ or ET_itemx and put it into the ET_table_item. */
+ contents_count = current->contents.number;
+ for (i = 0; i < contents_count; i++)
+ {
+ ELEMENT *e;
+ if (last_contents_child(current)->cmd == CM_item
+ || last_contents_child(current)->cmd == CM_itemx)
+ break;
+
+ e = pop_element_from_contents (current);
+ insert_into_contents (gathered, e, 0);
+ }
+ /* TODO: A similar algorithm is is in gather_def_item in def.c. If
+ speed is an issue then we could move all the elements at once instead
+ of calling insert_into_contents multiple times. */
+
+ if (type == ET_table_item) // 1423
+ {
+ ELEMENT *table_entry = new_element (ET_table_entry);
+ ELEMENT *table_term = new_element (ET_table_term);
+ add_to_element_contents (table_entry, table_term);
+
+ /* We previously collected elements into a ET_table_item. Now
+ do the same for ET_table_term. */
+ contents_count = current->contents.number;
+ for (i = 0; i < contents_count; i++)
+ {
+ ELEMENT *e;
+ if (last_contents_child(current)->type == ET_before_item
+ || last_contents_child(current)->type == ET_table_entry)
+ break;
+
+ e = pop_element_from_contents (current);
+ insert_into_contents (table_term, e, 0);
+ }
+
+ add_to_element_contents (current, table_entry);
+
+ if (gathered->contents.number > 0)
+ add_to_element_contents (table_entry, gathered);
+ else
+ destroy_element (gathered);
+ }
+ else /* Gathering ET_inter_item between @item and @itemx */ // 1457
+ {
+ /* TODO
+ // Text between @item and @itemx is only allowed in a few cases:
+ // comments, empty lines, or index entries
+ if (check_no_text (gathered))
+ line_error ("@itemx must follow @item");
+ */
+
+ if (gathered->contents.number > 0)
+ add_to_element_contents (current, gathered);
+ else
+ destroy_element (gathered);
+ }
+}
Modified: trunk/parsetexi/parser.h
===================================================================
--- trunk/parsetexi/parser.h 2015-03-06 21:40:09 UTC (rev 6180)
+++ trunk/parsetexi/parser.h 2015-03-07 19:28:54 UTC (rev 6181)
@@ -63,6 +63,7 @@
/* In multitable.c */
ELEMENT *item_line_parent (ELEMENT *current);
ELEMENT *item_multitable_parent (ELEMENT *current);
+void gather_previous_item (ELEMENT *current, enum command_id next_command);
#include "dump_perl.h"
Modified: trunk/parsetexi/separator.c
===================================================================
--- trunk/parsetexi/separator.c 2015-03-06 21:40:09 UTC (rev 6180)
+++ trunk/parsetexi/separator.c 2015-03-07 19:28:54 UTC (rev 6181)
@@ -20,7 +20,7 @@
#include "parser.h"
#include "tree.h"
#include "text.h"
-#include "error.h"
+#include "errors.h"
// 3600
/* Add the contents of CURRENT as an element to the extra value with
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6181] parsetexi gather_previous_item,
Gavin D. Smith <=