From 397826665153ef2e26f76e7dc7bf082e1537bc41 Mon Sep 17 00:00:00 2001
From: "Meredith L. Patterson" <mlp@thesmartpolitenerd.com>
Date: Thu, 23 May 2013 02:16:52 -0700
Subject: [PATCH] further merging of pesco's and aegis' changes

---
 README.md     | 23 ++++++++++--------
 src/Makefile  |  2 --
 src/actions.c | 60 -----------------------------------------------
 src/glue.c    | 64 +++++++++++++++++++++++++++++++++++++++++++--------
 src/glue.h    |  5 +++-
 5 files changed, 71 insertions(+), 83 deletions(-)
 delete mode 100644 src/actions.c

diff --git a/README.md b/README.md
index e008b12d..91ee36c0 100644
--- a/README.md
+++ b/README.md
@@ -11,24 +11,25 @@ Features
 * Benchmarking for parsing backends -- determine empirically which backend will be most time-efficient for your grammar
 * Parsing backends:
   * Packrat parsing
-  * LL(k) (not yet implemented)
+  * LL(k) 
   * GLR (not yet implemented)
   * LALR(8) (not yet implemented)
-  * Regular expressions (not yet implemented)
-* Language bindings: (not yet implemented)
-  * C++
+  * Regular expressions 
+* Language bindings: 
+  * C++ (not yet implemented)
   * Java
-  * Python
-  * Ruby
-  * Perl
-  * Go
-  * PHP
-  * .NET
+  * Python (not yet implemented)
+  * Ruby (not yet implemented)
+  * Perl (not yet implemented)
+  * Go (not yet implemented)
+  * PHP (not yet implemented)
+  * .NET (not yet implemented)
 
 Installing
 ==========
 ### Prerequisites
 * make
+* a JDK
 
 ### Optional Dependencies
 * pkg-config (for `make test`)
@@ -37,6 +38,8 @@ Installing
 
 To install, type `make`. To run the built-in test suite, type `make test`.
 
+If jni.h and jni_md.h aren't already somewhere on your include path, prepend `C_INCLUDE_PATH=/path/to/jdk/include` to that.
+
 There is not currently a `make install` target; to make Hammer available system-wide, copy `libhammer.a` to `/usr/lib/` (or `/usr/local/lib/`, or wherever ld will find it) and `hammer.h` to `/usr/include/`. 
 
 Usage
diff --git a/src/Makefile b/src/Makefile
index 94690d36..cafafa85 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -41,8 +41,6 @@ HAMMER_PARTS := \
 	system_allocator.o \
 	benchmark.o \
 	cfgrammar.o \
-	actions.o \
-	compile.o \
 	glue.o \
 	$(PARSERS:%=parsers/%.o) \
 	$(BACKENDS:%=backends/%.o)
diff --git a/src/actions.c b/src/actions.c
deleted file mode 100644
index 9fc2225d..00000000
--- a/src/actions.c
+++ /dev/null
@@ -1,60 +0,0 @@
-// XXX to be consolidated with glue.c when merged upstream
-
-#include <assert.h>
-#include "hammer.h"
-#include "internal.h"
-#include "parsers/parser_internal.h"
-
-
-const HParsedToken *h_act_first(const HParseResult *p) {
-  assert(p->ast);
-  assert(p->ast->token_type == TT_SEQUENCE);
-  assert(p->ast->seq->used > 0);
-
-  return p->ast->seq->elements[0];
-}
-
-const HParsedToken *h_act_second(const HParseResult *p) {
-  assert(p->ast);
-  assert(p->ast->token_type == TT_SEQUENCE);
-  assert(p->ast->seq->used > 0);
-
-  return p->ast->seq->elements[1];
-}
-
-const HParsedToken *h_act_last(const HParseResult *p) {
-  assert(p->ast);
-  assert(p->ast->token_type == TT_SEQUENCE);
-  assert(p->ast->seq->used > 0);
-
-  return p->ast->seq->elements[p->ast->seq->used-1];
-}
-
-static void act_flatten_(HCountedArray *seq, const HParsedToken *tok) {
-  if(tok == NULL) {
-    return;
-  } else if(tok->token_type == TT_SEQUENCE) {
-    size_t i;
-    for(i=0; i<tok->seq->used; i++)
-      act_flatten_(seq, tok->seq->elements[i]);
-  } else {
-    h_carray_append(seq, (HParsedToken *)tok);
-  }
-}
-
-const HParsedToken *h_act_flatten(const HParseResult *p) {
-  HCountedArray *seq = h_carray_new(p->arena);
-
-  act_flatten_(seq, p->ast);
-
-  HParsedToken *res = a_new_(p->arena, HParsedToken, 1);
-  res->token_type = TT_SEQUENCE;
-  res->seq = seq;
-  res->index = p->ast->index;
-  res->bit_offset = p->ast->bit_offset;
-  return res;
-}
-
-const HParsedToken *h_act_ignore(const HParseResult *p) {
-  return NULL;
-}
diff --git a/src/glue.c b/src/glue.c
index f1e086a5..2cbfde6c 100644
--- a/src/glue.c
+++ b/src/glue.c
@@ -1,12 +1,8 @@
+#include <assert.h>
 #include "glue.h"
-#include "../src/internal.h"  // for h_carray_*
-
-
-// The action equivalent of h_ignore.
-const HParsedToken *h_act_ignore(const HParseResult *p)
-{
-  return NULL;
-}
+#include "hammer.h"
+#include "internal.h"  // for h_carray_*
+#include "parsers/parser_internal.h"
 
 // Helper to build HAction's that pick one index out of a sequence.
 const HParsedToken *h_act_index(int i, const HParseResult *p)
@@ -27,9 +23,57 @@ const HParsedToken *h_act_index(int i, const HParseResult *p)
         return tok->seq->elements[i];
 }
 
-// Action version of h_seq_flatten.
+const HParsedToken *h_act_first(const HParseResult *p) {
+  assert(p->ast);
+  assert(p->ast->token_type == TT_SEQUENCE);
+  assert(p->ast->seq->used > 0);
+
+  return p->ast->seq->elements[0];
+}
+
+const HParsedToken *h_act_second(const HParseResult *p) {
+  assert(p->ast);
+  assert(p->ast->token_type == TT_SEQUENCE);
+  assert(p->ast->seq->used > 0);
+
+  return p->ast->seq->elements[1];
+}
+
+const HParsedToken *h_act_last(const HParseResult *p) {
+  assert(p->ast);
+  assert(p->ast->token_type == TT_SEQUENCE);
+  assert(p->ast->seq->used > 0);
+
+  return p->ast->seq->elements[p->ast->seq->used-1];
+}
+
+static void act_flatten_(HCountedArray *seq, const HParsedToken *tok) {
+  if(tok == NULL) {
+    return;
+  } else if(tok->token_type == TT_SEQUENCE) {
+    size_t i;
+    for(i=0; i<tok->seq->used; i++)
+      act_flatten_(seq, tok->seq->elements[i]);
+  } else {
+    h_carray_append(seq, (HParsedToken *)tok);
+  }
+}
+
 const HParsedToken *h_act_flatten(const HParseResult *p) {
-  return h_seq_flatten(p->arena, p->ast);
+  HCountedArray *seq = h_carray_new(p->arena);
+
+  act_flatten_(seq, p->ast);
+
+  HParsedToken *res = a_new_(p->arena, HParsedToken, 1);
+  res->token_type = TT_SEQUENCE;
+  res->seq = seq;
+  res->index = p->ast->index;
+  res->bit_offset = p->ast->bit_offset;
+  return res;
+}
+
+const HParsedToken *h_act_ignore(const HParseResult *p) {
+  return NULL;
 }
 
 // Low-level helper for the h_make family.
diff --git a/src/glue.h b/src/glue.h
index 3125ae07..ece7e9ea 100644
--- a/src/glue.h
+++ b/src/glue.h
@@ -88,9 +88,12 @@
 // action such as h_act_index.
 //
 
-const HParsedToken *h_act_ignore(const HParseResult *p);
 const HParsedToken *h_act_index(int i, const HParseResult *p);
+const HParsedToken *h_act_first(const HParseResult *p);
+const HParsedToken *h_act_second(const HParseResult *p);
+const HParsedToken *h_act_last(const HParseResult *p);
 const HParsedToken *h_act_flatten(const HParseResult *p);
+const HParsedToken *h_act_ignore(const HParseResult *p);
 
 // Define 'myaction' as a specialization of 'paction' by supplying the leading
 // parameters.
-- 
GitLab