mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-12 12:42:50 -06:00
the parser in the C runtime can now detect incomplete sentences just like the parser in the Haskell runtime. This is also reflected in all bindings.
This commit is contained in:
@@ -591,6 +591,30 @@ JNIEXPORT void JNICALL Java_org_grammaticalframework_pgf_Parser_addLiteralCallba
|
||||
j2gu_string(env, jcat, pool), &callback->callback);
|
||||
}
|
||||
|
||||
static void
|
||||
throw_parse_error(JNIEnv *env, PgfParseError* err)
|
||||
{
|
||||
jstring jtoken;
|
||||
if (err->incomplete)
|
||||
jtoken = NULL;
|
||||
else {
|
||||
jtoken = gu2j_string_len(env, err->token_ptr, err->token_len);
|
||||
if (!jtoken)
|
||||
return;
|
||||
}
|
||||
|
||||
jclass exception_class = (*env)->FindClass(env, "org/grammaticalframework/pgf/ParseError");
|
||||
if (!exception_class)
|
||||
return;
|
||||
jmethodID constrId = (*env)->GetMethodID(env, exception_class, "<init>", "(Ljava/lang/String;IZ)V");
|
||||
if (!constrId)
|
||||
return;
|
||||
jobject exception = (*env)->NewObject(env, exception_class, constrId, jtoken, err->offset, err->incomplete);
|
||||
if (!exception)
|
||||
return;
|
||||
(*env)->Throw(env, exception);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL
|
||||
Java_org_grammaticalframework_pgf_Parser_parseWithHeuristics
|
||||
(JNIEnv* env, jclass clazz, jobject jconcr, jstring jstartCat, jstring js, jdouble heuristics, jlong callbacksRef, jobject jpool)
|
||||
@@ -615,8 +639,7 @@ Java_org_grammaticalframework_pgf_Parser_parseWithHeuristics
|
||||
GuString msg = (GuString) gu_exn_caught_data(parse_err);
|
||||
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", msg);
|
||||
} else if (gu_exn_caught(parse_err, PgfParseError)) {
|
||||
GuString tok = (GuString) gu_exn_caught_data(parse_err);
|
||||
throw_string_exception(env, "org/grammaticalframework/pgf/ParseError", tok);
|
||||
throw_parse_error(env, (PgfParseError*) gu_exn_caught_data(parse_err));
|
||||
}
|
||||
|
||||
gu_pool_free(out_pool);
|
||||
@@ -656,8 +679,7 @@ Java_org_grammaticalframework_pgf_Completer_complete(JNIEnv* env, jclass clazz,
|
||||
GuString msg = (GuString) gu_exn_caught_data(parse_err);
|
||||
throw_string_exception(env, "org/grammaticalframework/pgf/PGFError", msg);
|
||||
} else if (gu_exn_caught(parse_err, PgfParseError)) {
|
||||
GuString tok = (GuString) gu_exn_caught_data(parse_err);
|
||||
throw_string_exception(env, "org/grammaticalframework/pgf/ParseError", tok);
|
||||
throw_parse_error(env, (PgfParseError*) gu_exn_caught_data(parse_err));
|
||||
}
|
||||
|
||||
gu_pool_free(pool);
|
||||
|
||||
Reference in New Issue
Block a user