diff options
-rw-r--r-- | prolog/engine.py | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/prolog/engine.py b/prolog/engine.py index bdbca21..f8e563f 100644 --- a/prolog/engine.py +++ b/prolog/engine.py @@ -72,7 +72,7 @@ def request(method, path, body=None, timeout=10): reply = json.loads(response.read().decode('utf-8')) if reply.get('event') == 'output': - messages.append(get_message(reply)) + messages.append(_get_message(reply)) # Pull the next output. These requests should return instantly # as no additional processing needs to be done in the pengine. @@ -86,32 +86,23 @@ def request(method, path, body=None, timeout=10): conn.close() # Strip boilerplate from Prolog messages … ugly. -def get_message(reply): +def _get_message(reply): data = strip_html(reply['data']).strip() - message = '' + # Prepend the message with formatted location. + # NOTE in the final version we probably want to return the location object + where = '' if reply['message'] in ('error', 'warning'): - message = reply['message'] + ': ' if 'location' in reply: loc = reply['location'] - message += 'near line ' + str(loc['line']) + where += 'near line ' + str(loc['line']) if 'ch' in loc: - message += ', character ' + str(loc['ch']) - message += ': ' - - if reply.get('code') == 'syntax_error': - match = re.match(r'^.*Syntax error: (.*)$', data, flags=re.DOTALL) - data = match.group(1) - elif reply.get('code') == 'permission_error': - match = re.match(r'^.*(No permission [^\n]*)', data, flags=re.DOTALL) - data = match.group(1) - elif reply.get('code') == 'type_error': - match = re.match(r'^.*(Type error: [^\n]*)', data, flags=re.DOTALL) - data = match.group(1) - message += data - - # Replace anonymous variable names with _. - message = re.sub(r'_G[0-9]*', '_', message) - return reply['message'], message + where += ', character ' + str(loc['ch']) + where += ': ' + # Strip HTML and pengine IDs from the messages. + text = strip_html(data) + text = re.sub(r"pengine://[0-9]*/src:[0-9]*: ", '', text) + text = re.sub(r"'[0-9]{10,}':", '', text) + return reply['message'], where + text # Return the value of variable [name] in the JSON object returned by Prolog. def get_var(data, name): |