Skip to content

Commit 34b7be4

Browse files
committed
core, sexp: Ignore malformed sexps when --expect-unexpected is on
Closes GH-50, GH-51.
1 parent ec63bae commit 34b7be4

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

alectryon/core.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,12 @@ def next_sexp(self):
126126
# https://github.com/ejgallego/coq-serapi/issues/212
127127
MSG = "SerTop printed an empty line. Last response: {!r}."
128128
raise ValueError(MSG.format(self.last_response))
129-
self.last_response = response
130-
sexp = sx.load(response)
131129
debug(response, '<< ')
132-
return sexp
130+
self.last_response = response
131+
try:
132+
return sx.load(response)
133+
except sx.ParseError:
134+
return response
133135

134136
def _send(self, sexp):
135137
s = sx.dump([b'query%d' % self.next_qid, sexp])

alectryon/sexp.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,14 @@ def parse(tokens):
7373
top.append(tok)
7474
return top[0]
7575

76+
class ParseError(Exception):
77+
pass
78+
7679
def load(bs):
77-
return parse(tokenize(bs))
80+
try:
81+
return parse(tokenize(bs))
82+
except IndexError:
83+
raise ParseError()
7884

7985
def unparse(sexp, buf):
8086
stack = [sexp]

0 commit comments

Comments
 (0)