mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
added a method in Python for pretty printing a grammar
This commit is contained in:
@@ -2619,6 +2619,24 @@ PGF_dealloc(PGFObject* self)
|
||||
Py_TYPE(self)->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PGF_repr(PGFObject *self)
|
||||
{
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
GuExn* err = gu_exn(tmp_pool);
|
||||
GuStringBuf* sbuf = gu_new_string_buf(tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
|
||||
pgf_print(self->pgf, out, err);
|
||||
|
||||
PyObject* pystr = PyString_FromStringAndSize(gu_string_buf_data(sbuf),
|
||||
gu_string_buf_length(sbuf));
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
return pystr;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PGF_getAbstractName(PGFObject *self, void *closure)
|
||||
{
|
||||
@@ -3239,7 +3257,7 @@ static PyTypeObject pgf_PGFType = {
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
(reprfunc) PGF_repr, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
|
||||
Reference in New Issue
Block a user