summaryrefslogtreecommitdiff
path: root/contrib/py-bindings/gfmodule.c
diff options
context:
space:
mode:
authorjordi.saludes <jordi.saludes@upc.edu>2010-07-25 14:48:25 +0000
committerjordi.saludes <jordi.saludes@upc.edu>2010-07-25 14:48:25 +0000
commit23eb7b6df612c7b03407d45a3606086d8b182948 (patch)
tree2866748e9827c69f1bfc645aa36063f6ab21110b /contrib/py-bindings/gfmodule.c
parentac23280320313b0e470c8de6d49415e93d3c9d97 (diff)
Added unapplying of Expr in py-bindings.
Diffstat (limited to 'contrib/py-bindings/gfmodule.c')
-rw-r--r--contrib/py-bindings/gfmodule.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/contrib/py-bindings/gfmodule.c b/contrib/py-bindings/gfmodule.c
index 8c04de5d2..06896b9ba 100644
--- a/contrib/py-bindings/gfmodule.c
+++ b/contrib/py-bindings/gfmodule.c
@@ -225,6 +225,38 @@ DEALLOCFN(expr_dealloc, Expr, gf_freeExpr, "freeExpr")
REPRCB(expr_repr, Expr, gf_showExpr)
+static PyObject*
+unapp(Expr *self) {
+ PyObject* obj = gf_unapp(self);
+ if (!obj) {
+ char* s = gf_unstr(self);
+ if (s) {
+ obj = PyString_FromString(s);
+ free(s);
+ } else {
+ long n = gf_unint(self);
+ if (n != -9) {
+ obj = PyInt_FromLong(n);
+ } else {
+ PyErr_Format(PyExc_TypeError, "Cannot unapply expr.");
+ }
+ }
+ }
+ return obj;
+}
+
+static PyMethodDef tree_methods[] = {
+ {"unapply", (PyCFunction)unapp, METH_NOARGS,"Unapply a tree."},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+static PyMethodDef expr_methods[] = {
+ {"unapply", (PyCFunction)unapp, METH_NOARGS,"Unapply an expression."},
+ {NULL, NULL, 0, NULL} /* Sentinel */
+};
+
+
+
/* tree typr: methods, constructor and destructor */
// Are Expr and Tree equivalent ?
@@ -232,6 +264,9 @@ REPRCB(tree_repr, Tree, gf_showExpr)
DEALLOCFN(Tree_dealloc, Tree, gf_freeTree, "freeTree")
+
+
+
/* gf module methods */
static PyMethodDef gf_methods[] = {
@@ -260,7 +295,9 @@ initgf(void)
READYTYPE(PGFType, pgf_repr, PGF_dealloc)
READYTYPE(LangType, lang_repr, Lang_dealloc)
READYTYPE(gfTypeType, gfType_repr, gfType_dealloc)
+ ExprType.tp_methods = expr_methods;
READYTYPE(ExprType, expr_repr, expr_dealloc)
+ TreeType.tp_methods = tree_methods;
READYTYPE(TreeType, tree_repr, Tree_dealloc)
m = Py_InitModule3("gf", gf_methods,