mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
added readType in Java
This commit is contained in:
@@ -1539,6 +1539,34 @@ Java_org_grammaticalframework_pgf_Type_getHypos(JNIEnv* env, jobject self)
|
||||
return jhypos;
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_grammaticalframework_pgf_Type_readType(JNIEnv* env, jclass clazz, jstring s)
|
||||
{
|
||||
GuPool* pool = gu_new_pool();
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuString buf = j2gu_string(env, s, tmp_pool);
|
||||
GuIn* in = gu_data_in((uint8_t*) buf, strlen(buf), tmp_pool);
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
|
||||
PgfType* ty = pgf_read_type(in, pool, err);
|
||||
if (!gu_ok(err)) {
|
||||
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", "The type cannot be parsed");
|
||||
gu_pool_free(tmp_pool);
|
||||
gu_pool_free(pool);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
jclass pool_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/Pool");
|
||||
jmethodID pool_constrId = (*env)->GetMethodID(env, pool_class, "<init>", "(J)V");
|
||||
jobject jpool = (*env)->NewObject(env, pool_class, pool_constrId, p2l(pool));
|
||||
|
||||
jmethodID constrId = (*env)->GetMethodID(env, clazz, "<init>", "(Ljava/lang/Object;J)V");
|
||||
return (*env)->NewObject(env, clazz, constrId, jpool, p2l(ty));
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_grammaticalframework_pgf_Type_toString(JNIEnv* env, jobject self)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user