From 1562625c3a71803659393bf11eb62bd1ea626fb4 Mon Sep 17 00:00:00 2001
From: Sven Robertz <sven@cs.lth.se>
Date: Tue, 9 Jul 2013 17:42:42 +0200
Subject: [PATCH] more cleanup and some documentation

---
 examples/dynamic/README              | 34 ++++++++++++++++++++++++----
 examples/dynamic/TestLabcommGen.java |  4 ++--
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/examples/dynamic/README b/examples/dynamic/README
index 4b8c397..2895d73 100644
--- a/examples/dynamic/README
+++ b/examples/dynamic/README
@@ -1,9 +1,33 @@
 This directory contains an embryo of an example of how to 
 generate and compile a labcomm endpoint on the fly.
 
-NB! There is currently no connection between the files StaticPart.java, DynamicPart.java, and
-TestLabCommCompiler.java
+NB! There is currently no connection to the StaticPart.java
+
+the runme.sh script builds and runs the TestLabCommGen, which illustrates the 
+on-the-fly compilation to RAM, reading the labcomm declarations and handlers from file
+
+The handlers declaration (in handlers.txt) is experimental, and has the following format:
+
+<sample name>:handler(<data type> <variable name>) {
+	<handler method code>
+}###
+
+where the end marker (}###) is a kludge to avoid having to parse the method body while still allowing
+it to contain blocks. Thus, having the sequence "}###" in the method body breaks this. Caveat hacker!
+
+An example handlers declaration:
+
+foo:handler(foo value) {
+	System.out.println("foo handler from handlers.txt");
+	System.out.println(value.x);
+	System.out.println(value.y);
+	System.out.println(value.z);
+	for(int i=0; i<value.x; i++){
+		System.out.print("."+(value.x-i));
+	}
+	System.out.println();
+}###
+bar:handler(int value) {
+	System.out.println(value);
+}###
 
-the runme.sh script builds and runs the TestLabCommCompiler, which illustrates the 
-on-the-fly compilation to RAM, reading the labcomm declarations from file but with the
-handlers hard coded in the test program.
diff --git a/examples/dynamic/TestLabcommGen.java b/examples/dynamic/TestLabcommGen.java
index a028e38..c5b852a 100644
--- a/examples/dynamic/TestLabcommGen.java
+++ b/examples/dynamic/TestLabcommGen.java
@@ -103,9 +103,9 @@ public class TestLabcommGen {
 			} else {
 				System.out.println("expeced handler decl:\n"+srcStr.substring(pos));	
 			}
-			int bodyEnd = srcStr.indexOf('}', pos); // HERE BE DRAGONS! too brittle
+			int bodyEnd = srcStr.indexOf("}###", pos); // HERE BE DRAGONS! a bit brittle
 			String body = srcStr.substring(pos, bodyEnd+1);
-			pos = bodyEnd+2;
+			pos = bodyEnd+5;
 //			System.out.println("body:");
 //			System.out.println(body);
 
-- 
GitLab