diff --git a/alectryon/core.py b/alectryon/core.py index 65faa458..b2eae5b7 100755 --- a/alectryon/core.py +++ b/alectryon/core.py @@ -126,10 +126,12 @@ def next_sexp(self): # https://github.com/ejgallego/coq-serapi/issues/212 MSG = "SerTop printed an empty line. Last response: {!r}." raise ValueError(MSG.format(self.last_response)) - self.last_response = response - sexp = sx.load(response) debug(response, '<< ') - return sexp + self.last_response = response + try: + return sx.load(response) + except sx.ParseError: + return response def _send(self, sexp): s = sx.dump([b'query%d' % self.next_qid, sexp]) diff --git a/alectryon/sexp.py b/alectryon/sexp.py index b8bf3b2c..0a4a0a6d 100644 --- a/alectryon/sexp.py +++ b/alectryon/sexp.py @@ -73,8 +73,14 @@ def parse(tokens): top.append(tok) return top[0] +class ParseError(Exception): + pass + def load(bs): - return parse(tokenize(bs)) + try: + return parse(tokenize(bs)) + except IndexError: + raise ParseError() def unparse(sexp, buf): stack = [sexp]