[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[5972] parsetexi update
From: |
Gavin D. Smith |
Subject: |
[5972] parsetexi update |
Date: |
Wed, 17 Dec 2014 19:06:07 +0000 |
Revision: 5972
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5972
Author: gavin
Date: 2014-12-17 19:06:05 +0000 (Wed, 17 Dec 2014)
Log Message:
-----------
parsetexi update
Modified Paths:
--------------
trunk/parsetexi/ChangeLog
trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
trunk/parsetexi/api.c
trunk/parsetexi/dump_perl.c
trunk/parsetexi/handle_commands.c
trunk/parsetexi/input.c
trunk/parsetexi/input.h
trunk/parsetexi/main.c
trunk/parsetexi/parser.c
trunk/parsetexi/parser.h
trunk/parsetexi/tree_types.h
Modified: trunk/parsetexi/ChangeLog
===================================================================
--- trunk/parsetexi/ChangeLog 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/ChangeLog 2014-12-17 19:06:05 UTC (rev 5972)
@@ -1,3 +1,14 @@
+2014-12-17 Gavin Smith <address@hidden>
+
+ * tree_types.h (LINE_NR): Fields added to struct.
+ * input.c (line_nr): New variable.
+ (next_text, input_push_text, input_push_file): Update line_nr.
+ * handle_commands.c (handle_misc_command): Record current line
+ number.
+ * dump_perl.c (dump_element): Dump line number if one was
+ recorded. This allows error messages to be printed when
+ makeinfo is run.
+
2014-12-14 Gavin Smith <address@hidden>
* Parsetexi/lib/Parsetexi.pm: Put Texinfo::Report in @ISA.
Modified: trunk/parsetexi/Parsetexi/lib/Parsetexi.pm
===================================================================
--- trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2014-12-16 20:20:10 UTC (rev
5971)
+++ trunk/parsetexi/Parsetexi/lib/Parsetexi.pm 2014-12-17 19:06:05 UTC (rev
5972)
@@ -64,6 +64,13 @@
require XSLoader;
XSLoader::load('Parsetexi', $VERSION);
+sub get_conf($$)
+{
+ my $self = shift;
+ my $var = shift;
+ return $self->{$var};
+}
+
# Copied from Parser.pm
# Customization variables obeyed by the Parser, and the default values.
our %default_customization_values = (
Modified: trunk/parsetexi/api.c
===================================================================
--- trunk/parsetexi/api.c 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/api.c 2014-12-17 19:06:05 UTC (rev 5972)
@@ -11,9 +11,8 @@
parse_file (char *filename)
{
debug_output = 0;
- input_push_file (filename);
init_index_commands ();
- root = parse_texi_file ();
+ root = parse_texi_file (filename);
}
ELEMENT *
Modified: trunk/parsetexi/dump_perl.c
===================================================================
--- trunk/parsetexi/dump_perl.c 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/dump_perl.c 2014-12-17 19:06:05 UTC (rev 5972)
@@ -207,6 +207,32 @@
}
void
+dump_line_nr (ELEMENT *e)
+{
+ printf ("{\n");
+ indent += 2;
+
+ if (e->line_nr.file_name)
+ {
+ dump_indent ();
+ printf ("'file_name' => '%s',\n", e->line_nr.file_name);
+ }
+
+ if (e->line_nr.line_nr)
+ {
+ dump_indent ();
+ printf ("'line_nr' => %d,\n", e->line_nr.line_nr);
+ }
+
+ /* TODO: macro. */
+ printf ("'macro' => ''\n");
+
+ indent -= 2;
+ dump_indent ();
+ printf ("},\n");
+}
+
+void
dump_string (char *s)
{
while (*s)
@@ -238,6 +264,13 @@
printf ("',\n");
}
+ if (e->line_nr.line_nr)
+ {
+ dump_indent ();
+ printf ("'line_nr' => ");
+ dump_line_nr (e);
+ }
+
if (e->text.text)
{
dump_indent ();
Modified: trunk/parsetexi/handle_commands.c
===================================================================
--- trunk/parsetexi/handle_commands.c 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/handle_commands.c 2014-12-17 19:06:05 UTC (rev 5972)
@@ -2,8 +2,7 @@
#include <string.h>
#include "parser.h"
-#include "handle_commands.h"
-#include "tree.h"
+#include "input.h"
/* Return a containing @itemize or @enumerate if inside it. */
// 1847
@@ -201,6 +200,7 @@
/* Add to contents */
misc = new_element (ET_NONE);
misc->cmd = cmd_id;
+ misc->line_nr = line_nr;
add_to_element_contents (current, misc);
/* If root command, and not node or part: */
Modified: trunk/parsetexi/input.c
===================================================================
--- trunk/parsetexi/input.c 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/input.c 2014-12-17 19:06:05 UTC (rev 5972)
@@ -4,8 +4,8 @@
#include <stdio.h>
#include <string.h>
+#include "tree_types.h"
#include "input.h"
-#include "tree_types.h"
#include "text.h"
enum input_type { IN_file, IN_text };
@@ -14,15 +14,20 @@
enum input_type type;
FILE *file;
+ char *filename;
char *text;
char *ptext; /* How far we are through 'text'. */
+ int line_number;
} INPUT;
static INPUT *input_stack = 0;
static size_t input_number = 0;
static size_t input_space = 0;
+/* Current filename and line number. */
+LINE_NR line_nr;
+
/* Collect text until a newline is found. */
// I don't really understand the difference between this and next_text.
// When would next_text not return a string ending in a newline?
@@ -106,6 +111,7 @@
// 1920 CPP_LINE_DIRECTIVES
+ line_nr.line_nr++;
return line;
}
break;
@@ -126,13 +132,33 @@
}
}
input_number--;
+ if (input_number > 0 && input_stack[input_number - 1].type == IN_file)
+ {
+ /* Restore LINE_NR. */
+ line_nr.line_nr = input_stack[input_number - 1].line_number;
+ line_nr.file_name = input_stack[input_number - 1].filename;
+ }
}
return 0;
}
+static void
+save_line_nr (void)
+{
+ if (input_number == 0)
+ return;
+
+ if (input_stack[input_number - 1].type == IN_file)
+ {
+ input_stack[input_number - 1].line_number = line_nr.line_nr;
+ }
+}
+
void
input_push_text (char *text)
{
+ save_line_nr ();
+
if (input_number == input_space)
{
input_stack = realloc (input_stack,
@@ -145,11 +171,25 @@
input_stack[input_number].text = text;
input_stack[input_number].ptext = text;
input_number++;
+
+ /* TODO: What goes in LINE_NR? It depends whether this text is the result
of
+ a macro expansion, or was pushed back when reading the file preamble. */
}
void
-input_push_stream (FILE *stream)
+input_push_file (char *filename)
{
+ FILE *stream;
+ save_line_nr ();
+
+ stream = fopen (filename, "r");
+
+ if (!stream)
+ {
+ fprintf (stderr, "Could not open %s\n", filename);
+ exit (1);
+ }
+
if (input_number == input_space)
{
input_stack = realloc (input_stack, (input_space += 5) * sizeof (INPUT));
@@ -159,21 +199,13 @@
input_stack[input_number].type = IN_file;
input_stack[input_number].file = stream;
+ input_stack[input_number].filename = filename;
+ input_stack[input_number].line_number = 0;
input_number++;
-}
-void
-input_push_file (char *filename)
-{
- FILE *stream;
- stream = fopen (filename, "r");
- if (!stream)
- {
- fprintf (stderr, "Could not open %s\n", filename);
- exit (1);
- }
+ line_nr.line_nr = 0;
+ line_nr.file_name = filename;
- input_push_stream (stream);
return;
}
Modified: trunk/parsetexi/input.h
===================================================================
--- trunk/parsetexi/input.h 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/input.h 2014-12-17 19:06:05 UTC (rev 5972)
@@ -5,4 +5,5 @@
void input_push_file (char *line);
void input_push_text (char *filename);
-void input_push_stream (FILE *stream);
+
+extern LINE_NR line_nr;
Modified: trunk/parsetexi/main.c
===================================================================
--- trunk/parsetexi/main.c 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/main.c 2014-12-17 19:06:05 UTC (rev 5972)
@@ -13,9 +13,8 @@
fprintf (stderr, "Please give the name of a file to process.\n");
exit (1);
}
- input_push_file (argv[1]);
init_index_commands ();
- root = parse_texi_file ();
+ root = parse_texi_file (argv[1]);
dump_tree_to_perl (root);
exit (0);
Modified: trunk/parsetexi/parser.c
===================================================================
--- trunk/parsetexi/parser.c 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/parser.c 2014-12-17 19:06:05 UTC (rev 5972)
@@ -109,12 +109,14 @@
/* parse_texi_file */
/* 835 */
ELEMENT *
-parse_texi_file (void)
+parse_texi_file (char *filename)
{
char *linep, *line = 0;
ELEMENT *root = new_element (ET_text_root);
ELEMENT *preamble = 0;
+ input_push_file (filename);
+
/* Check for preamble. */
do
{
Modified: trunk/parsetexi/parser.h
===================================================================
--- trunk/parsetexi/parser.h 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/parser.h 2014-12-17 19:06:05 UTC (rev 5972)
@@ -31,7 +31,7 @@
void push_conditional_stack (enum command_id cond);
enum command_id pop_conditional_stack (void);
size_t conditional_number;
-ELEMENT *parse_texi_file (void);
+ELEMENT *parse_texi_file (char *filename);
int abort_empty_line (ELEMENT **current_inout, char *additional);
ELEMENT *end_paragraph (ELEMENT *current);
void isolate_last_space (ELEMENT *current);
Modified: trunk/parsetexi/tree_types.h
===================================================================
--- trunk/parsetexi/tree_types.h 2014-12-16 20:20:10 UTC (rev 5971)
+++ trunk/parsetexi/tree_types.h 2014-12-17 19:06:05 UTC (rev 5972)
@@ -27,6 +27,9 @@
} ELEMENT_LIST;
typedef struct LINE_NR {
+ int line_nr;
+ char *file_name;
+ char *macro;
} LINE_NR;
/* Type of a link in the route from the root of the tree to an element. */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [5972] parsetexi update,
Gavin D. Smith <=