mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-17 00:39:32 -06:00
bugfix for print names in the C runtime and expose the functionality from Java
This commit is contained in:
@@ -191,9 +191,7 @@ PGF_API GuString
|
||||
pgf_print_name(PgfConcr* concr, PgfCId id)
|
||||
{
|
||||
PgfCId name =
|
||||
gu_map_get(concr->printnames, id, PgfCId);
|
||||
if (*name == 0)
|
||||
name = id;
|
||||
gu_map_get(concr->printnames, id, GuString);
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
@@ -565,7 +565,7 @@ pgf_read_abstract(PgfReader* rdr, PgfAbstr* abstract)
|
||||
static PgfCIdMap*
|
||||
pgf_read_printnames(PgfReader* rdr)
|
||||
{
|
||||
PgfCIdMap* printnames = gu_new_string_map(GuString, &"", rdr->opool);
|
||||
PgfCIdMap* printnames = gu_new_string_map(GuString, &gu_null_struct, rdr->opool);
|
||||
|
||||
size_t len = pgf_read_len(rdr);
|
||||
gu_return_on_exn(rdr->err, NULL);
|
||||
|
||||
@@ -1146,6 +1146,19 @@ Java_org_grammaticalframework_pgf_Concr_hasLinearization(JNIEnv* env, jobject se
|
||||
return res;
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL
|
||||
Java_org_grammaticalframework_pgf_Concr_getPrintName(JNIEnv* env, jobject self, jstring jid)
|
||||
{
|
||||
PgfConcr* concr = get_ref(env, self);
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
PgfCId id = j2gu_string(env, jid, tmp_pool);
|
||||
GuString name = pgf_print_name(concr, id);
|
||||
jstring jname = (name == NULL) ? NULL : gu2j_string(env, name);
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
return jname;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL
|
||||
Java_org_grammaticalframework_pgf_Pool_alloc(JNIEnv* env, jclass clazz)
|
||||
{
|
||||
|
||||
@@ -79,6 +79,10 @@ public class Concr {
|
||||
*/
|
||||
public native boolean hasLinearization(String fun);
|
||||
|
||||
/** returns the print name for that function or category.
|
||||
*/
|
||||
public native String getPrintName(String id);
|
||||
|
||||
/** If the concrete syntaxes in the grammar are stored in external
|
||||
* files then this method can be used to load the current syntax
|
||||
* in memory.
|
||||
|
||||
@@ -1303,11 +1303,15 @@ Concr_init(ConcrObject *self, PyObject *args, PyObject *kwds)
|
||||
static PyObject*
|
||||
Concr_printName(ConcrObject* self, PyObject *args)
|
||||
{
|
||||
GuString name;
|
||||
if (!PyArg_ParseTuple(args, "s", &name))
|
||||
GuString id;
|
||||
if (!PyArg_ParseTuple(args, "s", &id))
|
||||
return NULL;
|
||||
|
||||
return PyString_FromString(pgf_print_name(self->concr, name));
|
||||
GuString name = pgf_print_name(self->concr, id);
|
||||
if (name == NULL)
|
||||
Py_RETURN_NONE;
|
||||
|
||||
return PyString_FromString(name);
|
||||
}
|
||||
|
||||
#if ( (PY_VERSION_HEX < 0x02070000) \
|
||||
|
||||
Reference in New Issue
Block a user