Skip to content

Commit

Permalink
core, sexp: Ignore malformed sexps when --expect-unexpected is on
Browse files Browse the repository at this point in the history
Closes GH-50, GH-51.
  • Loading branch information
cpitclaudel committed Jul 13, 2021
1 parent ec63bae commit 34b7be4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions alectryon/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
8 changes: 7 additions & 1 deletion alectryon/sexp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 34b7be4

Please sign in to comment.