summaryrefslogtreecommitdiff
path: root/python/common.py
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-09-11 11:01:13 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-09-11 11:01:13 +0200
commit046463bcebe08c6cbe3504d676c0bf27f8695482 (patch)
tree02b42f57f9dbe049489f09148c55666388077e98 /python/common.py
parente77850d687754750ab9e9f2aa8113eb9d7a73fd6 (diff)
Add language hints for Python and use Hint classes
Diffstat (limited to 'python/common.py')
-rw-r--r--python/common.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/python/common.py b/python/common.py
new file mode 100644
index 0000000..39c323f
--- /dev/null
+++ b/python/common.py
@@ -0,0 +1,19 @@
+# coding=utf-8
+
+import ast
+from server.hints import Hint, HintSequence
+
+hint_type = {
+ 'no_hint': Hint('no_hint'),
+ 'test_results': Hint('test_results'),
+ 'syntax_error': Hint('syntax_error'),
+}
+
+def hint(program):
+ # Check program for syntax errors.
+ try:
+ tree = ast.parse(program, filename='user')
+ except SyntaxError as ex:
+ error_msg = '{}{}^\n{}'.format(ex.text, ' '*(ex.offset-1), ex.msg)
+ return [{'id': 'syntax_error', 'args': {'lineno': ex.lineno, 'message': error_msg}}]
+ return []