From 78dfc8958d9c53b7a4fc17d8afeaedf96dbac71e Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Tue, 29 Aug 2017 21:04:00 +0200 Subject: [PATCH] document the embedded API for Java --- doc/runtime-api.html | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/doc/runtime-api.html b/doc/runtime-api.html index 100fd4ffb..db06d3a4f 100644 --- a/doc/runtime-api.html +++ b/doc/runtime-api.html @@ -650,6 +650,26 @@ visit = case fg e2 of

+ +

In order to access the API you first need to generate +one boilerplate Java class with the compiler: +

+$ gf -make -output-format=java App.pgf
+
+This class will expose all functions in the abstract syntax +as methods. Now creating new trees is just a matter of writing ordinary Java +code: +
+System.out.println(App.DetCN(quant, cn));
+
+If the grammar name is too long to write it in front of every function +name then you can create an instance with a shorter name: +
+App a = new App();
+System.out.println(a.DetCN(quant, cn));
+
+

+

@@ -665,16 +685,16 @@ If there is no matching method name then the runtime will call the method default. The following is an example:

 >>> class ExampleVisitor:
-		def on_DetCN(self,quant,cn):
-			print("Found DetCN")
-			cn.visit(self)
+      def on_DetCN(self,quant,cn):
+        print("Found DetCN")
+        cn.visit(self)
 			
-		def on_AdjCN(self,adj,cn):
-			print("Found AdjCN")
-			cn.visit(self)
-			
-		def default(self,e):
-			pass
+      def on_AdjCN(self,adj,cn):
+        print("Found AdjCN")
+        cn.visit(self)
+
+      def default(self,e):
+        pass
 >>> e2.visit(ExampleVisitor())
 Found DetCN
 Found AdjCN