texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[5954] parsetexi update


From: Gavin D. Smith
Subject: [5954] parsetexi update
Date: Wed, 10 Dec 2014 22:27:36 +0000

Revision: 5954
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5954
Author:   gavin
Date:     2014-12-10 22:27:36 +0000 (Wed, 10 Dec 2014)
Log Message:
-----------
parsetexi update

Modified Paths:
--------------
    trunk/parsetexi/Parsetexi/Parsetexi.xs
    trunk/parsetexi/Parsetexi/t/Parsetexi.t

Added Paths:
-----------
    trunk/parsetexi/Parsetexi/t/sample.texi
    trunk/parsetexi/api.c
    trunk/parsetexi/api.h
    trunk/parsetexi/dump_perl.c

Modified: trunk/parsetexi/Parsetexi/Parsetexi.xs
===================================================================
--- trunk/parsetexi/Parsetexi/Parsetexi.xs      2014-12-10 22:00:56 UTC (rev 
5953)
+++ trunk/parsetexi/Parsetexi/Parsetexi.xs      2014-12-10 22:27:36 UTC (rev 
5954)
@@ -27,5 +27,18 @@
 get_root()
 
 char *
-element_type_namex (e)
+element_type_name(e)
         ELEMENT *e
+
+int
+num_contents_children(e)
+        ELEMENT *e
+
+int
+num_args_children (e)
+        ELEMENT *e
+
+ELEMENT *
+contents_child_by_index (e, index)
+        ELEMENT *e
+        int index

Modified: trunk/parsetexi/Parsetexi/t/Parsetexi.t
===================================================================
--- trunk/parsetexi/Parsetexi/t/Parsetexi.t     2014-12-10 22:00:56 UTC (rev 
5953)
+++ trunk/parsetexi/Parsetexi/t/Parsetexi.t     2014-12-10 22:27:36 UTC (rev 
5954)
@@ -8,7 +8,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 BEGIN { use_ok('Parsetexi') };
 
 #########################
@@ -17,13 +17,19 @@
 # its man page ( perldoc Test::More ) for help writing this test script.
 
 my $root;
-Parsetexi::parse_file ("sample.texi");
+Parsetexi::parse_file ("t/sample.texi");
 $root = Parsetexi::get_root ();
 
-my $root_type;
-$root_type = Parsetexi::element_type_namex ($root);
+my $type;
+$type = Parsetexi::element_type_name ($root);
 
-is ($root_type, 'document_root');
+is ($type, 'document_root');
 
-print "Root type is $root_type.\n"
+my $first_child;
+$first_child = Parsetexi::contents_child_by_index ($root, 0);
+$type = Parsetexi::element_type_name ($first_child);
 
+is ($type, 'text_root');
+
+print STDERR "Num children is " . Parsetexi::num_contents_children ($root);
+

Added: trunk/parsetexi/Parsetexi/t/sample.texi
===================================================================
--- trunk/parsetexi/Parsetexi/t/sample.texi                             (rev 0)
+++ trunk/parsetexi/Parsetexi/t/sample.texi     2014-12-10 22:27:36 UTC (rev 
5954)
@@ -0,0 +1,64 @@
+\input texinfo   @c -*-texinfo-*-
address@hidden %**start of header
address@hidden sample.info
address@hidden Sample Manual 1.0
address@hidden %**end of header
+
address@hidden
+This is a short example of a complete Texinfo file.
+
+Copyright @copyright{} 2014 Free Software Foundation, Inc.
address@hidden copying
+
address@hidden
address@hidden Sample Title
address@hidden
address@hidden 0pt plus 1filll
address@hidden
address@hidden titlepage
+
address@hidden Output the table of the contents at the beginning.
address@hidden
+
address@hidden
address@hidden Top
address@hidden GNU Sample
+
+This manual is for GNU Sample
+(version @value{VERSION}, @value{UPDATED}).
address@hidden ifnottex
+
address@hidden
+* First Chapter::    The first chapter is the
+                      only chapter in this sample.
+* Index::            Complete index.
address@hidden menu
+
+
address@hidden First Chapter
address@hidden First Chapter
+
address@hidden chapter, first
+
+This is the first chapter.
address@hidden index entry, another
+
+Here is a numbered list.
+
address@hidden
address@hidden
+This is the first item.
+
address@hidden
+This is the second item.
address@hidden enumerate
+
+
address@hidden Index
address@hidden Index
+
+
address@hidden cp
+
address@hidden
+

Added: trunk/parsetexi/api.c
===================================================================
--- trunk/parsetexi/api.c                               (rev 0)
+++ trunk/parsetexi/api.c       2014-12-10 22:27:36 UTC (rev 5954)
@@ -0,0 +1,42 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "parser.h"
+#include "input.h"
+
+static ELEMENT *root;
+
+/* Set ROOT to root of tree obtained by parsing FILENAME. */
+void
+parse_file (char *filename)
+{
+  debug_output = 0;
+  input_push_file (filename);
+  init_index_commands ();
+  root = parse_texi_file ();
+}
+
+ELEMENT *
+get_root (void)
+{
+  return root;
+}
+
+char *
+element_type_name (ELEMENT *e)
+{
+  return element_type_names[(e)->type];
+}
+
+int
+num_contents_children (ELEMENT *e)
+{
+  return e->contents.number;
+}
+
+int
+num_args_children (ELEMENT *e)
+{
+  return e->args.number;
+}
+

Added: trunk/parsetexi/api.h
===================================================================
--- trunk/parsetexi/api.h                               (rev 0)
+++ trunk/parsetexi/api.h       2014-12-10 22:27:36 UTC (rev 5954)
@@ -0,0 +1,6 @@
+
+void parse_file (char *filename);
+ELEMENT *get_root (void);
+char *element_type_name (ELEMENT *element);
+int num_contents_children (ELEMENT *e);
+int num_args_children (ELEMENT *e);

Added: trunk/parsetexi/dump_perl.c
===================================================================
--- trunk/parsetexi/dump_perl.c                         (rev 0)
+++ trunk/parsetexi/dump_perl.c 2014-12-10 22:27:36 UTC (rev 5954)
@@ -0,0 +1,129 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "parser.h"
+#include "input.h"
+
+#define element_type_name(e) element_type_names[(e)->type]
+
+int indent = 0;
+
+void dump_contents (ELEMENT *);
+void dump_element (ELEMENT *);
+
+/* Output INDENT spaces. */
+void
+dump_indent (void)
+{
+  int i;
+  for (i = 0; i < indent; i++)
+    printf (" ");
+}
+
+void
+dump_args (ELEMENT *e)
+{
+  int i;
+  printf ("[\n");
+  indent += 2;
+
+  for (i = 0; i < e->args.number; i++)
+    {
+      dump_indent ();
+      dump_element (e->args.list[i]);
+      printf (",\n");
+    }
+
+  indent -= 2;
+  dump_indent ();
+  printf ("],\n");
+}
+
+void
+dump_contents (ELEMENT *e)
+{
+  int i;
+  printf ("[\n");
+  indent += 2;
+
+  for (i = 0; i < e->contents.number; i++)
+    {
+      dump_indent ();
+      dump_element (e->contents.list[i]);
+      printf (",\n");
+    }
+
+  indent -= 2;
+  dump_indent ();
+  printf ("],\n");
+}
+
+void
+dump_string (char *s)
+{
+     while (*s)
+       {
+         if (*s == '\''
+           || *s == '\\')
+           putchar ('\\');
+         putchar (*s++);
+       }
+}
+
+void
+dump_element (ELEMENT *e)
+{
+  printf ("{\n");
+  indent += 2;
+  
+  if (e->type)
+    {
+      dump_indent ();
+      printf ("'type' => '%s',\n", element_type_name(e));
+    }
+
+  if (e->cmd)
+    {
+      dump_indent ();
+      printf ("'cmdname' => '");
+      dump_string (command_data(e->cmd).cmdname);
+      printf ("',\n");
+    }
+  
+  if (e->text.text)
+    {
+      char *s;
+      dump_indent ();
+      /* FIXME: Need to escape backslashes, e.g. output
+         \\input instead of \input. */
+      printf ("'text' => '");
+      dump_string (e->text.text);
+      printf ("',\n");
+    }
+
+  if (e->args.number > 0)
+    {
+      dump_indent ();
+      printf ("'args' => ");
+      dump_args (e);
+    }
+
+  if (e->contents.number > 0)
+    {
+      dump_indent ();
+      printf ("'contents' => ");
+      dump_contents (e);
+    }
+
+  indent -= 2;
+  dump_indent ();
+  printf ("}");
+}
+
+void
+dump_tree_to_perl (ELEMENT *root)
+{
+  printf ("$VAR1 = ");
+  dump_element (root);
+  printf (";\n");
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]