summaryrefslogtreecommitdiff
path: root/prolog/common.py
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-09-10 22:29:24 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-09-10 22:29:24 +0200
commit1b64321fda0bbf1f5a678671c1344eb2b87b5c74 (patch)
tree918743053a5b0b9a1ab45d6228c21e18af1132dc /prolog/common.py
parentee50df2225a974857e74d5ecb7c5f503e1c6b18a (diff)
Use Hint classes for hints from the last commit
Also move the language-specific hint method for Prolog to prolog.common.
Diffstat (limited to 'prolog/common.py')
-rw-r--r--prolog/common.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/prolog/common.py b/prolog/common.py
new file mode 100644
index 0000000..afba98f
--- /dev/null
+++ b/prolog/common.py
@@ -0,0 +1,21 @@
+# coding=utf-8
+
+import operator
+import prolog.engine
+from server.hints import Hint, HintSequence
+
+hint_defs = {
+ 'no_hint': HintSequence('no_hint', 4),
+ 'test_results': Hint('test_results'),
+ 'syntax_error': Hint('syntax_error'),
+}
+
+def hint(program):
+ # Check program for syntax errors.
+ engine_id, output = prolog.engine.create(code=program)
+ if engine_id is not None:
+ prolog.engine.destroy(engine_id)
+ if 'error' in map(operator.itemgetter(0), output):
+ errors_msg = '\n'.join(['{}: {}'.format(m_type, m_text) for m_type, m_text in output])
+ return [{'id': 'syntax_error', 'args': {'messages': errors_msg}}]
+ return []