[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[6090] parsetexi pass error messages
From: |
Gavin D. Smith |
Subject: |
[6090] parsetexi pass error messages |
Date: |
Sun, 01 Feb 2015 16:03:09 +0000 |
Revision: 6090
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=6090
Author: gavin
Date: 2015-02-01 16:03:07 +0000 (Sun, 01 Feb 2015)
Log Message:
-----------
parsetexi pass error messages
Modified Paths:
--------------
trunk/parsetexi/ChangeLog
trunk/parsetexi/Makefile.am
trunk/parsetexi/Parsetexi/Parsetexi.xs
trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
trunk/parsetexi/dump_perl.c
trunk/parsetexi/end_line.c
trunk/parsetexi/parser.h
Added Paths:
-----------
trunk/parsetexi/dump_perl.h
trunk/parsetexi/errors.c
trunk/parsetexi/errors.h
trunk/parsetexi/test-files/error.texi
Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog 2015-01-31 22:18:58 UTC (rev 6089)
+++ trunk/parsetexi/ChangeLog 2015-02-01 16:03:07 UTC (rev 6090)
@@ -1,3 +1,16 @@
+2015-02-01 Gavin Smith <address@hidden>
+
+ * errors.c: New file.
+ (line_error, line_errorf, dump_errors): New functions.
+ * end_line.c (parse_line_command_args) <@sp>: Call line_errorf
+ if argument is malformed.
+
+ * Parsetexi/lib/Parsetexi.pm (parse_texi_file): Fetch error
+ messages.
+
+ * dump_perl.c (dump_line_nr): Arguments changed.
+ * test-files/error.texi: New test file.
+
2015-01-31 Gavin Smith <address@hidden>
* command_data.txt: Specify argument types of the other "misc"
Modified: trunk/parsetexi/Makefile.am
===================================================================
--- trunk/parsetexi/Makefile.am 2015-01-31 22:18:58 UTC (rev 6089)
+++ trunk/parsetexi/Makefile.am 2015-02-01 16:03:07 UTC (rev 6090)
@@ -24,10 +24,11 @@
macro.c \
handle_commands.c handle_commands.h \
def.c def.h \
- dump_perl.c \
+ dump_perl.c dump_perl.h \
extra.c \
menus.c \
- labels.c
+ labels.c \
+ errors.c errors.h
parsetexi_SOURCES=$(libparsetexi_a_SOURCES) main.c
Modified: trunk/parsetexi/Parsetexi/Parsetexi.xs
===================================================================
--- trunk/parsetexi/Parsetexi/Parsetexi.xs 2015-01-31 22:18:58 UTC (rev
6089)
+++ trunk/parsetexi/Parsetexi/Parsetexi.xs 2015-02-01 16:03:07 UTC (rev
6090)
@@ -8,6 +8,7 @@
#include "../tree_types.h"
#include "../tree.h"
#include "../api.h"
+#include "../errors.h"
MODULE = Parsetexi PACKAGE = Parsetexi
@@ -15,6 +16,8 @@
ELEMENT * T_UV
END
+PROTOTYPES: ENABLE
+
char *
dump_tree_to_string_1 ()
@@ -28,6 +31,9 @@
char *dump_root_element_2 ()
+char *
+dump_errors ()
+
void
parse_file(filename)
char * filename
Modified: trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
===================================================================
--- trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2015-01-31 22:18:58 UTC (rev
6089)
+++ trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2015-02-01 16:03:07 UTC (rev
6090)
@@ -246,7 +246,7 @@
#print "Getting tree...\n";
- my ($TREE, $LABELS, $INDEX_NAMES);
+ my ($TREE, $LABELS, $INDEX_NAMES, $ERRORS);
if (1) {
# $| = 1; # Flush after each print
print "Parsing file...\n";
@@ -291,6 +291,16 @@
$self->{'index_names'} = $INDEX_NAMES;
+ # Copy the errors into the error list in Texinfo::Report.
+ # TODO: Could we just access the error list directly instead of going
+ # through Texinfo::Report line_error?
+ $tree_stream = dump_errors();
+ eval $tree_stream;
+ for my $error (@{$ERRORS}) {
+ $self->line_error ($error->{'message'}, $error->{'line_nr'});
+ }
+
+
#$Data::Dumper::Purity = 1;
#$Data::Dumper::Indent = 1;
#my $bar = Data::Dumper->Dump([$TREE], ['$TREE']);
Modified: trunk/parsetexi/dump_perl.c
===================================================================
--- trunk/parsetexi/dump_perl.c 2015-01-31 22:18:58 UTC (rev 6089)
+++ trunk/parsetexi/dump_perl.c 2015-02-01 16:03:07 UTC (rev 6090)
@@ -28,7 +28,7 @@
#define TREE_ROOT_VAR "$TREE"
-int indent = 0;
+static int indent = 0;
/* A dump to fill in references from one part of the tree to another. */
static TEXT fixup_dump;
@@ -42,7 +42,7 @@
void dump_args (ELEMENT *, TEXT *);
/* Output INDENT spaces. */
-void
+static void
dump_indent (TEXT *text)
{
int i;
@@ -352,22 +352,22 @@
}
void
-dump_line_nr (ELEMENT *e, TEXT *text)
+dump_line_nr (LINE_NR *line_nr, TEXT *text)
{
text_append_n (text, "{\n", 2);
indent += 2;
- if (e->line_nr.file_name)
+ if (line_nr->file_name)
{
dump_indent (text);
- text_printf (text, "'file_name' => '%s',\n", e->line_nr.file_name);
+ text_printf (text, "'file_name' => '%s',\n", line_nr->file_name);
}
- if (e->line_nr.line_nr)
+ if (line_nr->line_nr)
{
dump_indent (text);
text_append (text, "'line_nr' => ");
- text_printf (text, "%d", e->line_nr.line_nr);
+ text_printf (text, "%d", line_nr->line_nr);
text_append (text, ",\n");
}
@@ -404,7 +404,7 @@
{
dump_indent (text);
text_append (text, "'line_nr' => ");
- dump_line_nr (e, text);
+ dump_line_nr (&e->line_nr, text);
}
if (e->text.text)
@@ -602,7 +602,7 @@
{
dump_indent (text);
text_append (text, "'line_nr' => ");
- dump_line_nr (e, text);
+ dump_line_nr (&e->line_nr, text);
}
if (e->text.text)
Added: trunk/parsetexi/dump_perl.h
===================================================================
--- trunk/parsetexi/dump_perl.h (rev 0)
+++ trunk/parsetexi/dump_perl.h 2015-02-01 16:03:07 UTC (rev 6090)
@@ -0,0 +1,4 @@
+void dump_tree_to_perl (ELEMENT *root);
+void dump_string (char *s, TEXT *text);
+void dump_line_nr (LINE_NR *line_nr, TEXT *text);
+
Modified: trunk/parsetexi/end_line.c
===================================================================
--- trunk/parsetexi/end_line.c 2015-01-31 22:18:58 UTC (rev 6089)
+++ trunk/parsetexi/end_line.c 2015-02-01 16:03:07 UTC (rev 6090)
@@ -24,6 +24,7 @@
#include "convert.h"
#include "labels.h"
#include "indices.h"
+#include "errors.h"
// 5467, also in Common.pm 1334
// TODO: Check the behaviour here is the same
@@ -152,7 +153,7 @@
ADD_ARG (line)
}
else
- abort ();
+ line_errorf ("@sp arg must be numeric, not `%s'", line);
break;
}
case CM_defindex:
Added: trunk/parsetexi/errors.c
===================================================================
--- trunk/parsetexi/errors.c (rev 0)
+++ trunk/parsetexi/errors.c 2015-02-01 16:03:07 UTC (rev 6090)
@@ -0,0 +1,87 @@
+/* Copyright 2010, 2011, 2012, 2013, 2014, 2015
+ Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+#include "tree_types.h"
+#include "input.h"
+#include "text.h"
+#include "dump_perl.h"
+#include "errors.h"
+
+enum error_type { error, warning };
+
+typedef struct {
+ char *message;
+ enum error_type type;
+ LINE_NR line_nr;
+} ERROR_MESSAGE;
+
+static ERROR_MESSAGE *error_list = 0;
+static size_t error_number = 0;
+static size_t error_space = 0;
+
+void
+line_error (char *message)
+{
+ if (error_number == error_space)
+ {
+ error_list = realloc (error_list,
+ (error_space += 10) * sizeof (ERROR_MESSAGE));
+ }
+ error_list[error_number].message = message;
+ error_list[error_number].type = error;
+ error_list[error_number++].line_nr = line_nr; /* Field-by-field copy. */
+}
+
+void
+line_errorf (char *format, ...)
+{
+ va_list v;
+ char *message;
+
+ va_start (v, format);
+ vasprintf (&message, format, v);
+ line_error (message);
+}
+
+
+char *
+dump_errors (void)
+{
+ int i;
+ TEXT t;
+
+ text_init (&t);
+ text_append (&t, "$ERRORS = [\n");
+ for (i = 0; i < error_number; i++)
+ {
+ text_append (&t, "{ 'message' =>\n'");
+ dump_string (error_list[i].message, &t);
+ text_append (&t, "',\n");
+ text_printf (&t, "'type' => '%s',", error_list[i].type == error ? "error"
+ : "warning");
+ text_append (&t, "'line_nr' => ");
+ dump_line_nr (&error_list[i].line_nr, &t);
+ text_append (&t, "},\n");
+ }
+ text_append (&t, "];\n");
+
+ return t.text;
+}
+
+
Added: trunk/parsetexi/errors.h
===================================================================
--- trunk/parsetexi/errors.h (rev 0)
+++ trunk/parsetexi/errors.h 2015-02-01 16:03:07 UTC (rev 6090)
@@ -0,0 +1,3 @@
+void line_error (char *message);
+void line_errorf (char *format, ...);
+char *dump_errors (void);
Modified: trunk/parsetexi/parser.h
===================================================================
--- trunk/parsetexi/parser.h 2015-01-31 22:18:58 UTC (rev 6089)
+++ trunk/parsetexi/parser.h 2015-02-01 16:03:07 UTC (rev 6090)
@@ -60,8 +60,7 @@
ELEMENT *item_line_parent (ELEMENT *current);
ELEMENT *item_multitable_parent (ELEMENT *current);
-/* In dump_perl.c */
-void dump_tree_to_perl (ELEMENT *root);
+#include "dump_perl.h"
/* In extra.c */
void add_extra_key_element (ELEMENT *e, char *key, ELEMENT *value);
Added: trunk/parsetexi/test-files/error.texi
===================================================================
--- trunk/parsetexi/test-files/error.texi (rev 0)
+++ trunk/parsetexi/test-files/error.texi 2015-02-01 16:03:07 UTC (rev
6090)
@@ -0,0 +1,5 @@
address@hidden Top
+
address@hidden xxx
address@hidden 1212
address@hidden 1212yyy
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [6090] parsetexi pass error messages,
Gavin D. Smith <=