mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-09-13 13:56:01 -06:00
Merge branch 'majestic' of github.com:krangelov/gf-core into majestic
This commit is contained in:
@@ -355,6 +355,59 @@ PgfLinearizationOutputIfaceVtbl pypgf_lin_out_iface_vtbl =
|
|||||||
(void*) pypgf_lin_out_flush
|
(void*) pypgf_lin_out_flush
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
Concr_tabularLinearize(ConcrObject* self, PyObject *args)
|
||||||
|
{
|
||||||
|
ExprObject* pyexpr;
|
||||||
|
if (!PyArg_ParseTuple(args, "O!", &pgf_ExprType, &pyexpr))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
PgfExn err;
|
||||||
|
PgfText **texts =
|
||||||
|
pgf_tabular_linearize(self->grammar->db, self->concr, (PgfExpr) pyexpr, NULL,
|
||||||
|
&marshaller, &err);
|
||||||
|
if (handleError(err) != PGF_EXN_NONE) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (texts == NULL) {
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PyObject *res = PyList_New(0);
|
||||||
|
if (!res)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
while (texts[0] != NULL && texts[1] != NULL) {
|
||||||
|
PyObject* pyfield = PyUnicode_FromStringAndSize(texts[0]->text, texts[0]->size);
|
||||||
|
free(texts[0]); texts++;
|
||||||
|
if (!pyfield)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
PyObject* pylin = PyUnicode_FromStringAndSize(texts[0]->text, texts[0]->size);
|
||||||
|
free(texts[0]); texts++;
|
||||||
|
if (!pylin)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
PyObject *tup = PyTuple_New(2);
|
||||||
|
PyTuple_SetItem(tup, 0, pyfield);
|
||||||
|
PyTuple_SetItem(tup, 1, pylin);
|
||||||
|
PyList_Append(res, tup);
|
||||||
|
Py_DECREF(tup);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
Py_XDECREF(res);
|
||||||
|
|
||||||
|
while (texts[0]) {
|
||||||
|
free(texts[0]); texts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
Concr_bracketedLinearize(ConcrObject* self, PyObject *args)
|
Concr_bracketedLinearize(ConcrObject* self, PyObject *args)
|
||||||
{
|
{
|
||||||
@@ -548,10 +601,10 @@ static PyMethodDef Concr_methods[] = {
|
|||||||
},
|
},
|
||||||
/*{"linearizeAll", (PyCFunction)Concr_linearizeAll, METH_VARARGS | METH_KEYWORDS,
|
/*{"linearizeAll", (PyCFunction)Concr_linearizeAll, METH_VARARGS | METH_KEYWORDS,
|
||||||
"Takes an abstract tree and linearizes with all variants"
|
"Takes an abstract tree and linearizes with all variants"
|
||||||
},
|
},*/
|
||||||
{"tabularLinearize", (PyCFunction)Concr_tabularLinearize, METH_VARARGS,
|
{"tabularLinearize", (PyCFunction)Concr_tabularLinearize, METH_VARARGS,
|
||||||
"Takes an abstract tree and linearizes it to a table containing all fields"
|
"Takes an abstract tree and linearizes it to a table containing all fields"
|
||||||
},*/
|
},
|
||||||
{"bracketedLinearize", (PyCFunction)Concr_bracketedLinearize, METH_VARARGS,
|
{"bracketedLinearize", (PyCFunction)Concr_bracketedLinearize, METH_VARARGS,
|
||||||
"Takes an abstract tree and linearizes it to a bracketed string"
|
"Takes an abstract tree and linearizes it to a bracketed string"
|
||||||
},
|
},
|
||||||
@@ -806,8 +859,8 @@ _collect_cats(PgfItor *fn, PgfText *key, object value, PgfExn *err)
|
|||||||
|
|
||||||
if (PyList_Append((PyObject*) clo->collection, py_name) != 0) {
|
if (PyList_Append((PyObject*) clo->collection, py_name) != 0) {
|
||||||
err->type = PGF_EXN_OTHER_ERROR;
|
err->type = PGF_EXN_OTHER_ERROR;
|
||||||
Py_DECREF(py_name);
|
|
||||||
}
|
}
|
||||||
|
Py_DECREF(py_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@@ -892,8 +945,8 @@ _collect_funs(PgfItor *fn, PgfText *key, object value, PgfExn *err)
|
|||||||
|
|
||||||
if (PyList_Append((PyObject*) clo->collection, py_name) != 0) {
|
if (PyList_Append((PyObject*) clo->collection, py_name) != 0) {
|
||||||
err->type = PGF_EXN_OTHER_ERROR;
|
err->type = PGF_EXN_OTHER_ERROR;
|
||||||
Py_DECREF(py_name);
|
|
||||||
}
|
}
|
||||||
|
Py_DECREF(py_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
|
|||||||
Reference in New Issue
Block a user