[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[7250] parsetexi update
From: |
gavinsmith0123 |
Subject: |
[7250] parsetexi update |
Date: |
Sat, 9 Jul 2016 21:35:26 +0000 (UTC) |
Revision: 7250
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=7250
Author: gavin
Date: 2016-07-09 21:35:26 +0000 (Sat, 09 Jul 2016)
Log Message:
-----------
parsetexi update
Modified Paths:
--------------
trunk/tp/parsetexi/ChangeLog
trunk/tp/parsetexi/convert.c
trunk/tp/parsetexi/convert.h
trunk/tp/parsetexi/end_line.c
trunk/tp/parsetexi/parser.c
Modified: trunk/tp/parsetexi/ChangeLog
===================================================================
--- trunk/tp/parsetexi/ChangeLog 2016-07-09 20:26:17 UTC (rev 7249)
+++ trunk/tp/parsetexi/ChangeLog 2016-07-09 21:35:26 UTC (rev 7250)
@@ -1,3 +1,8 @@
+2016-07-09 Gavin Smith <address@hidden>
+
+ * convert.c (convert_to_texinfo): New function.
+ (text_convert): Remove.
+
2016-06-13 Gavin Smith <address@hidden>
* Makefile.am (bin_PROGRAMS): Add an independent 'parsetexi'
Modified: trunk/tp/parsetexi/convert.c
===================================================================
--- trunk/tp/parsetexi/convert.c 2016-07-09 20:26:17 UTC (rev 7249)
+++ trunk/tp/parsetexi/convert.c 2016-07-09 21:35:26 UTC (rev 7250)
@@ -1,4 +1,4 @@
-/* Copyright 2010, 2011, 2012, 2013, 2014, 2015
+/* Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016
Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
@@ -22,24 +22,106 @@
#include "parser.h"
#include "text.h"
-/* Stub for Texinfo::Convert::Text::convert */
-/* TODO: Don't use this function at all. */
-char *
-text_convert (ELEMENT *e)
+#define ADD(x) text_append (result, x)
+
+static void expand_cmd_args_to_texi (ELEMENT *e, TEXT *result);
+static void convert_to_texinfo_internal (ELEMENT *e, TEXT *result);
+
+
+
+static void
+expand_cmd_args_to_texi (ELEMENT *e, TEXT *result)
{
- int which = e->contents.number;
- which--;
- if (which > 0)
+ enum command_id cmd = e->cmd;
+
+ if (cmd)
{
- if (e->contents.list[which]->type == ET_spaces_at_end)
- which--;
+ ADD("@"); ADD(command_name(cmd));
+ }
- if (which > 0 && e->contents.list[which]->text.text)
- return e->contents.list[which]->text.text;
+ // TODO extra spaces
+
+ // TODO multitable or block command
+
+ // TODO macro
+
+ // TODO node
+
+ // TODO "fix" arg
+
+ if (e->args.number > 0)
+ {
+ int braces, arg_nr, i;
+ braces = (e->args.list[0]->type == ET_brace_command_arg
+ || e->args.list[0]->type == ET_brace_command_context);
+ if (braces)
+ ADD("{");
+
+ // TODO @verb
+
+ arg_nr = 0;
+ for (i = 0; i < e->args.number; i++)
+ {
+ if (command_data(cmd).flags & CF_brace)
+ {
+ if (arg_nr)
+ ADD(",");
+ arg_nr++;
+ }
+ convert_to_texinfo_internal (e->args.list[i], result);
+ }
+
+ // TODO @verb
+
+ if (braces)
+ ADD("}");
}
- return "";
}
+static void
+convert_to_texinfo_internal (ELEMENT *e, TEXT *result)
+{
+ if (e->text.end > 0)
+ ADD(e->text.text);
+ else
+ {
+ // TODO "fix" argument
+
+ if (e->cmd)
+ {
+ expand_cmd_args_to_texi (e, result);
+ }
+
+ if (e->type == ET_bracketed)
+ ADD("{");
+ if (e->contents.number > 0)
+ {
+ int i;
+ for (i = 0; i < e->contents.number; i++)
+ convert_to_texinfo_internal (e->contents.list[i], result);
+ }
+ if (e->type == ET_bracketed)
+ ADD("}");
+
+ // TODO: "fix" arg or raw block command
+ }
+
+ return;
+}
+#undef ADD
+
+char *
+convert_to_texinfo (ELEMENT *e)
+{
+ TEXT result;
+
+ if (!e)
+ return "";
+ text_init (&result);
+ convert_to_texinfo_internal (e, &result);
+ return result.text;
+}
+
/* Produce normalized node name recursively. IN_UC is non-zero if we are
converting to upper case. */
static void
Modified: trunk/tp/parsetexi/convert.h
===================================================================
--- trunk/tp/parsetexi/convert.h 2016-07-09 20:26:17 UTC (rev 7249)
+++ trunk/tp/parsetexi/convert.h 2016-07-09 21:35:26 UTC (rev 7250)
@@ -1,2 +1,2 @@
-char *text_convert (ELEMENT *e);
char *convert_to_normalized (ELEMENT *label);
+char *convert_to_texinfo (ELEMENT *e);
Modified: trunk/tp/parsetexi/end_line.c
===================================================================
--- trunk/tp/parsetexi/end_line.c 2016-07-09 20:26:17 UTC (rev 7249)
+++ trunk/tp/parsetexi/end_line.c 2016-07-09 21:35:26 UTC (rev 7250)
@@ -1318,36 +1318,32 @@
else if (arg_type == MISC_text) /* 3118 */
{
char *text = 0;
-
- /* argument string has to be parsed as Texinfo. This calls convert in
- Common/Text.pm on the first element of current->args. */
- /* however, this makes it impossible to decouple the parser and
- output stages... Any use of Texinfo::Convert is problematic. */
- /* Fortunately Text.pm is not too complicated (unlike Plaintext.pm). */
+ int superfluous_arg = 0;
+ int i;
+ ELEMENT *trimmed = 0;
- // TODO: Convert properly.
if (current->args.number > 0)
{
- int i;
- ELEMENT *arg = current->args.list[0];
- for (i = 0; i < arg->contents.number; i++)
- {
- ELEMENT *e = arg->contents.list[i];
- if (e->type != ET_empty_spaces_after_command
- && e->type != ET_spaces_at_end
- && e->text.end > 0)
- {
- text = e->text.text;
- break;
- }
- }
+ trimmed = trim_spaces_comment_from_content
+ (args_child_by_index(current, 0));
+
+ if (trimmed->contents.number > 1
+ || (trimmed->contents.number == 1
+ && !trimmed->contents.list[0]->text.text))
+ superfluous_arg = 1;
+
+ text = trimmed->contents.list[0]->text.text;
}
+
if (!text)
text = "";
+ //destroy_element (trimmed);
if (!text || !strcmp (text, ""))
{
- line_warn ("@%s missing argument", command_name(cmd)); // 3123
+ if (!superfluous_arg)
+ line_warn ("@%s missing argument", command_name(cmd)); // 3123
+ add_extra_string (current, "missing_argument", "1");
}
else
{
@@ -1402,11 +1398,21 @@
strdup (end_command));
}
if (end_command
- && line[strspn (line, whitespace_chars)] != '\0')
+ && (superfluous_arg
+ || line[strspn (line, whitespace_chars)] != '\0'))
{
+ char *line, *line2;
+ line = convert_to_texinfo (current->args.list[0]);
+
+ line2 = line;
+ line2 += strspn (line2, whitespace_chars);
+ free (read_command_name (&line2));
command_error (current,
"superfluous argument to @end %s: "
- "%s", end_command, line);
+ "%s", end_command, line2);
+ superfluous_arg = 0; /* Don't issue another error
+ message below. */
+ free (line);
}
}
}
@@ -1415,6 +1421,10 @@
command_error (current, "bad argument to @end: %s", line);
}
}
+ else if (0 && superfluous_arg)
+ {
+ /* An error message is issued below. */
+ }
else if (current->cmd == CM_include) // 3166
{
debug ("Include %s", text);
@@ -1480,6 +1490,12 @@
{
}
}
+ if (superfluous_arg)
+ {
+ command_error (current, "bad argument to @%s",
+ command_name(current->cmd));
+ // TODO say what the bad argument is
+ }
}
else if (current->cmd == CM_node) /* 3235 */
{
Modified: trunk/tp/parsetexi/parser.c
===================================================================
--- trunk/tp/parsetexi/parser.c 2016-07-09 20:26:17 UTC (rev 7249)
+++ trunk/tp/parsetexi/parser.c 2016-07-09 21:35:26 UTC (rev 7250)
@@ -820,18 +820,21 @@
p = line + strspn (line, whitespace_chars);
if (*p && *p != '@')
goto superfluous_arg;
- p++;
- tmp = read_command_name (&p);
- if (tmp && (!strcmp (tmp, "c") || !strcmp (tmp, "comment")))
+ if (*p)
{
- }
- else if (0)
- {
+ p++;
+ tmp = read_command_name (&p);
+ if (tmp && (!strcmp (tmp, "c") || !strcmp (tmp, "comment")))
+ {
+ }
+ else if (*p && p[strspn (p, whitespace_chars)])
+ {
superfluous_arg:
- line_warn ("superfluous argument to @end %s: %s",
- command_name (current->cmd), line);
+ line_warn ("superfluous argument to @end %s: %s",
+ command_name (current->cmd), line);
+ }
+ free (tmp);
}
- free (tmp);
/* For macros, define a new macro (unless we are in a nested
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [7250] parsetexi update,
gavinsmith0123 <=