summaryrefslogtreecommitdiff
path: root/src/runtime/python
diff options
context:
space:
mode:
authorKrasimir Angelov <kr.angelov@gmail.com>2017-09-06 12:38:42 +0200
committerKrasimir Angelov <kr.angelov@gmail.com>2017-09-06 12:38:42 +0200
commit15d014abb825837f0fd7c9e17d5907001135faaf (patch)
treebc569f465432042702dfaa240746b8c6db609588 /src/runtime/python
parent18f2135785a71a1e93519a060d40b7ba523cf03b (diff)
the parser in the C runtime can now detect incomplete sentences just like the parser in the Haskell runtime. This is also reflected in all bindings.
Diffstat (limited to 'src/runtime/python')
-rw-r--r--src/runtime/python/pypgf.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/runtime/python/pypgf.c b/src/runtime/python/pypgf.c
index 7da62e453..97718103b 100644
--- a/src/runtime/python/pypgf.c
+++ b/src/runtime/python/pypgf.c
@@ -1545,13 +1545,28 @@ Concr_parse(ConcrObject* self, PyObject *args, PyObject *keywds)
GuString msg = (GuString) gu_exn_caught_data(parse_err);
PyErr_SetString(PGFError, msg);
} else if (gu_exn_caught(parse_err, PgfParseError)) {
- GuString tok = (GuString) gu_exn_caught_data(parse_err);
- PyObject* py_tok = PyString_FromString(tok);
- PyObject_SetAttrString(ParseError, "token", py_tok);
- PyErr_Format(ParseError, "Unexpected token: \"%s\"", tok);
- Py_DECREF(py_tok);
+ PgfParseError* err = (PgfParseError*) gu_exn_caught_data(parse_err);
+ PyObject* py_offset = PyInt_FromLong(err->offset);
+ if (err->incomplete) {
+ PyObject_SetAttrString(ParseError, "incomplete", Py_True);
+ PyObject_SetAttrString(ParseError, "offset", py_offset);
+ PyErr_Format(ParseError, "The sentence is incomplete");
+ } else {
+ PyObject* py_tok = PyString_FromStringAndSize(err->token_ptr,
+ err->token_len);
+ PyObject_SetAttrString(ParseError, "incomplete", Py_False);
+ PyObject_SetAttrString(ParseError, "offset", py_offset);
+ PyObject_SetAttrString(ParseError, "token", py_tok);
+#if PY_MAJOR_VERSION >= 3
+ PyErr_Format(ParseError, "Unexpected token: \"%U\"", py_tok);
+#else
+ PyErr_Format(ParseError, "Unexpected token: \"%s\"", PyString_AsString(py_tok));
+#endif
+ Py_DECREF(py_tok);
+ }
+ Py_DECREF(py_offset);
}
-
+
Py_DECREF(pyres);
pyres = NULL;
}