diff options
Diffstat (limited to 'src/runtime/java/jpgf.c')
| -rw-r--r-- | src/runtime/java/jpgf.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/runtime/java/jpgf.c b/src/runtime/java/jpgf.c new file mode 100644 index 000000000..4796e32dd --- /dev/null +++ b/src/runtime/java/jpgf.c @@ -0,0 +1,31 @@ +#include <pgf/pgf.h> +#include <gu/mem.h> +#include "org_grammaticalframework_PGF.h" + +JNIEXPORT jobject JNICALL +Java_org_grammaticalframework_PGF_readPGF(JNIEnv *env, jclass cls, jstring s) +{ + const char *fpath = (*env)->GetStringUTFChars(env, s, 0); + + GuPool* pool = gu_new_pool(); + GuPool* tmp_pool = gu_local_pool(); + + // Create an exception frame that catches all errors. + GuExn* err = gu_new_exn(NULL, gu_kind(type), tmp_pool); + + // Read the PGF grammar. + PgfPGF* pgf = pgf_read(fpath, pool, err); + if (!gu_ok(err)) { + gu_pool_free(pool); + gu_pool_free(tmp_pool); + return NULL; + } + + gu_pool_free(tmp_pool); + + (*env)->ReleaseStringUTFChars(env, s, fpath); + + jmethodID constrId = (*env)->GetMethodID(env, cls, "<init>", "(II)V"); + + return (*env)->NewObject(env, cls, constrId, (int) pool, (int) pgf); +} |
