[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6121] parsetexi register_command_arg
From: |
Gavin D. Smith |
Subject: |
[6121] parsetexi register_command_arg |
Date: |
Thu, 12 Feb 2015 22:35:57 +0000 |
Revision: 6121
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6121
Author: gavin
Date: 2015-02-12 22:35:56 +0000 (Thu, 12 Feb 2015)
Log Message:
-----------
parsetexi register_command_arg
Modified Paths:
--------------
trunk/parsetexi/ChangeLog
trunk/parsetexi/dump_perl.c
trunk/parsetexi/end_line.c
trunk/parsetexi/extra.c
trunk/parsetexi/makeinfo-debug.txt
trunk/parsetexi/parser.c
trunk/parsetexi/parser.h
trunk/parsetexi/separator.c
trunk/parsetexi/tree.c
trunk/parsetexi/tree.h
trunk/parsetexi/tree_types.h
Added Paths:
-----------
trunk/parsetexi/test-files/email.texi
Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/ChangeLog 2015-02-12 22:35:56 UTC (rev 6121)
@@ -1,5 +1,12 @@
2015-02-12 Gavin Smith <address@hidden>
+ * separator.c (register_command_arg): New function.
+ (handle_close_brace, handle_comma) <brace commands with positive
+ number of args>: Call it.
+ * extra.c (add_extra_key_contents_array): New function.
+
+2015-02-12 Gavin Smith <address@hidden>
+
* command_data.txt <brace commands>: Add arg types for all
commands (some of these could change).
Modified: trunk/parsetexi/dump_perl.c
===================================================================
--- trunk/parsetexi/dump_perl.c 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/dump_perl.c 2015-02-12 22:35:56 UTC (rev 6121)
@@ -69,13 +69,23 @@
dump_args (ELEMENT *e, TEXT *text)
{
int i;
+ int not_in_tree = 0;
+
+ /* Don't set routing information if not dumping from a route
+ directly from the root, that is via an extra value. */
+ if (e->parent_type == route_not_in_tree
+ || (e->parent_type == route_uninitialized && e->parent))
+ not_in_tree = 1;
text_append_n (text, "[\n", 2);
indent += 2;
for (i = 0; i < e->args.number; i++)
{
- e->args.list[i]->parent_type = route_args;
- e->args.list[i]->index_in_parent = i;
+ if (!not_in_tree)
+ {
+ e->args.list[i]->parent_type = route_args;
+ e->args.list[i]->index_in_parent = i;
+ }
dump_indent (text);
dump_element (e->args.list[i], text);
@@ -91,13 +101,24 @@
dump_contents (ELEMENT *e, TEXT *text)
{
int i;
+ int not_in_tree = 0;
+
+ /* Don't set routing information if not dumping from a route
+ directly from the root, that is via an extra value. */
+ if (e->parent_type == route_not_in_tree
+ || (e->parent_type == route_uninitialized && e->parent))
+ not_in_tree = 1;
+
text_append_n (text, "[\n", 2);
indent += 2;
for (i = 0; i < e->contents.number; i++)
{
- e->contents.list[i]->parent_type = route_contents;
- e->contents.list[i]->index_in_parent = i;
+ if (!not_in_tree)
+ {
+ e->contents.list[i]->parent_type = route_contents;
+ e->contents.list[i]->index_in_parent = i;
+ }
dump_indent (text);
dump_element (e->contents.list[i], text);
@@ -289,6 +310,7 @@
{
switch (e->extra[i].type)
{
+ int j;
case extra_element:
dump_element (e->extra[i].value, text);
break;
@@ -298,6 +320,22 @@
text_append (text, "' => ");
dump_contents (e->extra[i].value, text);
break;
+ case extra_element_contents_array:
+ /* Like extra_element_contents, but this time output an array
+ of arrays (instead of an array). */
+ text_append_n (text, "'", 1);
+ text_append (text, e->extra[i].key);
+ text_append (text, "' => [\n");
+ indent += 2;
+ for (j = 0; j < e->extra[i].value->contents.number; j++)
+ {
+ dump_indent (text);
+ dump_contents (e->extra[i].value->contents.list[j],
+ text);
+ }
+ indent -= 2;
+ text_append (text, "],");
+ break;
default:
abort ();
}
Modified: trunk/parsetexi/end_line.c
===================================================================
--- trunk/parsetexi/end_line.c 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/end_line.c 2015-02-12 22:35:56 UTC (rev 6121)
@@ -27,37 +27,6 @@
#include "indices.h"
#include "errors.h"
-// 5467, also in Common.pm 1334
-// TODO: Check the behaviour here is the same
-/* Return a new element whose contents are the same as those of ORIGINAL,
- but with some elements representing empty spaces removed. Elements like
- these are used to represent some of the "content" extra keys. */
-ELEMENT *
-trim_spaces_comment_from_content (ELEMENT *original)
-{
- ELEMENT *trimmed;
- int i;
-
- trimmed = new_element (ET_NONE);
- trimmed->parent_type = route_not_in_tree;
- for (i = 0; i < original->contents.number; i++)
- {
- if (original->contents.list[i]->type
- != ET_empty_spaces_after_command
- && original->contents.list[i]->type != ET_spaces_at_end)
- {
- /* FIXME: Is this safe to serialize? */
- /* For example, if there are extra keys in the elements under each
- argument? They may not be set in a copy.
- Hopefully there aren't many extra keys set on commands in
- node names. */
- add_to_element_contents (trimmed, original->contents.list[i]);
- }
- }
-
- return trimmed;
-}
-
static int
is_decimal_number (char *string)
{
Modified: trunk/parsetexi/extra.c
===================================================================
--- trunk/parsetexi/extra.c 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/extra.c 2015-02-12 22:35:56 UTC (rev 6121)
@@ -51,6 +51,13 @@
e->extra[e->extra_number - 1].type = extra_element_contents;
}
+void
+add_extra_key_contents_array (ELEMENT *e, char *key, ELEMENT *value)
+{
+ add_extra_key (e, key, value);
+ e->extra[e->extra_number - 1].type = extra_element_contents_array;
+}
+
/* Add an extra key that is a reference to the text field of another
element. */
void
Modified: trunk/parsetexi/makeinfo-debug.txt
===================================================================
--- trunk/parsetexi/makeinfo-debug.txt 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/makeinfo-debug.txt 2015-02-12 22:35:56 UTC (rev 6121)
@@ -3,6 +3,7 @@
$makeinfo -c DUMP_TREE=1 multitparseable.texi 2>&1 |less
makeinfo -c TEXINFO_OUTPUT_FORMAT=debugtree mltitble.texi
+----- often more readable than DUMP_TREE, but no "extra"
makeinfo -c DEBUG=1 -c TEXINFO_OUTPUT_FORMAT=parse mltitble.texi
Modified: trunk/parsetexi/parser.c
===================================================================
--- trunk/parsetexi/parser.c 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/parser.c 2015-02-12 22:35:56 UTC (rev 6121)
@@ -380,10 +380,15 @@
}
/* 2149 */
-/* Split any trailing whitespace on the last element in a line into its
- own element, ET_spaces_at_end by default. This helps with line
- argument parsing as there will be no leading or trailing spaces.
+/* Split any trailing whitespace on the last contents child of CURRENT into
+ own element, ET_spaces_at_end by default.
+
+ This is used for the argument to a line command, and for the arguments to a
+ brace command taking a given number of arguments.
+ This helps with argument parsing as there will be no leading or trailing
+ spaces.
+
Also, "to help expansion disregard unuseful spaces". Could that mean
macro expansion? */
void
@@ -458,6 +463,39 @@
}
}
+// 5467, also in Common.pm 1334
+// TODO: Check the behaviour here is the same
+/* Return a new element whose contents are the same as those of ORIGINAL,
+ but with some elements representing empty spaces removed. Elements like
+ these are used to represent some of the "content" extra keys. */
+ELEMENT *
+trim_spaces_comment_from_content (ELEMENT *original)
+{
+ ELEMENT *trimmed;
+ int i;
+
+ trimmed = new_element (ET_NONE);
+ trimmed->parent_type = route_not_in_tree;
+ for (i = 0; i < original->contents.number; i++)
+ {
+ if (original->contents.list[i]->type != ET_empty_spaces_after_command
+ && original->contents.list[i]->type != ET_spaces_at_end
+ && original->contents.list[i]->type != ET_empty_spaces_before_argument)
+ {
+ /* FIXME: Is this safe to serialize? */
+ /* For example, if there are extra keys in the elements under each
+ argument? They may not be set in a copy.
+ Hopefully there aren't many extra keys set on commands in
+ node names. */
+ //add_to_element_contents (trimmed, original->contents.list[i]);
+ add_to_contents_as_array (trimmed, original->contents.list[i]);
+ }
+ }
+
+ return trimmed;
+}
+
+
/* 3491 */
/* Add an "ET_empty_line_after_command" element containing the whitespace at
the beginning of the rest of the line. This element can be later changed
to
Modified: trunk/parsetexi/parser.h
===================================================================
--- trunk/parsetexi/parser.h 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/parser.h 2015-02-12 22:35:56 UTC (rev 6121)
@@ -42,6 +42,7 @@
char *read_command_name (char **ptr);
ELEMENT *merge_text (ELEMENT *current, char *text);
void start_empty_line_after_command (ELEMENT *current, char **line_inout);
+ELEMENT *trim_spaces_comment_from_content (ELEMENT *original);
extern const char *whitespace_chars, *whitespace_chars_except_newline;
extern const char *digit_chars;
@@ -65,6 +66,7 @@
/* In extra.c */
void add_extra_key_element (ELEMENT *e, char *key, ELEMENT *value);
void add_extra_key_contents (ELEMENT *e, char *key, ELEMENT *value);
+void add_extra_key_contents_array (ELEMENT *e, char *key, ELEMENT *value);
void add_extra_key_text (ELEMENT *e, char *key, ELEMENT *value);
void add_extra_key_index_entry (ELEMENT *e, char *key, INDEX_ENTRY_REF *value);
void add_extra_key_misc_args (ELEMENT *e, char *key, ELEMENT *value);
Modified: trunk/parsetexi/separator.c
===================================================================
--- trunk/parsetexi/separator.c 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/separator.c 2015-02-12 22:35:56 UTC (rev 6121)
@@ -21,6 +21,39 @@
#include "tree.h"
#include "text.h"
+// 3600
+/* Add the contents of CURRENT as an element to the extra value with
+ key KEY, except that some "empty space" elements are removed. Used for
+ 'brace_command_contents' for the arguments to a brace command, and
+ 'block_command_line_contents' for the arguments to a block line command.
+
+ For a brace command $element, $element->{'args'} has pretty much the same
+ information as $element->{'extra'}->{'brace_command_contents'}. */
+
+static void
+register_command_arg (ELEMENT *current, char *key)
+{
+ ELEMENT *value;
+ ELEMENT *new;
+ KEY_PAIR *k;
+
+ /* FIXME: Could we add all the command args together, instead of one-by-one,
+ to avoid having to look for the extra value every time? */
+ k = lookup_extra_key (current->parent, key);
+ if (k)
+ value = k->value;
+ else
+ {
+ value = new_element (ET_NONE);
+ value->parent_type = route_not_in_tree;
+ add_extra_key_contents_array (current->parent, key, value);
+ }
+
+ new = trim_spaces_comment_from_content (current);
+
+ add_to_contents_as_array (value, new);
+}
+
/* 4888 */
ELEMENT *
handle_open_brace (ELEMENT *current, char **line_inout)
@@ -29,8 +62,7 @@
abort_empty_line (¤t, NULL);
/* 4890 */
- if (command_flags(current) & CF_brace
- /* || definfoenclose */ )
+ if (command_flags(current) & CF_brace)
{
enum command_id command;
ELEMENT *arg;
@@ -86,9 +118,12 @@
else /* not context brace */
{
current->type = ET_brace_command_arg;
- /* If this command takes more than one argument (why??) */
- /* TODO: Also "simple text commands" 425 */
- if (command_data(command).data > 1)
+
+ /* Commands which are said to take a positive number of arguments
+ disregard leading and trailing whitespace. In
+ 'handle_close_brace', the 'brace_command_contents' array
+ is set. */
+ if (command_data(command).data > 0)
{
ELEMENT *e;
e = new_element (ET_empty_spaces_before_argument);
@@ -96,9 +131,12 @@
add_extra_key_element (current->parent,
"spaces_before_argument", e);
}
- /* 4956 - TODO inline commands */
+ else if (command_data(command).data == BRACE_inline)
+ {
+ // 4956
+ }
}
-
+ debug ("OPENED");
}
/* 4967 */
@@ -169,6 +207,14 @@
/* The Perl code here checks that the popped context and the
parent command match as strings. */
}
+ else if (command_data(current->parent->cmd).data > 0)
+ {
+ // 5033
+ isolate_last_space (current, 0);
+ register_command_arg (current, "brace_command_contents");
+ //remove_empty_content_arguments ();
+ }
+
closed_command = current->parent->cmd;
debug ("CLOSING(brace) %s", command_data(closed_command).cmdname);
@@ -261,7 +307,15 @@
abort_empty_line (¤t, NULL);
/* Register brace_command_contents or block_command_line_contents in extra
- key. Hopefully we won't have to do this. */
+ key. */
+ if (command_flags(current->parent) & CF_brace
+ && command_data(current->parent->cmd).data > 0)
+ {
+ // 5033
+ isolate_last_space (current, 0);
+ register_command_arg (current, "brace_command_contents");
+ //remove_empty_content_arguments ();
+ }
type = current->type;
current = current->parent;
Added: trunk/parsetexi/test-files/email.texi
===================================================================
--- trunk/parsetexi/test-files/email.texi (rev 0)
+++ trunk/parsetexi/test-files/email.texi 2015-02-12 22:35:56 UTC (rev
6121)
@@ -0,0 +1 @@
address@hidden, same place}
Modified: trunk/parsetexi/tree.c
===================================================================
--- trunk/parsetexi/tree.c 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/tree.c 2015-02-12 22:35:56 UTC (rev 6121)
@@ -77,7 +77,18 @@
e->parent = parent;
}
+/* Special purpose function for when we are only using PARENT as an
+ array, and we don't want to overwrite E->parent. */
void
+add_to_contents_as_array (ELEMENT *parent, ELEMENT *e)
+{
+ ELEMENT_LIST *list = &parent->contents;
+ reallocate_list (list);
+
+ list->list[list->number++] = e;
+}
+
+void
add_to_element_args (ELEMENT *parent, ELEMENT *e)
{
ELEMENT_LIST *list = &parent->args;
Modified: trunk/parsetexi/tree.h
===================================================================
--- trunk/parsetexi/tree.h 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/tree.h 2015-02-12 22:35:56 UTC (rev 6121)
@@ -16,6 +16,7 @@
ELEMENT *new_element (enum element_type type);
void add_to_element_contents (ELEMENT *parent, ELEMENT *e);
+void add_to_contents_as_array (ELEMENT *parent, ELEMENT *e);
void add_to_element_args (ELEMENT *parent, ELEMENT *e);
void insert_into_contents (ELEMENT *parent, ELEMENT *e, int where);
ELEMENT *remove_from_contents (ELEMENT *parent, int where);
Modified: trunk/parsetexi/tree_types.h
===================================================================
--- trunk/parsetexi/tree_types.h 2015-02-12 19:36:41 UTC (rev 6120)
+++ trunk/parsetexi/tree_types.h 2015-02-12 22:35:56 UTC (rev 6121)
@@ -27,6 +27,7 @@
enum extra_type {
extra_element,
extra_element_contents,
+ extra_element_contents_array,
extra_element_text,
extra_index_entry,
extra_misc_args,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6121] parsetexi register_command_arg,
Gavin D. Smith <=