summaryrefslogtreecommitdiff
path: root/contrib/py-bindings/gfmodule.c
diff options
context:
space:
mode:
authorjordi.saludes <jordi.saludes@upc.edu>2010-06-18 15:33:08 +0000
committerjordi.saludes <jordi.saludes@upc.edu>2010-06-18 15:33:08 +0000
commit7bee8ce0c7e79ef82387d2a375e172de867dcd1c (patch)
tree154b88dbdc74bdce74a1c845a1d009af7c090d88 /contrib/py-bindings/gfmodule.c
parent33eebe698d23f326994959c7f33962bc2d26e57f (diff)
Added CId and categories to py-bindings.
Diffstat (limited to 'contrib/py-bindings/gfmodule.c')
-rw-r--r--contrib/py-bindings/gfmodule.c32
1 files changed, 32 insertions, 0 deletions
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 */
@@ -102,6 +118,20 @@ startCategory(PyObject *self, PyObject *noarg)
}
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)
{
PyObject *langs = PyList_New(0);
@@ -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)