From 7bee8ce0c7e79ef82387d2a375e172de867dcd1c Mon Sep 17 00:00:00 2001 From: "jordi.saludes" Date: Fri, 18 Jun 2010 15:33:08 +0000 Subject: Added CId and categories to py-bindings. --- contrib/py-bindings/gfmodule.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'contrib/py-bindings/gfmodule.c') diff --git a/contrib/py-bindings/gfmodule.c b/contrib/py-bindings/gfmodule.c index 92129d4a5..34375a85d 100644 --- a/contrib/py-bindings/gfmodule.c +++ b/contrib/py-bindings/gfmodule.c @@ -69,12 +69,28 @@ checkType(void* obj, PyTypeObject* tp) /* new types and declarations */ +NEWGF(CId,GF_CId,CIdType,"gf.cid","c identifier") NEWGF(Lang,GF_Language,LangType,"gf.lang","language") NEWGF(gfType,GF_Type,gfTypeType,"gf.type","gf type") NEWGF(PGFModule,GF_PGF,PGFType,"gf.pgf","PGF module") NEWGF(Expr,GF_Expr,ExprType,"gf.expr","gf expression") NEWGF(Tree,GF_Tree,TreeType,"gf.tree","gf tree") +/* CId methods, constructor and destructor */ + + +DEALLOCFN(CId_dealloc, CId, gf_freeCId, "freeCId") + +static PyObject* +CId_repr(CId *self) +{ + char* str_cid = gf_showCId(self->obj); + PyObject* repr = PyString_FromString(str_cid); + free(str_cid); + return repr; +} + + /* PGF methods, constructor and destructor */ @@ -101,6 +117,20 @@ startCategory(PyObject *self, PyObject *noarg) return cat; } +static PyObject* +categories(PGFModule* self) +{ + PyObject* cats = PyList_New(0); + GF_CId *p = gf_categories(self->obj); + while (*p) { + CId* c = (CId*)CIdType.tp_new(&CIdType,NULL,NULL); + c->obj = *(p++); + PyList_Append(cats, (PyObject*)c); + Py_DECREF(c); //? + } + return cats; +} + static PyObject* languages(PGFModule* self) { @@ -197,6 +227,7 @@ static PyMethodDef pgf_methods[] = { {"parse", (PyCFunction)parse, METH_VARARGS|METH_KEYWORDS,"Parse a string."}, {"lin", (PyCFunction)linearize, METH_VARARGS,"Linearize tree."}, {"startcat", (PyCFunction)startCategory, METH_NOARGS,"Get the start category."}, + {"categories", (PyCFunction)categories, METH_NOARGS,"Get all categories."}, {"abstract", (PyCFunction)abstractName, METH_NOARGS,"Get the module abstract name."}, {"languages", (PyCFunction)languages, METH_NOARGS,"Get the module languages."}, {NULL, NULL, 0, NULL} /* Sentinel */ @@ -267,6 +298,7 @@ initgf(void) t.tp_dealloc = (destructor)tdealloc; \ if (PyType_Ready(&t) < 0) return; + READYTYPE(CIdType, CId_repr, CId_dealloc) PGFType.tp_methods = pgf_methods; READYTYPE(PGFType, pgf_repr, PGF_dealloc) READYTYPE(LangType, lang_repr, Lang_dealloc) -- cgit v1.2.3